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.

52 lines
1.7 KiB

  1. #pragma once
  2. namespace esphome {
  3. namespace yeelight {
  4. namespace bs2 {
  5. /// A tag, used for logging.
  6. static const char *TAG = "yeelight_bs2";
  7. /// The minimum color temperature in mired. Same as supported by
  8. /// the original Yeelight firmware.
  9. static const int MIRED_MIN = 153;
  10. /// The maximum color temperature in mired. Same as supported by
  11. /// the original Yeelight firmware.
  12. static const int MIRED_MAX = 588;
  13. /// This abstract class is used for building classes that translate
  14. /// LightColorValues into the required GPIO pin outputs to represent
  15. /// the requested color on the device.
  16. class GPIOOutputs {
  17. public:
  18. float red = 0.0f;
  19. float green = 0.0f;
  20. float blue = 0.0f;
  21. float white = 0.0f;
  22. light::LightColorValues values;
  23. /// Set the red, green, blue, white fields to the PWM duty cycles
  24. /// that are required to represent the requested light color for
  25. /// the provided LightColorValues input.
  26. /// Returns true when the class can handle the input, false otherwise.
  27. virtual bool set_light_color_values(light::LightColorValues v) = 0;
  28. /// Copy the output values to another GPIOOutputs object.
  29. void copy_to(GPIOOutputs *other) {
  30. other->red = red;
  31. other->green = green;
  32. other->blue = blue;
  33. other->white = white;
  34. other->values = values;
  35. }
  36. void log(const char *prefix) {
  37. ESP_LOGD(TAG, "%s: RGB=[%f,%f,%f], white=%f",
  38. prefix, red, green, blue, white);
  39. }
  40. };
  41. } // namespace bs2
  42. } // namespace yeelight
  43. } // namespace esphome