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.

57 lines
1.2 KiB

  1. #pragma once
  2. #include "../common.h"
  3. #include "../front_panel_hal.h"
  4. #include "esphome/components/output/float_output.h"
  5. #include <cmath>
  6. namespace esphome {
  7. namespace xiaomi {
  8. namespace bslamp2 {
  9. /**
  10. * An output, used for controlling the front panel illumination and
  11. * level indicator on the Xiaomi Mijia Bedside Lamp 2 front panel.
  12. */
  13. class XiaomiBslamp2FrontPanelOutput : public output::FloatOutput, public Component {
  14. public:
  15. void set_parent(FrontPanelHAL *front_panel) {
  16. front_panel_ = front_panel;
  17. }
  18. void write_state(float level) {
  19. if (level > 0) {
  20. turn_on_leds(LED_POWER | LED_COLOR);
  21. set_level(level);
  22. } else {
  23. turn_off_leds(LED_ALL);
  24. }
  25. }
  26. void set_level(float level) {
  27. front_panel_->set_slider_level(level);
  28. }
  29. void set_leds(uint16_t leds) {
  30. front_panel_->set_leds(leds);
  31. }
  32. void turn_on_leds(uint16_t leds) {
  33. front_panel_->turn_on_leds(leds);
  34. }
  35. void turn_off_leds(uint16_t leds) {
  36. front_panel_->turn_off_leds(leds);
  37. }
  38. void update_leds() {
  39. front_panel_->update_leds();
  40. }
  41. protected:
  42. FrontPanelHAL *front_panel_;
  43. };
  44. } // namespace bslamp2
  45. } // namespace xiaomi
  46. } // namespace esphome