ソースを参照

handle all color values

Chris Mullins 8 年 前
コミット
06f7b38330
共有3 個のファイルを変更した21 個の追加3 個の削除を含む
  1. 17 2
      lib/Udp/V6RgbCctCommandHandler.cpp
  2. 2 0
      lib/Udp/V6RgbCctCommandHandler.h
  3. 2 1
      platformio.ini

+ 17 - 2
lib/Udp/V6RgbCctCommandHandler.cpp

@@ -39,9 +39,8 @@ bool V6RgbCctCommandHandler::handleCommand(
   }
   
   switch (cmd) {
-      
     case V2_COLOR:
-      client->updateColorRaw(arg);
+      handleUpdateColor(client, commandArg);
       break;
       
     case V2_KELVIN:
@@ -66,3 +65,19 @@ bool V6RgbCctCommandHandler::handleCommand(
   
   return true;
 }
+
+/* 
+ * Arguments are 32 bits. Most commands use the first byte, but color arguments
+ * can use all four. Triggered in app when quickly transitioning through colors.
+ */
+void V6RgbCctCommandHandler::handleUpdateColor(MiLightClient *client, uint32_t color) {
+  for (int i = 3; i >= 0; i--) {
+    const uint8_t argValue = (color >> (i*8)) & 0xFF;
+    
+    if (argValue == 0) {
+      return;
+    }
+    
+    client->updateColorRaw(argValue);
+  }
+}

+ 2 - 0
lib/Udp/V6RgbCctCommandHandler.h

@@ -34,6 +34,8 @@ public:
     uint32_t commandArg
   );
   
+  void handleUpdateColor(MiLightClient* client, uint32_t color);
+  
 };
 
 #endif

+ 2 - 1
platformio.ini

@@ -16,7 +16,8 @@ lib_deps_external =
   RF24
   WiFiManager
   ArduinoJson
-build_flags = -D MILIGHT_HUB_VERSION=\"1.1.0\" -D MILIGHT_UDP_DEBUG
+build_flags = -D MILIGHT_HUB_VERSION=\"1.1.0\" 
+# -D MILIGHT_UDP_DEBUG
 
 [env:nodemcuv2]
 platform = espressif8266