#pragma once #include #include // To control the servo 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 * * The controller simply configures the servo for operation, * and then sets the desired servo value for the 'pressed' and 'released' states. * The controller requires periodic updating through the `loop()` function * in order to release the button after the specified time. * */ class ServoController { public: /** * @brief Construct a new servo controller */ ServoController(); /** * @brief Configure the servo * * @param The configuration for the servo */ void configure(ServoConfiguration configuration); /** * @brief Update the servo state periodically * * This function should be periodically called to update the servo state, * specifically to release the button after the opening time has elapsed. * * There is no required interval to call this function, but the accuracy of * the opening interval is dependent on the calling frequency. */ void loop(uint32_t millis); /** * Push the door opener button down by moving the servo arm. */ void pressButton(); /** * Release the door opener button by moving the servo arm. */ void releaseButton(); private: // Indicator that the door button is pushed bool buttonIsPressed = false; uint32_t openDuration = 0; int pressedValue = 0; int releasedValue = 0; // The time (in ms since start) when the door opening should end uint32_t openingEndTime = 0; // Servo controller Servo servo; // PWM Module needed for the servo ESP32PWM pwm; };