Explorar el Código

Use near white in RGB to switch to white

Bijesh Krishnadas hace 8 años
padre
commit
a4fa26ec13
Se han modificado 2 ficheros con 17 adiciones y 14 borrados
  1. 15 13
      lib/MiLight/MiLightClient.cpp
  2. 2 1
      lib/MiLight/MiLightClient.h

+ 15 - 13
lib/MiLight/MiLightClient.cpp

@@ -267,16 +267,23 @@ void MiLightClient::update(const JsonObject& request) {
     uint8_t r = color["r"];
     uint8_t g = color["g"];
     uint8_t b = color["b"];
+    //If close to white
+    if( r > 256 - RGB_BOUNDARY && g > 256 - RGB_BOUNDARY && b > 256 - RGB_BOUNDARY)
+    {
+        this->updateColorWhite();
+    }
+    else
+    {
+      double hsv[3];
+      RGBConverter converter;
+      converter.rgbToHsv(r, g, b, hsv);
 
-    double hsv[3];
-    RGBConverter converter;
-    converter.rgbToHsv(r, g, b, hsv);
-
-    uint16_t hue = round(hsv[0]*360);
-    uint8_t saturation = round(hsv[1]*100);
+      uint16_t hue = round(hsv[0]*360);
+      uint8_t saturation = round(hsv[1]*100);
 
-    this->updateHue(hue);
-    this->updateSaturation(saturation);
+      this->updateHue(hue);
+      this->updateSaturation(saturation);
+    }
   }
 
   if (request.containsKey("level")) {
@@ -298,11 +305,6 @@ void MiLightClient::update(const JsonObject& request) {
     );
   }
 
-  //Homeassistant - Switch to white if white value is set
-  if (request.containsKey("white_value")) {
-    this->updateColorWhite();
-  }
-  
   if (request.containsKey("mode")) {
     this->updateMode(request["mode"]);
   }

+ 2 - 1
lib/MiLight/MiLightClient.h

@@ -11,7 +11,8 @@
 //#define DEBUG_PRINTF
 
 #define MILIGHT_DEFAULT_RESEND_COUNT 10
-
+//Used to determine close to white
+#define RGB_BOUNDARY 40
 
 class MiLightClient {
 public: