Create servo configuration

This commit is contained in:
Christoph Hagen
2023-08-09 13:38:12 +02:00
parent d13bf67443
commit b99245085e
3 changed files with 56 additions and 30 deletions

View File

@ -3,6 +3,39 @@
#include <stdint.h>
#include <ESP32Servo.h> // To control the servo
typedef struct ServoConfiguration {
/**
* @brief The timer to use for the servo control
* number 0-3 indicating which timer to allocate in this library
*/
int pwmTimer;
/**
* @brief The servo frequency (depending on the model used)
*/
int pwmFrequency;
/**
* @brief The pin where the servo PWM line is connected
*/
int pin;
/**
* @brief The duration (in ms) for which the button should remain pressed
*/
uint32_t openDuration;
/**
* @brief The servo value (in µs) that specifies the 'pressed' state
*/
int pressedValue;
/**
* @brief The servo value (in µs) that specifies the 'released' state
*/
int releasedValue;
};
/**
* @brief A controller for the button control servo
*
@ -17,22 +50,16 @@ class ServoController {
public:
/**
* @brief Construct a new Servo Controller object
*
* @param timer The timer to use for the servo control
* @param frequency The servo frequency (depending on the model used)
* @param pin The pin where the servo PWM line is connected
* @brief Construct a new servo controller
*/
ServoController(int timer, int frequency, int pin);
ServoController();
/**
* @brief Configure the button values
* @brief Configure the servo
*
* @param openDuration The duration (in ms) for which the button should remain pressed
* @param pressedValue The servo value (in µs) that specifies the 'pressed' state
* @param releasedValue The servo value (in µs) that specifies the 'released' state
* @param The configuration for the servo
*/
void configure(uint32_t openDuration, int pressedValue, int releasedValue);
void configure(ServoConfiguration configuration);
/**
* @brief Update the servo state periodically
@ -60,12 +87,6 @@ private:
// Indicator that the door button is pushed
bool buttonIsPressed = false;
int timer;
int frequency;
int pin;
uint32_t openDuration = 0;
int pressedValue = 0;