Fixed Alexa whites

This commit is contained in:
cschwinne 2020-03-25 00:59:48 +01:00
parent 53f09c0630
commit ed729c32d2
7 changed files with 61 additions and 50 deletions

View File

@ -2,6 +2,10 @@
### Development versions after 0.9.1 release ### Development versions after 0.9.1 release
#### Build 2003222
- Fixed Alexa Whites on non-RGBW lights (bump Espalexa to 2.4.5)
#### Build 2003221 #### Build 2003221
- Moved Cronixie driver from FX library to drawOverlay handler - Moved Cronixie driver from FX library to drawOverlay handler

View File

@ -10,7 +10,7 @@
*/ */
/* /*
* @title Espalexa library * @title Espalexa library
* @version 2.4.4 * @version 2.4.5
* @author Christian Schwinne * @author Christian Schwinne
* @license MIT * @license MIT
* @contributors d-999 * @contributors d-999
@ -49,7 +49,7 @@
#include <WiFiUdp.h> #include <WiFiUdp.h>
#ifdef ESPALEXA_DEBUG #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_DEBUG(x) Serial.print (x)
#define EA_DEBUGLN(x) Serial.println (x) #define EA_DEBUGLN(x) Serial.println (x)
#else #else
@ -164,7 +164,7 @@ private:
json += "\",\"modelid\":\"" + modelidString(dev->getType()); json += "\",\"modelid\":\"" + modelidString(dev->getType());
json += "\",\"manufacturername\":\"Philips\",\"productname\":\"E" + String(static_cast<uint8_t>(dev->getType())); json += "\",\"manufacturername\":\"Philips\",\"productname\":\"E" + String(static_cast<uint8_t>(dev->getType()));
json += "\",\"uniqueid\":\"" + String(encodeLightId(deviceId+1)); json += "\",\"uniqueid\":\"" + String(encodeLightId(deviceId+1));
json += "\",\"swversion\":\"espalexa-2.4.4\"}"; json += "\",\"swversion\":\"espalexa-2.4.5\"}";
return json; return json;
} }
@ -188,7 +188,7 @@ private:
} }
res += "\r\nFree Heap: " + (String)ESP.getFreeHeap(); res += "\r\nFree Heap: " + (String)ESP.getFreeHeap();
res += "\r\nUptime: " + (String)millis(); 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); server->send(200, "text/plain", res);
} }
#endif #endif
@ -370,9 +370,10 @@ public:
if (!discoverable) return; //do not reply to M-SEARCH if not discoverable if (!discoverable) return; //do not reply to M-SEARCH if not discoverable
String request = packetBuffer; String request = packetBuffer;
if(request.indexOf("M-SEARCH") >= 0) { if(request.indexOf("M-SEA") >= 0) { //M-SEARCH
EA_DEBUGLN(request); 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..."); EA_DEBUGLN("Responding search req...");
respondToSearch(); respondToSearch();
} }

View File

@ -122,37 +122,28 @@ uint32_t EspalexaDevice::getRGB()
float temp = 10000/ _ct; //kelvins = 1,000,000/mired (and that /100) float temp = 10000/ _ct; //kelvins = 1,000,000/mired (and that /100)
float r, g, b; float r, g, b;
// Cold white to warm white receiving from Alexa: _ct = 199, 234, 284, 350, 383 (from cold white to warm white) if (temp <= 66) {
switch (_ct) { r = 255;
case 199: rgb[0]=255,rgb[1]=255,rgb[2]=255;rgb[3]=255;break; g = temp;
case 234: rgb[0]=127,rgb[1]=127,rgb[2]=127;rgb[3]=255;break; g = 99.470802 * log(g) - 161.119568;
case 284: rgb[0]=0,rgb[1]=0,rgb[2]=0;rgb[3]=255;break; if (temp <= 19) {
case 350: rgb[0]=130,rgb[1]=90,rgb[2]=0;rgb[3]=255;break; b = 0;
case 383: rgb[0]=255,rgb[1]=153,rgb[2]=0;rgb[3]=255;break; } else {
default: { b = temp-10;
if( temp <= 66 ){ b = 138.517731 * log(b) - 305.044793;
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 {
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) } else if (_mode == EspalexaColorMode::hs)
{ {
float h = ((float)_hue)/65535.0; float h = ((float)_hue)/65535.0;
@ -226,7 +217,7 @@ uint32_t EspalexaDevice::getRGB()
rgb[1] = 255.0*g; rgb[1] = 255.0*g;
rgb[2] = 255.0*b; 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; return _rgb;
} }

View File

@ -5,9 +5,9 @@
typedef class EspalexaDevice; typedef class EspalexaDevice;
typedef void (*BrightnessCallbackFunction) (uint8_t b); typedef std::function<void(uint8_t b)> BrightnessCallbackFunction;
typedef void (*DeviceCallbackFunction) (EspalexaDevice* d); typedef std::function<void(EspalexaDevice* d)> DeviceCallbackFunction;
typedef void (*ColorCallbackFunction) (uint8_t br, uint32_t col); typedef std::function<void(uint8_t br, uint32_t col)> ColorCallbackFunction;
enum class EspalexaColorMode : uint8_t { none = 0, ct = 1, hs = 2, xy = 3 }; 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 }; enum class EspalexaDeviceType : uint8_t { onoff = 0, dimmable = 1, whitespectrum = 2, color = 3, extendedcolor = 4 };

View File

@ -7,7 +7,6 @@
* @author Christian Schwinne * @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 (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). //ESP8266-01 (black) has 1MB flash and can thus fit the whole program. Use 1M(64K SPIFFS).
@ -119,7 +118,7 @@
#endif #endif
//version code in format yymmddb (b = daily build) //version code in format yymmddb (b = daily build)
#define VERSION 2003221 #define VERSION 2003222
char versionString[] = "0.9.1"; char versionString[] = "0.9.1";

View File

@ -61,12 +61,28 @@ void onAlexaChange(EspalexaDevice* dev)
colorUpdated(NOTIFIER_CALL_MODE_ALEXA); colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
} else //color } else //color
{ {
uint32_t color = espalexaDevice->getRGB(); if (espalexaDevice->getColorMode() == EspalexaColorMode::ct) //shade of white
col[3] = ((color >> 24) & 0xFF); // white color from Alexa is "pure white only" {
col[0] = ((color >> 16) & 0xFF); uint16_t ct = espalexaDevice->getCt();
col[1] = ((color >> 8) & 0xFF); if (useRGBW)
col[2] = (color & 0xFF); {
if (useRGBW && col[3] == 0) colorRGBtoRGBW(col); // do not touch white value if EspalexaDevice.cpp did set the white channel 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); colorUpdated(NOTIFIER_CALL_MODE_ALEXA);
} }
} }

View File

@ -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 4: rgb[0]=t,rgb[1]=p,rgb[2]=255;break;
case 5: rgb[0]=255,rgb[1]=p,rgb[2]=q; 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 void colorCTtoRGB(uint16_t mired, byte* rgb) //white spectrum to rgb
{ {
//this is only an approximation using WS2812B with gamma correction enabled //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 { } else {
rgb[0]=237;rgb[1]=255;rgb[2]=239;//150 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) 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; float z = 1.0f - x - y;