Skip to content

Commit

Permalink
(2.4.5) Remove white channel handling that caused RGB to be black if …
Browse files Browse the repository at this point in the history
…White selected
  • Loading branch information
Aircoookie committed Mar 22, 2020
1 parent 3a57512 commit d27bf16
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 35 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Espalexa
version=2.4.4
version=2.4.5
author=Christian Schwinne
maintainer=Christian Schwinne
sentence=Library to control an ESP module with the Alexa voice assistant
Expand Down
8 changes: 4 additions & 4 deletions src/Espalexa.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
/*
* @title Espalexa library
* @version 2.4.4
* @version 2.4.5
* @author Christian Schwinne
* @license MIT
* @contributors d-999
Expand Down Expand Up @@ -49,7 +49,7 @@
#include <WiFiUdp.h>

#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
Expand Down Expand Up @@ -164,7 +164,7 @@ class Espalexa {
json += "\",\"modelid\":\"" + modelidString(dev->getType());
json += "\",\"manufacturername\":\"Philips\",\"productname\":\"E" + String(static_cast<uint8_t>(dev->getType()));
json += "\",\"uniqueid\":\"" + String(encodeLightId(deviceId+1));
json += "\",\"swversion\":\"espalexa-2.4.4\"}";
json += "\",\"swversion\":\"espalexa-2.4.5\"}";

return json;
}
Expand All @@ -188,7 +188,7 @@ class Espalexa {
}
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
Expand Down
51 changes: 21 additions & 30 deletions src/EspalexaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit d27bf16

Please sign in to comment.