GroupState.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <inttypes.h>
  2. #include <Arduino.h>
  3. #include <MiLightButtons.h>
  4. #include <ArduinoJson.h>
  5. #ifndef _GROUP_STATE_H
  6. #define _GROUP_STATE_H
  7. struct GroupId {
  8. uint16_t deviceId;
  9. uint8_t groupId;
  10. MiLightRemoteType deviceType;
  11. GroupId();
  12. GroupId(const GroupId& other);
  13. GroupId(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType);
  14. bool operator==(const GroupId& other);
  15. void operator=(const GroupId& other);
  16. };
  17. enum BulbMode {
  18. BULB_MODE_WHITE,
  19. BULB_MODE_COLOR,
  20. BULB_MODE_SCENE,
  21. BULB_MODE_NIGHT
  22. };
  23. static const char* BULB_MODE_NAMES[] = {
  24. "white",
  25. "color",
  26. "scene",
  27. "night"
  28. };
  29. class GroupState {
  30. public:
  31. GroupState();
  32. // 1 bit
  33. bool isSetState() const;
  34. MiLightStatus getState() const;
  35. void setState(const MiLightStatus on);
  36. // 7 bits
  37. bool isSetBrightness() const;
  38. uint8_t getBrightness() const;
  39. void setBrightness(uint8_t brightness);
  40. // 8 bits
  41. bool isSetHue() const;
  42. uint8_t getHue() const;
  43. void setHue(uint8_t hue);
  44. // 7 bits
  45. bool isSetSaturation() const;
  46. uint8_t getSaturation() const;
  47. void setSaturation(uint8_t saturation);
  48. // 5 bits
  49. bool isSetMode() const;
  50. uint8_t getMode() const;
  51. void setMode(uint8_t mode);
  52. // 7 bits
  53. bool isSetKelvin() const;
  54. uint8_t getKelvin() const;
  55. void setKelvin(uint8_t kelvin);
  56. // 3 bits
  57. bool isSetBulbMode() const;
  58. BulbMode getBulbMode() const;
  59. void setBulbMode(BulbMode mode);
  60. void patch(const JsonObject& state);
  61. void applyState(JsonObject& state);
  62. static const GroupState& defaultState(MiLightRemoteType remoteType);
  63. private:
  64. uint32_t
  65. _state : 1,
  66. _brightness : 7,
  67. _hue : 8,
  68. _saturation : 7,
  69. _mode : 4,
  70. _bulbMode : 3,
  71. _isSetState : 1,
  72. _isSetHue : 1;
  73. uint32_t
  74. _kelvin : 7,
  75. _isSetBrightness : 1,
  76. _isSetSaturation : 1,
  77. _isSetMode : 1,
  78. _isSetKelvin : 1,
  79. _isSetBulbMode : 1,
  80. _brightnessColor : 7,
  81. _brightnessMode : 7,
  82. _isSetBrightnessColor : 1,
  83. _isSetBrightnessMode : 1,
  84. : 5;
  85. };
  86. struct GroupStateNode {
  87. GroupState state;
  88. GroupId nextNode;
  89. GroupId prevNode;
  90. };
  91. #endif