Bladeren bron

clean up config definition

Chris Mullins 8 jaren geleden
bovenliggende
commit
f76e093e44

+ 2 - 2
README.md

@@ -49,8 +49,8 @@ You should now be able to navigate to `http://<ip of ESP>`. It should look like
 1. `GET /`. Opens web UI. You'll need to upload it first.
 2. `GET /settings`. Gets current settings as JSON.
 3. `PUT /settings`. Patches settings (e.g., doesn't overwrite keys that aren't present). Accepts a JSON blob in the body.
-4. `GET /gateway_traffic`. Starts an HTTP long poll. Returns any Milight traffic it hears. Useful if you need to know what your Milight gateway/remote ID is.
-5. `PUT /gateways/:device_id/:device_type/:group_id`. Controls or sends commands to `:group_id` from `:device_id`. Since protocols for RGBW/CCT are different, specify one of `rgbw` or `cct` as `:device_type. Accepts a JSON blob.
+4. `GET /gateway_traffic/:device_type`. Starts an HTTP long poll. Returns any Milight traffic it hears. Useful if you need to know what your Milight gateway/remote ID is. Since protocols for RGBW/CCT are different, specify one of `rgbw`, `cct`, or `rgb_cct` as `:device_type. Accepts a JSON blob.
+5. `PUT /gateways/:device_id/:device_type/:group_id`. Controls or sends commands to `:group_id` from `:device_id`. 
 6. `PUT /gateways/:device_id/:device_type`. A few commands have support for being sent to all groups. You can send those here.
 7. `POST /firmware`. OTA firmware update.
 8. `POST /web`. Update web UI.

+ 1 - 1
lib/MiLight/MiLightClient.cpp

@@ -65,7 +65,7 @@ void MiLightClient::write(uint8_t packet[]) {
   }
   
   for (int i = 0; i < this->resendCount; i++) {
-    currentRadio->getRadio()->write(packet, currentRadio->config.packetLength);
+    currentRadio->getRadio()->write(packet, currentRadio->config.getPacketLength());
   }
 }
     

+ 2 - 2
lib/MiLight/MiLightRadio.cpp

@@ -53,7 +53,7 @@ int MiLightRadio::configure() {
   }
 
   // +1 to be able to buffer the length 
-  retval = _pl1167.setMaxPacketLength(config.packetLength + 1);
+  retval = _pl1167.setMaxPacketLength(config.getPacketLength() + 1);
   if (retval < 0) {
     return retval;
   }
@@ -143,7 +143,7 @@ int MiLightRadio::write(uint8_t frame[], size_t frame_length)
 
 int MiLightRadio::resend()
 {
-  for (size_t i = 0; i < config.numChannels; i++) {
+  for (size_t i = 0; i < MiLightRadioConfig::NUM_CHANNELS; i++) {
     _pl1167.writeFIFO(_out_packet, _out_packet[0] + 1);
     _pl1167.transmit(config.channels[i]);
   }

+ 4 - 0
lib/MiLight/MiLightRadioConfig.cpp

@@ -10,4 +10,8 @@ MiLightRadioConfig* MiLightRadioConfig::fromString(const String& s) {
   }
   
   return NULL;
+}
+
+size_t MiLightRadioConfig::getPacketLength() const {
+  return packetFormatter->getPacketLength();
 }

+ 16 - 17
lib/MiLight/MiLightRadioConfig.h

@@ -10,46 +10,45 @@
 
 class MiLightRadioConfig {
 public:
+  static const size_t NUM_CHANNELS = 3;
+  
   MiLightRadioConfig(const uint16_t syncword0,
   const uint16_t syncword3,
-  const size_t packetLength,
-  const uint8_t* channels,
-  const size_t numChannels,
   PacketFormatter* packetFormatter,
-  const MiLightRadioType type) 
+  const MiLightRadioType type,
+  const uint8_t channel0,
+  const uint8_t channel1,
+  const uint8_t channel2) 
     : syncword0(syncword0),
       syncword3(syncword3),
-      packetLength(packetLength),
-      channels(channels),
-      numChannels(numChannels),
       packetFormatter(packetFormatter),
       type(type)
-  {}
+  {
+    channels[0] = channel0;
+    channels[1] = channel1;
+    channels[2] = channel2;
+  }
     
   const uint16_t syncword0;
   const uint16_t syncword3;
-  const size_t packetLength;
-  const uint8_t* channels;
-  const size_t numChannels;
+  uint8_t channels[3];
   PacketFormatter* packetFormatter;
   const MiLightRadioType type;
   
   static MiLightRadioConfig* fromString(const String& s);
+  size_t getPacketLength() const;
 };
 
-const uint8_t RGBW_CHANNELS[] = {9, 40, 71};
 static MiLightRadioConfig MilightRgbwConfig(
-  0x147A, 0x258B, 7, RGBW_CHANNELS, 3, new RgbwPacketFormatter(8), RGBW
+  0x147A, 0x258B, new RgbwPacketFormatter(8), RGBW, 9, 40, 71
 );
 
-const uint8_t CCT_CHANNELS[] = {4, 39, 74};
 static MiLightRadioConfig MilightCctConfig(
-  0x050A, 0x55AA, 7, CCT_CHANNELS, 3, new CctPacketFormatter(8), CCT
+  0x050A, 0x55AA, new CctPacketFormatter(8), CCT, 4, 39, 74
 );
 
-const uint8_t RGBCCT_CHANNELS[] = {70, 39, 8};
 static MiLightRadioConfig MilightRgbCctConfig(
-  0x7236, 0x1809, 9, RGBCCT_CHANNELS, 3, new RgbCctPacketFormatter(9), RGB_CCT
+  0x7236, 0x1809, new RgbCctPacketFormatter(9), RGB_CCT, 8, 39, 70
 );
 
 #endif

+ 4 - 0
lib/MiLight/PacketFormatter.cpp

@@ -59,4 +59,8 @@ void PacketFormatter::formatV1Packet(uint8_t const* packet, char* buffer) {
     packet[5],
     packet[6]
   );
+}
+  
+size_t PacketFormatter::getPacketLength() const {
+  return packetLength;
 }

+ 2 - 0
lib/MiLight/PacketFormatter.h

@@ -53,6 +53,8 @@ public:
     return round(value * (newMax / oldMax));
   }
   
+  size_t getPacketLength() const;
+  
 protected:
   uint8_t* packet;
   size_t packetLength;

+ 3 - 3
lib/WebServer/MiLightHttpServer.cpp

@@ -154,7 +154,7 @@ void MiLightHttpServer::handleListenGateway(const UrlTokenBindings* bindings) {
     yield();
   }
   
-  uint8_t packet[config->packetLength];
+  uint8_t packet[config->getPacketLength()];
   milightClient->read(packet);
   
   String response = "Packet received (";
@@ -294,9 +294,9 @@ void MiLightHttpServer::handleSendRaw(const UrlTokenBindings* bindings) {
     return;
   }
   
-  uint8_t packet[config->packetLength];
+  uint8_t packet[config->getPacketLength()];
   const String& hexPacket = request["packet"];
-  hexStrToBytes<uint8_t>(hexPacket.c_str(), hexPacket.length(), packet, config->packetLength);
+  hexStrToBytes<uint8_t>(hexPacket.c_str(), hexPacket.length(), packet, config->getPacketLength());
   
   size_t numRepeats = MILIGHT_DEFAULT_RESEND_COUNT;
   if (request.containsKey("num_repeats")) {