Ver código fonte

Add computed_color option which sends color=255,255,255 when in white mode

Christopher Mullins 8 anos atrás
pai
commit
cd02ec18b1

Diferenças do arquivo suprimidas por serem muito extensas
+ 2 - 2
dist/index.html.gz.h


+ 35 - 13
lib/MiLightState/GroupState.cpp

@@ -78,6 +78,9 @@ GroupState::GroupState() {
 
 bool GroupState::isSetField(GroupStateField field) const {
   switch (field) {
+    case GroupStateField::COMPUTED_COLOR:
+      // Always set -- either send RGB color or white
+      return true;
     case GroupStateField::STATE:
     case GroupStateField::STATUS:
       return isSetState();
@@ -98,6 +101,9 @@ bool GroupState::isSetField(GroupStateField field) const {
       return isSetBulbMode();
   }
 
+  Serial.print(F("WARNING: tried to check if unknown field was set: "));
+  Serial.println(static_cast<unsigned int>(field));
+
   return false;
 }
 
@@ -312,6 +318,26 @@ bool GroupState::patch(const JsonObject& state) {
   return changes;
 }
 
+void GroupState::applyColor(ArduinoJson::JsonObject& state) {
+  uint8_t rgb[3];
+  RGBConverter converter;
+  converter.hsvToRgb(
+    getHue()/360.0,
+    // Default to fully saturated
+    (isSetSaturation() ? getSaturation() : 100)/100.0,
+    1,
+    rgb
+  );
+  applyColor(state, rgb[0], rgb[1], rgb[2]);
+}
+
+void GroupState::applyColor(ArduinoJson::JsonObject& state, uint8_t r, uint8_t g, uint8_t b) {
+  JsonObject& color = state.createNestedObject("color");
+  color["r"] = r;
+  color["g"] = g;
+  color["b"] = b;
+}
+
 void GroupState::applyField(JsonObject& partialState, GroupStateField field) {
   if (isSetField(field)) {
     switch (field) {
@@ -334,19 +360,15 @@ void GroupState::applyField(JsonObject& partialState, GroupStateField field) {
 
       case GroupStateField::COLOR:
         if (getBulbMode() == BULB_MODE_COLOR) {
-          uint8_t rgb[3];
-          RGBConverter converter;
-          converter.hsvToRgb(
-            getHue()/360.0,
-            // Default to fully saturated
-            (isSetSaturation() ? getSaturation() : 100)/100.0,
-            1,
-            rgb
-          );
-          JsonObject& color = partialState.createNestedObject("color");
-          color["r"] = rgb[0];
-          color["g"] = rgb[1];
-          color["b"] = rgb[2];
+          applyColor(partialState);
+        }
+        break;
+
+      case GroupStateField::COMPUTED_COLOR:
+        if (getBulbMode() == BULB_MODE_COLOR) {
+          applyColor(partialState);
+        } else {
+          applyColor(partialState, 255, 255, 255);
         }
         break;
 

+ 3 - 0
lib/MiLightState/GroupState.h

@@ -126,6 +126,9 @@ private:
   };
 
   Data state;
+
+  void applyColor(JsonObject& state, uint8_t r, uint8_t g, uint8_t b);
+  void applyColor(JsonObject& state);
 };
 
 extern const BulbId DEFAULT_BULB_ID;

+ 4 - 2
lib/Types/GroupStateField.h

@@ -13,7 +13,8 @@ static const char* STATE_NAMES[] = {
   "mode",
   "kelvin",
   "color_temp",
-  "bulb_mode"
+  "bulb_mode",
+  "computed_color"
 };
 
 enum class GroupStateField {
@@ -28,7 +29,8 @@ enum class GroupStateField {
   MODE,
   KELVIN,
   COLOR_TEMP,
-  BULB_MODE
+  BULB_MODE,
+  COMPUTED_COLOR
 };
 
 class GroupStateFieldHelpers {

+ 2 - 1
web/src/js/script.js

@@ -25,7 +25,8 @@ var GROUP_STATE_KEYS = [
   "mode",
   "kelvin",
   "color_temp",
-  "bulb_mode"
+  "bulb_mode",
+  "computed_color"
 ];
 
 var FORM_SETTINGS_HELP = {