소스 검색

Split out BulbId

Christopher Mullins 6 년 전
부모
커밋
62bf2a3b65
6개의 변경된 파일62개의 추가작업 그리고 67개의 파일을 삭제
  1. 2 35
      lib/MiLightState/GroupState.cpp
  2. 3 13
      lib/MiLightState/GroupState.h
  3. 0 19
      lib/Radio/MiLightConstants.h
  4. 5 0
      lib/Settings/Settings.h
  5. 36 0
      lib/Types/BulbId.cpp
  6. 16 0
      lib/Types/BulbId.h

+ 2 - 35
lib/MiLightState/GroupState.cpp

@@ -2,6 +2,7 @@
 #include <Units.h>
 #include <MiLightRemoteConfig.h>
 #include <RGBConverter.h>
+#include <BulbId.h>
 
 static const char* BULB_MODE_NAMES[] = {
   "white",
@@ -11,6 +12,7 @@ static const char* BULB_MODE_NAMES[] = {
 };
 
 const BulbId DEFAULT_BULB_ID;
+
 static const GroupStateField ALL_PHYSICAL_FIELDS[] = {
   GroupStateField::BULB_MODE,
   GroupStateField::HUE,
@@ -49,41 +51,6 @@ const GroupState& GroupState::defaultState(MiLightRemoteType remoteType) {
   return state;
 }
 
-BulbId::BulbId()
-  : deviceId(0),
-    groupId(0),
-    deviceType(REMOTE_TYPE_UNKNOWN)
-{ }
-
-BulbId::BulbId(const BulbId &other)
-  : deviceId(other.deviceId),
-    groupId(other.groupId),
-    deviceType(other.deviceType)
-{ }
-
-BulbId::BulbId(
-  const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType
-)
-  : deviceId(deviceId),
-    groupId(groupId),
-    deviceType(deviceType)
-{ }
-
-void BulbId::operator=(const BulbId &other) {
-  deviceId = other.deviceId;
-  groupId = other.groupId;
-  deviceType = other.deviceType;
-}
-
-// determine if now BulbId's are the same.  This compared deviceID (the controller/remote ID) and
-// groupId (the group number on the controller, 1-4 or 1-8 depending), but ignores the deviceType
-// (type of controller/remote) as this doesn't directly affect the identity of the bulb
-bool BulbId::operator==(const BulbId &other) {
-  return deviceId == other.deviceId
-    && groupId == other.groupId
-    && deviceType == other.deviceType;
-}
-
 void GroupState::initFields() {
   state.fields._state                = 0;
   state.fields._brightness           = 0;

+ 3 - 13
lib/MiLightState/GroupState.h

@@ -1,9 +1,11 @@
 #include <stddef.h>
 #include <inttypes.h>
-#include <MiLightConstants.h>
+#include <MiLightRemoteType.h>
+#include <MiLightStatus.h>
 #include <MiLightRadioConfig.h>
 #include <GroupStateField.h>
 #include <ArduinoJson.h>
+#include <BulbId.h>
 
 #ifndef _GROUP_STATE_H
 #define _GROUP_STATE_H
@@ -11,18 +13,6 @@
 // enable to add debugging on state
 // #define DEBUG_STATE
 
-struct BulbId {
-  uint16_t deviceId;
-  uint8_t groupId;
-  MiLightRemoteType deviceType;
-
-  BulbId();
-  BulbId(const BulbId& other);
-  BulbId(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType);
-  bool operator==(const BulbId& other);
-  void operator=(const BulbId& other);
-};
-
 enum BulbMode {
   BULB_MODE_WHITE,
   BULB_MODE_COLOR,

+ 0 - 19
lib/Radio/MiLightConstants.h

@@ -1,19 +0,0 @@
-#ifndef _MILIGHT_BUTTONS
-#define _MILIGHT_BUTTONS
-
-enum MiLightRemoteType {
-  REMOTE_TYPE_UNKNOWN = 255,
-  REMOTE_TYPE_RGBW    = 0,
-  REMOTE_TYPE_CCT     = 1,
-  REMOTE_TYPE_RGB_CCT = 2,
-  REMOTE_TYPE_RGB     = 3,
-  REMOTE_TYPE_FUT089  = 4,
-  REMOTE_TYPE_FUT091  = 5
-};
-
-enum MiLightStatus {
-  ON = 0,
-  OFF = 1
-};
-
-#endif

+ 5 - 0
lib/Settings/Settings.h

@@ -7,8 +7,13 @@
 #include <Size.h>
 #include <LEDStatus.h>
 #include <AuthProviders.h>
+
+#include <MiLightRemoteType.h>
+#include <BulbId.h>
+
 #include <vector>
 #include <memory>
+#include <map>
 
 #ifndef _SETTINGS_H_INCLUDED
 #define _SETTINGS_H_INCLUDED

+ 36 - 0
lib/Types/BulbId.cpp

@@ -0,0 +1,36 @@
+#include <BulbId.h>
+
+BulbId::BulbId()
+  : deviceId(0),
+    groupId(0),
+    deviceType(REMOTE_TYPE_UNKNOWN)
+{ }
+
+BulbId::BulbId(const BulbId &other)
+  : deviceId(other.deviceId),
+    groupId(other.groupId),
+    deviceType(other.deviceType)
+{ }
+
+BulbId::BulbId(
+  const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType
+)
+  : deviceId(deviceId),
+    groupId(groupId),
+    deviceType(deviceType)
+{ }
+
+void BulbId::operator=(const BulbId &other) {
+  deviceId = other.deviceId;
+  groupId = other.groupId;
+  deviceType = other.deviceType;
+}
+
+// determine if now BulbId's are the same.  This compared deviceID (the controller/remote ID) and
+// groupId (the group number on the controller, 1-4 or 1-8 depending), but ignores the deviceType
+// (type of controller/remote) as this doesn't directly affect the identity of the bulb
+bool BulbId::operator==(const BulbId &other) {
+  return deviceId == other.deviceId
+    && groupId == other.groupId
+    && deviceType == other.deviceType;
+}

+ 16 - 0
lib/Types/BulbId.h

@@ -0,0 +1,16 @@
+#pragma once
+
+#include <stdint.h>
+#include <MiLightRemoteType.h>
+
+struct BulbId {
+  uint16_t deviceId;
+  uint8_t groupId;
+  MiLightRemoteType deviceType;
+
+  BulbId();
+  BulbId(const BulbId& other);
+  BulbId(const uint16_t deviceId, const uint8_t groupId, const MiLightRemoteType deviceType);
+  bool operator==(const BulbId& other);
+  void operator=(const BulbId& other);
+};