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.

43 lines
1.3 KiB

  1. #pragma once
  2. #include <array>
  3. #include <stdexcept>
  4. #include "common.h"
  5. namespace esphome {
  6. namespace yeelight {
  7. namespace bs2 {
  8. class ColorNightLight : public GPIOOutputs {
  9. public:
  10. bool set_light_color_values(light::LightColorValues v) {
  11. values = v;
  12. // This night light mode is activated when white light is selected.
  13. // Based on measurements using the original device firmware, so it
  14. // matches the night light of the original firmware.
  15. if (v.get_white() > 0) {
  16. red = 0.968f;
  17. green = 0.968f;
  18. blue = 0.972f;
  19. white = 0.0f;
  20. }
  21. // In RGB mode, the selected color is used to give the night light
  22. // a specific color, instead of the default. This is a nice extra
  23. // for this firmware, as the original firmware does not support it.
  24. else {
  25. red = 0.9997f - v.get_red() * (0.9997f - 0.9680f);
  26. green = 0.9997f - v.get_green() * (0.9997f - 0.9680f);
  27. auto blue_on = 0.9720f + (0.9680f - 0.9720f) * (1.0f - (v.get_red() + v.get_green())/2.0f);
  28. blue = 0.9997f - v.get_blue() * (0.9997f - blue_on);
  29. white = 0.0f;
  30. }
  31. return true;
  32. }
  33. };
  34. } // namespace yeelight_bs2
  35. } // namespace yeelight
  36. } // namespace bs2