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.

48 lines
1.2 KiB

  1. #pragma once
  2. #include "esphome/components/gpio/output/gpio_binary_output.h"
  3. #include "esphome/components/ledc/ledc_output.h"
  4. #include "esphome/core/component.h"
  5. namespace esphome {
  6. namespace xiaomi {
  7. namespace bslamp2 {
  8. class LightHAL : Component {
  9. public:
  10. void set_red_pin(ledc::LEDCOutput *pin) { red_ = pin; }
  11. void set_green_pin(ledc::LEDCOutput *pin) { green_ = pin; }
  12. void set_blue_pin(ledc::LEDCOutput *pin) { blue_ = pin; }
  13. void set_white_pin(ledc::LEDCOutput *pin) { white_ = pin; }
  14. void set_master1_pin(gpio::GPIOBinaryOutput *pin) { master1_ = pin; }
  15. void set_master2_pin(gpio::GPIOBinaryOutput *pin) { master2_ = pin; }
  16. void turn_on() {
  17. master1_->turn_on();
  18. master2_->turn_on();
  19. }
  20. void turn_off() {
  21. master1_->turn_off();
  22. master2_->turn_off();
  23. }
  24. void set_rgbw(float r, float g, float b, float w) {
  25. red_->set_level(r);
  26. green_->set_level(g);
  27. blue_->set_level(b);
  28. white_->set_level(w);
  29. }
  30. protected:
  31. ledc::LEDCOutput *red_;
  32. ledc::LEDCOutput *green_;
  33. ledc::LEDCOutput *blue_;
  34. ledc::LEDCOutput *white_;
  35. gpio::GPIOBinaryOutput *master1_;
  36. gpio::GPIOBinaryOutput *master2_;
  37. };
  38. } // namespace bslamp2
  39. } // namespace xiaomi
  40. } // namespace esphome