backlight.h 794 B

123456789101112131415161718192021222324252627282930313233343536
  1. #pragma once
  2. #include <cstdint>
  3. #include <functional>
  4. #include <driver/gpio.h>
  5. #include <esp_timer.h>
  6. class Backlight {
  7. public:
  8. Backlight();
  9. ~Backlight();
  10. void RestoreBrightness();
  11. void SetBrightness(uint8_t brightness, bool permanent = false);
  12. inline uint8_t brightness() const { return brightness_; }
  13. protected:
  14. void OnTransitionTimer();
  15. virtual void SetBrightnessImpl(uint8_t brightness) = 0;
  16. esp_timer_handle_t transition_timer_ = nullptr;
  17. uint8_t brightness_ = 0;
  18. uint8_t target_brightness_ = 0;
  19. uint8_t step_ = 1;
  20. };
  21. class PwmBacklight : public Backlight {
  22. public:
  23. PwmBacklight(gpio_num_t pin, bool output_invert = false, uint32_t freq_hz = 25000);
  24. ~PwmBacklight();
  25. void SetBrightnessImpl(uint8_t brightness) override;
  26. };