Bläddra i källkod

Split out types libraries, adjust includes

Christopher Mullins 6 år sedan
förälder
incheckning
157cd2ca14

+ 2 - 28
lib/MiLight/MiLightRemoteConfig.cpp

@@ -1,4 +1,5 @@
 #include <MiLightRemoteConfig.h>
+#include <MiLightRemoteType.h>
 
 /**
  * IMPORTANT NOTE: These should be in the same order as MiLightRemoteType.
@@ -13,34 +14,7 @@ const MiLightRemoteConfig* MiLightRemoteConfig::ALL_REMOTES[] = {
 };
 
 const MiLightRemoteConfig* MiLightRemoteConfig::fromType(const String& type) {
-  if (type.equalsIgnoreCase("rgbw") || type.equalsIgnoreCase("fut096")) {
-    return &FUT096Config;
-  }
-
-  if (type.equalsIgnoreCase("cct") || type.equalsIgnoreCase("fut007")) {
-    return &FUT007Config;
-  }
-
-  if (type.equalsIgnoreCase("rgb_cct") || type.equalsIgnoreCase("fut092")) {
-    return &FUT092Config;
-  }
-
-  if (type.equalsIgnoreCase("fut089")) {
-    return &FUT089Config;
-  }
-
-  if (type.equalsIgnoreCase("rgb") || type.equalsIgnoreCase("fut098")) {
-    return &FUT098Config;
-  }
-
-  if (type.equalsIgnoreCase("v2_cct") || type.equalsIgnoreCase("fut091")) {
-    return &FUT091Config;
-  }
-
-  Serial.print(F("MiLightRemoteConfig::fromType: ERROR - tried to fetch remote config for type: "));
-  Serial.println(type);
-
-  return NULL;
+  return fromType(MiLightRemoteTypeHelpers::remoteTypeFromString(type));
 }
 
 const MiLightRemoteConfig* MiLightRemoteConfig::fromType(MiLightRemoteType type) {

+ 1 - 1
lib/MiLight/PacketFormatter.h

@@ -1,7 +1,7 @@
 #include <Arduino.h>
 #include <inttypes.h>
 #include <functional>
-#include <MiLightConstants.h>
+#include <MiLightRemoteType.h>
 #include <ArduinoJson.h>
 #include <GroupState.h>
 #include <GroupStateStore.h>

+ 1 - 1
lib/Radio/MiLightRadioConfig.h

@@ -1,5 +1,5 @@
 #include <Arduino.h>
-#include <MiLightConstants.h>
+#include <MiLightRemoteType.h>
 #include <Size.h>
 
 #ifndef _MILIGHT_RADIO_CONFIG

+ 0 - 19
lib/Types/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

+ 54 - 0
lib/Types/MiLightRemoteType.cpp

@@ -0,0 +1,54 @@
+#include <MiLightRemoteType.h>
+#include <Arduino.h>
+
+const MiLightRemoteType MiLightRemoteTypeHelpers::remoteTypeFromString(const String& type) {
+  if (type.equalsIgnoreCase("rgbw") || type.equalsIgnoreCase("fut096")) {
+    return REMOTE_TYPE_RGBW;
+  }
+
+  if (type.equalsIgnoreCase("cct") || type.equalsIgnoreCase("fut007")) {
+    return REMOTE_TYPE_CCT;
+  }
+
+  if (type.equalsIgnoreCase("rgb_cct") || type.equalsIgnoreCase("fut092")) {
+    return REMOTE_TYPE_RGB_CCT;
+  }
+
+  if (type.equalsIgnoreCase("fut089")) {
+    return REMOTE_TYPE_FUT089;
+  }
+
+  if (type.equalsIgnoreCase("rgb") || type.equalsIgnoreCase("fut098")) {
+    return REMOTE_TYPE_RGB;
+  }
+
+  if (type.equalsIgnoreCase("v2_cct") || type.equalsIgnoreCase("fut091")) {
+    return REMOTE_TYPE_FUT091;
+  }
+
+  Serial.print(F("remoteTypeFromString: ERROR - tried to fetch remote config for type: "));
+  Serial.println(type);
+
+  return REMOTE_TYPE_UNKNOWN;
+}
+
+const String MiLightRemoteTypeHelpers::remoteTypeToString(const MiLightRemoteType type) {
+  switch (type) {
+    case REMOTE_TYPE_RGBW:
+      return "rgbw";
+    case REMOTE_TYPE_CCT:
+      return "cct";
+    case REMOTE_TYPE_RGB_CCT:
+      return "rgb_cct";
+    case REMOTE_TYPE_FUT089:
+      return "fut089";
+    case REMOTE_TYPE_RGB:
+      return "rgb";
+    case REMOTE_TYPE_FUT091:
+      return "fut091";
+    default:
+      Serial.print(F("remoteTypeToString: ERROR - tried to fetch remote config name for unknown type: "));
+      Serial.println(type);
+      return "unknown";
+  }
+}

+ 19 - 0
lib/Types/MiLightRemoteType.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include <Arduino.h>
+
+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
+};
+
+class MiLightRemoteTypeHelpers {
+public:
+  static const MiLightRemoteType remoteTypeFromString(const String& type);
+  static const String remoteTypeToString(const MiLightRemoteType type);
+};

+ 6 - 0
lib/Types/MiLightStatus.h

@@ -0,0 +1,6 @@
+#pragma once
+
+enum MiLightStatus {
+  ON = 0,
+  OFF = 1
+};

+ 2 - 1
src/main.cpp

@@ -8,10 +8,12 @@
 #include <IntParsing.h>
 #include <Size.h>
 #include <LinkedList.h>
+#include <LEDStatus.h>
 #include <GroupStateStore.h>
 #include <MiLightRadioConfig.h>
 #include <MiLightRemoteConfig.h>
 #include <MiLightHttpServer.h>
+#include <MiLightRemoteType.h>
 #include <Settings.h>
 #include <MiLightUdpServer.h>
 #include <ESP8266mDNS.h>
@@ -21,7 +23,6 @@
 #include <MiLightDiscoveryServer.h>
 #include <MiLightClient.h>
 #include <BulbStateUpdater.h>
-#include <LEDStatus.h>
 #include <RadioSwitchboard.h>
 #include <PacketSender.h>