Przeglądaj źródła

inital definition of state

Chris Mullins 8 lat temu
rodzic
commit
ceadb81803
2 zmienionych plików z 63 dodań i 0 usunięć
  1. 48 0
      lib/MiLightState/GroupState.h
  2. 15 0
      lib/MiLightState/GroupStateStore.h

+ 48 - 0
lib/MiLightState/GroupState.h

@@ -0,0 +1,48 @@
+#include <inttypes.h>
+#include <Arduino.h>
+
+#ifndef _GROUP_STATE_H
+#define _GROUP_STATE_H
+
+struct GroupId {
+  uint16_t deviceId;
+  uint8_t groupId;
+};
+
+struct GroupState {
+  // xxxx xxxx  xxxx xxxx  xxxx xxxx  xxxx xxxx
+  // ^..
+  uint32_t data;
+
+  // 1 bit
+  bool isOn();
+  void setOn(bool on);
+
+  // 7 bits
+  uint8_t getBrightness();
+  void setBrightness(uint8_t brightness);
+
+  // 8 bits
+  uint8_t getHue();
+  void setHue(uint8_t hue);
+
+  // 7 bits
+  uint8_t getSaturation();
+  void setSaturation(uint8_t saturation);
+
+  // 5 bits
+  uint8_t getMode();
+  void setMode(uint8_t mode);
+
+  // 7 bits
+  uint8_t getKelvin();
+  void setKelvin(uint8_t kelvin);
+};
+
+struct GroupStateNode {
+  GroupState state;
+  GroupId nextNode;
+  GroupId prevNode;
+};
+
+#endif

+ 15 - 0
lib/MiLightState/GroupStateStore.h

@@ -0,0 +1,15 @@
+#include <GroupState.h>
+
+#ifndef _STATE_CACHE_H
+#define _STATE_CACHE_H
+
+class GroupStateStore {
+public:
+  bool get(const GroupId& id, GroupState& state);
+  void set(const GroupId& id, const GroupState& state);
+
+private:
+  void evictOldest(GroupState& state);
+};
+
+#endif