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.

50 lines
1.3 KiB

  1. #pragma once
  2. #include "light_modes.h"
  3. namespace esphome {
  4. namespace xiaomi {
  5. namespace bslamp2 {
  6. /**
  7. * This abstract class is used for implementing classes that translate
  8. * LightColorValues into the required GPIO PWM duty cycle levels to represent
  9. * the requested color on the physical device.
  10. */
  11. class GPIOOutputs {
  12. public:
  13. float red = 0.0f;
  14. float green = 0.0f;
  15. float blue = 0.0f;
  16. float white = 0.0f;
  17. std::string light_mode = LIGHT_MODE_OFF;
  18. /**
  19. * Sets the red, green, blue, white fields to the PWM duty cycles
  20. * that are required to represent the requested light color for
  21. * the provided LightColorValues input.
  22. *
  23. * Returns true when the input can be handled, false otherwise.
  24. */
  25. virtual bool set_light_color_values(light::LightColorValues v) = 0;
  26. /**
  27. * Copies the current output values to another GPIOOutputs object.
  28. */
  29. void copy_to(GPIOOutputs *other) {
  30. other->red = red;
  31. other->green = green;
  32. other->blue = blue;
  33. other->white = white;
  34. other->light_mode = light_mode;
  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 bslamp2
  42. } // namespace xiaomi
  43. } // namespace esphome