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.

55 lines
1.6 KiB

  1. #pragma once
  2. namespace esphome {
  3. namespace xiaomi {
  4. namespace bslamp2 {
  5. // Light modes that can be reported by implementations of GPIOOutputs.
  6. static const std::string LIGHT_MODE_UNKNOWN { "unknown" };
  7. static const std::string LIGHT_MODE_OFF { "off" };
  8. static const std::string LIGHT_MODE_RGB { "rgb" };
  9. static const std::string LIGHT_MODE_WHITE { "white" };
  10. static const std::string LIGHT_MODE_NIGHT { "night" };
  11. /**
  12. * This abstract class is used for implementing classes that translate
  13. * LightColorValues into the required GPIO PWM duty cycle levels to represent
  14. * the requested color on the physical device.
  15. */
  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. std::string light_mode = LIGHT_MODE_OFF;
  23. /**
  24. * Sets the red, green, blue, white fields to the PWM duty cycles
  25. * that are required to represent the requested light color for
  26. * the provided LightColorValues input.
  27. *
  28. * Returns true when the input can be handled, false otherwise.
  29. */
  30. virtual bool set_light_color_values(light::LightColorValues v) = 0;
  31. /**
  32. * Copies the current output values to another GPIOOutputs object.
  33. */
  34. void copy_to(GPIOOutputs *other) {
  35. other->red = red;
  36. other->green = green;
  37. other->blue = blue;
  38. other->white = white;
  39. other->light_mode = light_mode;
  40. }
  41. void log(const char *prefix) {
  42. ESP_LOGD(TAG, "%s: RGB=[%f,%f,%f], white=%f",
  43. prefix, red, green, blue, white);
  44. }
  45. };
  46. } // namespace bslamp2
  47. } // namespace xiaomi
  48. } // namespace esphome