Explorar o código

fix color shift

Chris Mullins %!s(int64=8) %!d(string=hai) anos
pai
achega
9c659127ef
Modificáronse 2 ficheiros con 3 adicións e 3 borrados
  1. 1 1
      lib/MiLight/MiLightClient.cpp
  2. 2 2
      lib/MiLight/MiLightUdpServer.cpp

+ 1 - 1
lib/MiLight/MiLightClient.cpp

@@ -90,7 +90,7 @@ void MiLightClient::updateHue(const uint16_t deviceId, const uint8_t groupId, co
   // Map color as a Hue value in [0, 359] to [0, 255]. The protocol also has
   // 0 being roughly magenta (#FF00FF)
   const int16_t remappedColor = (hue + 40) % 360;
-  const uint8_t adjustedColor = round(remappedColor * (255 / 359.0));
+  const uint8_t adjustedColor = round(remappedColor * (255 / 360.0));
   
   write(deviceId, adjustedColor, 0, groupId, COLOR);
 }

+ 2 - 2
lib/MiLight/MiLightUdpServer.cpp

@@ -46,7 +46,6 @@ void MiLightUdpServer::handleCommand(uint8_t command, uint8_t commandArg) {
     client->updateColorWhite(deviceId, groupId);
     this->lastGroup = groupId;
   } else {
-    // Group on/off
     switch (command) {
       case UDP_ALL_ON:
         client->allOn(deviceId);
@@ -57,7 +56,8 @@ void MiLightUdpServer::handleCommand(uint8_t command, uint8_t commandArg) {
         break;
       
       case UDP_COLOR:
-        client->updateColorRaw(deviceId, this->lastGroup, commandArg);
+        // UDP color is shifted by 0xC8 from 2.4 GHz color ...
+        client->updateColorRaw(deviceId, this->lastGroup, commandArg + 0xC8);
         break;
         
       case UDP_DISCO_MODE: