Create servo configuration
This commit is contained in:
12
src/main.cpp
12
src/main.cpp
@ -23,7 +23,7 @@ TimeCheck timeCheck{};
|
||||
|
||||
ServerConnection server(serverUrl, serverPort, serverPath);
|
||||
|
||||
ServoController servo(pwmTimer, servoFrequency, servoPin);
|
||||
ServoController servo{};
|
||||
|
||||
AsyncWebServer local(localPort);
|
||||
|
||||
@ -40,7 +40,15 @@ void setup() {
|
||||
Serial.setDebugOutput(true);
|
||||
Serial.println("[INFO] Device started");
|
||||
|
||||
servo.configure(lockOpeningDuration, servoPressedState, servoReleasedState);
|
||||
ServoConfiguration servoConfig;
|
||||
servoConfig.pwmTimer = pwmTimer;
|
||||
servoConfig.pwmFrequency = servoFrequency;
|
||||
servoConfig.pin = servoPin;
|
||||
servoConfig.openDuration = lockOpeningDuration;
|
||||
servoConfig.pressedValue = servoPressedState;
|
||||
servoConfig.releasedValue = servoReleasedState;
|
||||
|
||||
servo.configure(servoConfig);
|
||||
Serial.println("[INFO] Servo configured");
|
||||
|
||||
controller.configure();
|
||||
|
@ -2,18 +2,15 @@
|
||||
|
||||
#include <esp32-hal.h> // For `millis()`
|
||||
|
||||
ServoController::ServoController(int timer, int frequency, int pin)
|
||||
: timer(timer), frequency(frequency), pin(pin) {
|
||||
|
||||
}
|
||||
ServoController::ServoController() { }
|
||||
|
||||
void ServoController::configure(uint32_t openDuration, int pressedValue, int releasedValue) {
|
||||
this->openDuration = openDuration;
|
||||
this->pressedValue = pressedValue;
|
||||
this->releasedValue = releasedValue;
|
||||
ESP32PWM::allocateTimer(timer);
|
||||
servo.setPeriodHertz(frequency);
|
||||
servo.attach(pin);
|
||||
void ServoController::configure(ServoConfiguration configuration) {
|
||||
openDuration = configuration.openDuration;
|
||||
pressedValue = configuration.pressedValue;
|
||||
releasedValue = configuration.releasedValue;
|
||||
ESP32PWM::allocateTimer(configuration.pwmTimer);
|
||||
servo.setPeriodHertz(configuration.pwmFrequency);
|
||||
servo.attach(configuration.pin);
|
||||
releaseButton();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user