GroupState.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #include <inttypes.h>
  2. #include <Arduino.h>
  3. #include <MiLightButtons.h>
  4. #ifndef _GROUP_STATE_H
  5. #define _GROUP_STATE_H
  6. struct GroupId {
  7. uint16_t deviceId;
  8. uint8_t groupId;
  9. MiLightRemoteType deviceType;
  10. GroupId();
  11. GroupId(const GroupId& other);
  12. GroupId(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType);
  13. bool operator==(const GroupId& other);
  14. void operator=(const GroupId& other);
  15. };
  16. enum BulbMode {
  17. BULB_MODE_WHITE,
  18. BULB_MODE_COLOR,
  19. BULB_MODE_SCENE
  20. };
  21. class GroupState {
  22. public:
  23. GroupState();
  24. // 1 bit
  25. bool isOn();
  26. void setOn(bool on);
  27. // 7 bits
  28. uint8_t getBrightness() const;
  29. void setBrightness(uint8_t brightness);
  30. // 8 bits
  31. uint8_t getHue();
  32. void setHue(uint8_t hue);
  33. // 7 bits
  34. uint8_t getSaturation();
  35. void setSaturation(uint8_t saturation);
  36. // 5 bits
  37. uint8_t getMode();
  38. void setMode(uint8_t mode);
  39. // 7 bits
  40. uint8_t getKelvin();
  41. void setKelvin(uint8_t kelvin);
  42. // 3 bits
  43. BulbMode getBulbMode();
  44. void setBulbMode(BulbMode mode);
  45. static const GroupState DEFAULT_STATE;
  46. private:
  47. uint32_t
  48. _on : 1,
  49. _brightness : 7,
  50. _hue : 8,
  51. _saturation : 7,
  52. _mode : 4,
  53. _bulbMode : 3,
  54. : 2;
  55. uint8_t
  56. _kelvin : 7,
  57. : 1;
  58. };
  59. struct GroupStateNode {
  60. GroupState state;
  61. GroupId nextNode;
  62. GroupId prevNode;
  63. };
  64. #endif