Browse Source

list of configs

Chris Mullins 8 years ago
parent
commit
e570750294

+ 6 - 0
lib/MiLight/MiLightRadioConfig.cpp

@@ -1,4 +1,10 @@
 #include <MiLightRadioConfig.h>
+  
+const MiLightRadioConfig* MiLightRadioConfig::ALL_CONFIGS[] = {
+  &MilightRgbwConfig,
+  &MilightCctConfig,
+  &MilightRgbCctConfig
+};
 
 MiLightRadioConfig* MiLightRadioConfig::fromString(const String& s) {
   if (s.equalsIgnoreCase("rgbw")) {

+ 10 - 4
lib/MiLight/MiLightRadioConfig.h

@@ -16,13 +16,15 @@ public:
   const uint16_t syncword3,
   PacketFormatter* packetFormatter,
   const MiLightRadioType type,
+  const char* name,
   const uint8_t channel0,
   const uint8_t channel1,
   const uint8_t channel2) 
     : syncword0(syncword0),
       syncword3(syncword3),
       packetFormatter(packetFormatter),
-      type(type)
+      type(type),
+      name(name)
   {
     channels[0] = channel0;
     channels[1] = channel1;
@@ -34,21 +36,25 @@ public:
   uint8_t channels[3];
   PacketFormatter* packetFormatter;
   const MiLightRadioType type;
+  const char* name;
+  
+  static const size_t NUM_CONFIGS = 3;
+  static const MiLightRadioConfig* ALL_CONFIGS[NUM_CONFIGS];
   
   static MiLightRadioConfig* fromString(const String& s);
   size_t getPacketLength() const;
 };
 
 static MiLightRadioConfig MilightRgbwConfig(
-  0x147A, 0x258B, new RgbwPacketFormatter(8), RGBW, 9, 40, 71
+  0x147A, 0x258B, new RgbwPacketFormatter(8), RGBW, "rgbw", 9, 40, 71
 );
 
 static MiLightRadioConfig MilightCctConfig(
-  0x050A, 0x55AA, new CctPacketFormatter(8), CCT, 4, 39, 74
+  0x050A, 0x55AA, new CctPacketFormatter(8), CCT, "cct", 4, 39, 74
 );
 
 static MiLightRadioConfig MilightRgbCctConfig(
-  0x7236, 0x1809, new RgbCctPacketFormatter(9), RGB_CCT, 8, 39, 70
+  0x7236, 0x1809, new RgbCctPacketFormatter(9), RGB_CCT, "rgb_cct", 8, 39, 70
 );
 
 #endif

+ 16 - 0
lib/WebServer/MiLightHttpServer.cpp

@@ -12,6 +12,7 @@ void MiLightHttpServer::begin() {
   server.on("/settings", HTTP_GET, handleServeFile(SETTINGS_FILE, "application/json"));
   server.on("/settings", HTTP_PUT, [this]() { handleUpdateSettings(); });
   server.on("/settings", HTTP_POST, [this]() { server.send(200, "text/plain", "success"); }, handleUpdateFile(SETTINGS_FILE));
+  server.on("/radio_configs", HTTP_GET, [this]() { handleGetRadioConfigs(); });
   server.onPattern("/gateway_traffic/:type", HTTP_GET, [this](const UrlTokenBindings* b) { handleListenGateway(b); });
   server.onPattern("/gateways/:device_id/:type/:group_id", HTTP_PUT, [this](const UrlTokenBindings* b) { handleUpdateGroup(b); });
   server.onPattern("/gateways/:device_id/:type", HTTP_PUT, [this](const UrlTokenBindings* b) { handleUpdateGateway(b); });
@@ -67,6 +68,21 @@ void MiLightHttpServer::onSettingsSaved(SettingsSavedHandler handler) {
   this->settingsSavedHandler = handler;
 }
   
+void MiLightHttpServer::handleGetRadioConfigs() {
+  DynamicJsonBuffer buffer;
+  JsonArray& arr = buffer.createArray();
+  
+  for (size_t i = 0; i < MiLightRadioConfig::NUM_CONFIGS; i++) {
+    const MiLightRadioConfig* config = MiLightRadioConfig::ALL_CONFIGS[i];
+    arr.add(config->name);
+  }
+  
+  String body;
+  arr.printTo(body);
+  
+  server.send(200, "application/json", body);
+}
+  
 ESP8266WebServer::THandlerFunction MiLightHttpServer::handleServeFile(
   const char* filename, 
   const char* contentType, 

+ 1 - 0
lib/WebServer/MiLightHttpServer.h

@@ -32,6 +32,7 @@ protected:
   void applySettings(Settings& settings);
   
   void handleUpdateSettings();
+  void handleGetRadioConfigs();
   void handleListenGateway(const UrlTokenBindings* urlBindings);
   void handleSendRaw(const UrlTokenBindings* urlBindings);
   void handleUpdateGroup(const UrlTokenBindings* urlBindings);