From ed729c32d2d2e6a6ffefa29cd009047eadea08dd Mon Sep 17 00:00:00 2001 From: cschwinne Date: Wed, 25 Mar 2020 00:59:48 +0100 Subject: [PATCH] Fixed Alexa whites --- CHANGELOG.md | 4 ++ wled00/src/dependencies/espalexa/Espalexa.h | 13 ++--- .../dependencies/espalexa/EspalexaDevice.cpp | 51 ++++++++----------- .../dependencies/espalexa/EspalexaDevice.h | 6 +-- wled00/wled00.ino | 3 +- wled00/wled12_alexa.ino | 28 +++++++--- wled00/wled14_colors.ino | 6 +-- 7 files changed, 61 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 321eea8a..68243a3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ### Development versions after 0.9.1 release +#### Build 2003222 + +- Fixed Alexa Whites on non-RGBW lights (bump Espalexa to 2.4.5) + #### Build 2003221 - Moved Cronixie driver from FX library to drawOverlay handler diff --git a/wled00/src/dependencies/espalexa/Espalexa.h b/wled00/src/dependencies/espalexa/Espalexa.h index 49c9b6a9..7a1312f8 100644 --- a/wled00/src/dependencies/espalexa/Espalexa.h +++ b/wled00/src/dependencies/espalexa/Espalexa.h @@ -10,7 +10,7 @@ */ /* * @title Espalexa library - * @version 2.4.4 + * @version 2.4.5 * @author Christian Schwinne * @license MIT * @contributors d-999 @@ -49,7 +49,7 @@ #include #ifdef ESPALEXA_DEBUG - #pragma message "Espalexa 2.4.4 debug mode" + #pragma message "Espalexa 2.4.5 debug mode" #define EA_DEBUG(x) Serial.print (x) #define EA_DEBUGLN(x) Serial.println (x) #else @@ -164,7 +164,7 @@ private: json += "\",\"modelid\":\"" + modelidString(dev->getType()); json += "\",\"manufacturername\":\"Philips\",\"productname\":\"E" + String(static_cast(dev->getType())); json += "\",\"uniqueid\":\"" + String(encodeLightId(deviceId+1)); - json += "\",\"swversion\":\"espalexa-2.4.4\"}"; + json += "\",\"swversion\":\"espalexa-2.4.5\"}"; return json; } @@ -188,7 +188,7 @@ private: } res += "\r\nFree Heap: " + (String)ESP.getFreeHeap(); res += "\r\nUptime: " + (String)millis(); - res += "\r\n\r\nEspalexa library v2.4.4 by Christian Schwinne 2020"; + res += "\r\n\r\nEspalexa library v2.4.5 by Christian Schwinne 2020"; server->send(200, "text/plain", res); } #endif @@ -370,9 +370,10 @@ public: if (!discoverable) return; //do not reply to M-SEARCH if not discoverable String request = packetBuffer; - if(request.indexOf("M-SEARCH") >= 0) { + if(request.indexOf("M-SEA") >= 0) { //M-SEARCH EA_DEBUGLN(request); - if(request.indexOf("upnp:rootdevice") > 0 || request.indexOf("asic:1") > 0 || request.indexOf("ssdp:all") > 0) { + //match upnp:rootdevice, device:basic:1, ssdp:all and ssdp:discover + if(request.indexOf("np:rootd") > 0 || request.indexOf("asic:1") > 0 || request.indexOf("dp:all") > 0 || request.indexOf("dp:dis") > 0) { EA_DEBUGLN("Responding search req..."); respondToSearch(); } diff --git a/wled00/src/dependencies/espalexa/EspalexaDevice.cpp b/wled00/src/dependencies/espalexa/EspalexaDevice.cpp index 25d70bb0..520cf441 100644 --- a/wled00/src/dependencies/espalexa/EspalexaDevice.cpp +++ b/wled00/src/dependencies/espalexa/EspalexaDevice.cpp @@ -122,37 +122,28 @@ uint32_t EspalexaDevice::getRGB() float temp = 10000/ _ct; //kelvins = 1,000,000/mired (and that /100) float r, g, b; -// Cold white to warm white receiving from Alexa: _ct = 199, 234, 284, 350, 383 (from cold white to warm white) - switch (_ct) { - case 199: rgb[0]=255,rgb[1]=255,rgb[2]=255;rgb[3]=255;break; - case 234: rgb[0]=127,rgb[1]=127,rgb[2]=127;rgb[3]=255;break; - case 284: rgb[0]=0,rgb[1]=0,rgb[2]=0;rgb[3]=255;break; - case 350: rgb[0]=130,rgb[1]=90,rgb[2]=0;rgb[3]=255;break; - case 383: rgb[0]=255,rgb[1]=153,rgb[2]=0;rgb[3]=255;break; - default: { - if( temp <= 66 ){ - r = 255; - g = temp; - g = 99.470802 * log(g) - 161.119568; - if( temp <= 19){ - b = 0; - } else { - b = temp-10; - b = 138.517731 * log(b) - 305.044793; - } - } else { - r = temp - 60; - r = 329.698727 * pow(r, -0.13320476); - g = temp - 60; - g = 288.12217 * pow(g, -0.07551485 ); - b = 255; - } - - rgb[0] = (byte)constrain(r,0.1,255.1); - rgb[1] = (byte)constrain(g,0.1,255.1); - rgb[2] = (byte)constrain(b,0.1,255.1); + if (temp <= 66) { + r = 255; + g = temp; + g = 99.470802 * log(g) - 161.119568; + if (temp <= 19) { + b = 0; + } else { + b = temp-10; + b = 138.517731 * log(b) - 305.044793; } + } else { + r = temp - 60; + r = 329.698727 * pow(r, -0.13320476); + g = temp - 60; + g = 288.12217 * pow(g, -0.07551485 ); + b = 255; } + + rgb[0] = (byte)constrain(r,0.1,255.1); + rgb[1] = (byte)constrain(g,0.1,255.1); + rgb[2] = (byte)constrain(b,0.1,255.1); + } else if (_mode == EspalexaColorMode::hs) { float h = ((float)_hue)/65535.0; @@ -226,7 +217,7 @@ uint32_t EspalexaDevice::getRGB() rgb[1] = 255.0*g; rgb[2] = 255.0*b; } - _rgb = ((rgb[3] << 24) | (rgb[0] << 16) | (rgb[1] << 8) | (rgb[2])); //white value is only >0 if Alexa did provide a CT value, RGB colors will not be touched. + _rgb = ((rgb[0] << 16) | (rgb[1] << 8) | (rgb[2])); return _rgb; } diff --git a/wled00/src/dependencies/espalexa/EspalexaDevice.h b/wled00/src/dependencies/espalexa/EspalexaDevice.h index a6644916..4785591f 100644 --- a/wled00/src/dependencies/espalexa/EspalexaDevice.h +++ b/wled00/src/dependencies/espalexa/EspalexaDevice.h @@ -5,9 +5,9 @@ typedef class EspalexaDevice; -typedef void (*BrightnessCallbackFunction) (uint8_t b); -typedef void (*DeviceCallbackFunction) (EspalexaDevice* d); -typedef void (*ColorCallbackFunction) (uint8_t br, uint32_t col); +typedef std::function BrightnessCallbackFunction; +typedef std::function DeviceCallbackFunction; +typedef std::function ColorCallbackFunction; enum class EspalexaColorMode : uint8_t { none = 0, ct = 1, hs = 2, xy = 3 }; enum class EspalexaDeviceType : uint8_t { onoff = 0, dimmable = 1, whitespectrum = 2, color = 3, extendedcolor = 4 }; diff --git a/wled00/wled00.ino b/wled00/wled00.ino index 55f714f5..7c64796d 100644 --- a/wled00/wled00.ino +++ b/wled00/wled00.ino @@ -7,7 +7,6 @@ * @author Christian Schwinne */ - //ESP8266-01 (blue) got too little storage space to work with all features of WLED. To use it, you must use ESP8266 Arduino Core v2.4.2 and the setting 512K(No SPIFFS). //ESP8266-01 (black) has 1MB flash and can thus fit the whole program. Use 1M(64K SPIFFS). @@ -119,7 +118,7 @@ #endif //version code in format yymmddb (b = daily build) -#define VERSION 2003221 +#define VERSION 2003222 char versionString[] = "0.9.1"; diff --git a/wled00/wled12_alexa.ino b/wled00/wled12_alexa.ino index 9c27041b..5163640e 100644 --- a/wled00/wled12_alexa.ino +++ b/wled00/wled12_alexa.ino @@ -61,12 +61,28 @@ void onAlexaChange(EspalexaDevice* dev) colorUpdated(NOTIFIER_CALL_MODE_ALEXA); } else //color { - uint32_t color = espalexaDevice->getRGB(); - col[3] = ((color >> 24) & 0xFF); // white color from Alexa is "pure white only" - col[0] = ((color >> 16) & 0xFF); - col[1] = ((color >> 8) & 0xFF); - col[2] = (color & 0xFF); - if (useRGBW && col[3] == 0) colorRGBtoRGBW(col); // do not touch white value if EspalexaDevice.cpp did set the white channel + if (espalexaDevice->getColorMode() == EspalexaColorMode::ct) //shade of white + { + uint16_t ct = espalexaDevice->getCt(); + if (useRGBW) + { + switch (ct) { //these values empirically look good on RGBW + case 199: col[0]=255; col[1]=255; col[2]=255; col[3]=255; break; + case 234: col[0]=127; col[1]=127; col[2]=127; col[3]=255; break; + case 284: col[0]= 0; col[1]= 0; col[2]= 0; col[3]=255; break; + case 350: col[0]=130; col[1]= 90; col[2]= 0; col[3]=255; break; + case 383: col[0]=255; col[1]=153; col[2]= 0; col[3]=255; break; + } + } else { + colorCTtoRGB(ct, col); + } + } else { + uint32_t color = espalexaDevice->getRGB(); + + col[0] = ((color >> 16) & 0xFF); + col[1] = ((color >> 8) & 0xFF); + col[2] = ( color & 0xFF); + } colorUpdated(NOTIFIER_CALL_MODE_ALEXA); } } diff --git a/wled00/wled14_colors.ino b/wled00/wled14_colors.ino index c8ca0dcb..a1db307a 100644 --- a/wled00/wled14_colors.ino +++ b/wled00/wled14_colors.ino @@ -57,10 +57,9 @@ void colorHStoRGB(uint16_t hue, byte sat, byte* rgb) //hue, sat to rgb case 4: rgb[0]=t,rgb[1]=p,rgb[2]=255;break; case 5: rgb[0]=255,rgb[1]=p,rgb[2]=q; } - if (useRGBW) colorRGBtoRGBW(col); + if (useRGBW && strip.rgbwMode == RGBW_MODE_LEGACY) colorRGBtoRGBW(col); } -#ifndef WLED_DISABLE_HUESYNC void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb { //this is only an approximation using WS2812B with gamma correction enabled @@ -81,9 +80,10 @@ void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb } else { rgb[0]=237;rgb[1]=255;rgb[2]=239;//150 } - if (useRGBW) colorRGBtoRGBW(col); + if (useRGBW && strip.rgbwMode == RGBW_MODE_LEGACY) colorRGBtoRGBW(col); } +#ifndef WLED_DISABLE_HUESYNC void colorXYtoRGB(float x, float y, byte* rgb) //coordinates to rgb (https://www.developers.meethue.com/documentation/color-conversions-rgb-xy) { float z = 1.0f - x - y;