GroupState.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 isSetOn() const;
  26. bool isOn() const;
  27. void setOn(bool on);
  28. // 7 bits
  29. bool isSetBrightness() const;
  30. uint8_t getBrightness() const;
  31. void setBrightness(uint8_t brightness);
  32. // 8 bits
  33. bool isSetHue() const;
  34. uint8_t getHue() const;
  35. void setHue(uint8_t hue);
  36. // 7 bits
  37. bool isSetSaturation() const;
  38. uint8_t getSaturation() const;
  39. void setSaturation(uint8_t saturation);
  40. // 5 bits
  41. bool isSetMode() const;
  42. uint8_t getMode() const;
  43. void setMode(uint8_t mode);
  44. // 7 bits
  45. bool isSetKelvin() const;
  46. uint8_t getKelvin() const;
  47. void setKelvin(uint8_t kelvin);
  48. // 3 bits
  49. bool isSetBulbMode() const;
  50. BulbMode getBulbMode() const;
  51. void setBulbMode(BulbMode mode);
  52. static const GroupState DEFAULT_STATE;
  53. private:
  54. uint32_t
  55. _on : 1,
  56. _brightness : 7,
  57. _hue : 8,
  58. _saturation : 7,
  59. _mode : 4,
  60. _bulbMode : 3,
  61. _isSetOn : 1,
  62. _isSetHue : 1;
  63. uint16_t
  64. _kelvin : 7,
  65. _isSetBrightness : 1,
  66. _isSetSaturation : 1,
  67. _isSetMode : 1,
  68. _isSetKelvin : 1,
  69. _isSetBulbMode : 1,
  70. : 4;
  71. };
  72. struct GroupStateNode {
  73. GroupState state;
  74. GroupId nextNode;
  75. GroupId prevNode;
  76. };
  77. #endif