Skip to content

Commit

Permalink
(2.3.1) Async always on workaround
Browse files Browse the repository at this point in the history
Replaced CT to RGB code
  • Loading branch information
Aircoookie committed Jan 5, 2019
1 parent d79dc18 commit 4398ea1
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 21 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.3.0
version=2.3.1
author=Christian Schwinne
maintainer=Christian Schwinne
sentence=Library to control an ESP module with the Alexa voice assistant
Expand Down
11 changes: 9 additions & 2 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.3.0
* @version 2.3.1
* @author Christian Schwinne
* @license MIT
* @contributors d-999
Expand Down Expand Up @@ -187,7 +187,6 @@ class Espalexa {
#ifdef ESPALEXA_ASYNC
if (serverAsync == nullptr) {
serverAsync = new AsyncWebServer(80);
//serverAsync->onRequestBody([=](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total){server = request; serveNotFound();});
serverAsync->onNotFound([=](AsyncWebServerRequest *request){server = request; serveNotFound();});
}

Expand Down Expand Up @@ -392,6 +391,14 @@ class Espalexa {
{
server = request; //copy request reference
String req = request->url(); //body from global variable
if (body.length() == 0) //if first body method didn't work, try other
{
EA_DEBUG("BodyMethod2");
if (request->hasParam("body", true)) // This is necessary, otherwise ESP crashes if there is no body
body = request->getParam("body", true)->value();
}
EA_DEBUG("FinalBody: ");
EA_DEBUGLN(body);
#else
bool handleAlexaApiCall(String req, String body)
{
Expand Down
45 changes: 27 additions & 18 deletions src/EspalexaDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,26 +66,35 @@ uint32_t EspalexaDevice::getColorRGB()

if (isColorTemperatureMode())
{
//this is only an approximation using WS2812B with gamma correction enabled
//TODO replace with better formula
if (_ct > 475) {
rgb[0]=255;rgb[1]=199;rgb[2]=92;//500
} else if (_ct > 425) {
rgb[0]=255;rgb[1]=213;rgb[2]=118;//450
} else if (_ct > 375) {
rgb[0]=255;rgb[1]=216;rgb[2]=118;//400
} else if (_ct > 325) {
rgb[0]=255;rgb[1]=234;rgb[2]=140;//350
} else if (_ct > 275) {
rgb[0]=255;rgb[1]=243;rgb[2]=160;//300
} else if (_ct > 225) {
rgb[0]=250;rgb[1]=255;rgb[2]=188;//250
} else if (_ct > 175) {
rgb[0]=247;rgb[1]=255;rgb[2]=215;//200
//TODO tweak a bit to match hue lamp characteristics
//based on https://gist.github.com/paulkaplan/5184275
float temp = 10000/ _ct; //kelvins = 1,000,000/mired (and that /100)
float r, g, b;

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 {
rgb[0]=237;rgb[1]=255;rgb[2]=239;//150
r = temp - 60;
r = 329.698727 * pow(r, -0.13320476);
g = temp - 60;
g = 288.12217 * pow(g, -0.07551485 );
b = 255;
}
} else { //hue + sat mode

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
{ //hue + sat mode
float h = ((float)_hue)/65535.0;
float s = ((float)_sat)/255.0;
byte i = floor(h*6);
Expand Down

0 comments on commit 4398ea1

Please sign in to comment.