You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.2 KiB

  1. #pragma once
  2. #include "esphome/core/automation.h"
  3. #include "esphome/core/component.h"
  4. #include "../front_panel_hal.h"
  5. #include "output.h"
  6. #include <cmath>
  7. namespace esphome {
  8. namespace xiaomi {
  9. namespace bslamp2 {
  10. template<typename... Ts> class SetLEDsAction : public Action<Ts...> {
  11. public:
  12. explicit SetLEDsAction(XiaomiBslamp2FrontPanelOutput *parent) : parent_(parent) {}
  13. TEMPLATABLE_VALUE(int, mode)
  14. TEMPLATABLE_VALUE(uint16_t, leds)
  15. void play(Ts... x) override {
  16. uint16_t mode = this->mode_.value(x...);
  17. uint16_t value = this->leds_.value(x...);
  18. switch (mode) {
  19. case 0:
  20. parent_->turn_off_leds(value);
  21. break;
  22. case 1:
  23. parent_->turn_on_leds(value);
  24. break;
  25. case 2:
  26. parent_->set_leds(value);
  27. break;
  28. }
  29. }
  30. protected:
  31. XiaomiBslamp2FrontPanelOutput *parent_;
  32. };
  33. template<typename... Ts> class UpdateLEDsAction : public Action<Ts...> {
  34. public:
  35. explicit UpdateLEDsAction(XiaomiBslamp2FrontPanelOutput *parent) : parent_(parent) {}
  36. void play(Ts... x) override {
  37. parent_->update_leds();
  38. }
  39. protected:
  40. XiaomiBslamp2FrontPanelOutput *parent_;
  41. };
  42. } // namespace bslamp2
  43. } // namespace xiaomi
  44. } // namespace esphome