diff --git a/include/Animation/AnimationController.h b/include/Animation/AnimationController.h index c497a2b..3ed4c1b 100644 --- a/include/Animation/AnimationController.h +++ b/include/Animation/AnimationController.h @@ -4,7 +4,7 @@ #include "Animation.h" -#include +#include #include diff --git a/include/Fader.h b/include/Fader.h index cd1713b..0ddc823 100644 --- a/include/Fader.h +++ b/include/Fader.h @@ -2,6 +2,8 @@ #include +#include + class Fader { public: diff --git a/include/UpdateServer.h b/include/UpdateServer.h index 1912209..65bdaa9 100644 --- a/include/UpdateServer.h +++ b/include/UpdateServer.h @@ -2,7 +2,7 @@ #include -#include +#include #include #include "ChallengeResponse.h" diff --git a/include/WebServer.h b/include/WebServer.h index 054fe28..46760b0 100644 --- a/include/WebServer.h +++ b/include/WebServer.h @@ -4,7 +4,7 @@ #include #include -#include +#include #include #include "ChallengeResponse.h" diff --git a/platformio.ini b/platformio.ini index cc8d280..2515b85 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,14 +9,14 @@ ; https://docs.platformio.org/page/projectconf.html [env:nodemcu-32s] -platform = espressif32 +platform = espressif32 @ 5.2.0 board = nodemcu-32s framework = arduino monitor_speed = 115200 lib_deps = - ESP32 Digital RGB LED Drivers - esp32_https_server + ESP32 Digital RGB LED Drivers @ 1.5.4 + esp32_https_server @ 1.0.0 -build_flags = -std=c++11 \ No newline at end of file +build_flags = -std=c++11 diff --git a/src/WebServer.cpp b/src/WebServer.cpp index fe9ed61..9e2670a 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -115,13 +115,12 @@ void WebServer::handleColor(httpsserver::HTTPRequest *req, httpsserver::HTTPResp httpsserver::ResourceParameters * params = req->getParams(); - if(!params->isRequestParameterSet("color")) { + std::string colorstr; + if(!params->getQueryParameter("color", colorstr)) { error400(res, "Parameter 'color' not set."); return; } - std::string colorstr = params->getRequestParameter("color"); - Fader::Color color; std::string errorMessage; if(!parseColor(colorstr, &color, &errorMessage)) { @@ -150,17 +149,18 @@ void WebServer::handleSetAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPRe httpsserver::ResourceParameters * params = req->getParams(); - if(!params->isRequestParameterSet("anim")) { + std::string animstr; + if(!params->getQueryParameter("anim", animstr)) { error400(res, "Parameter 'anim' not set."); return; } - std::istringstream animstr(params->getRequestParameter("anim")); + std::istringstream animstream(animstr); uint32_t anim_id; - animstr >> anim_id; + animstream >> anim_id; - if(animstr.bad() || animstr.fail()) { + if(animstream.bad() || animstream.fail()) { error400(res, "Parameter 'anim' could not be parsed as number."); return; } @@ -203,16 +203,10 @@ void WebServer::handleText(httpsserver::HTTPRequest *req, httpsserver::HTTPRespo httpsserver::ResourceParameters * params = req->getParams(); - if(!params->isRequestParameterSet("text")) { - error400(res, "Required parameter 'text' not set."); - return; - } - Fader::Color color; - if(params->isRequestParameterSet("color")) { - std::string colorstr = params->getRequestParameter("color"); - + std::string colorstr; + if(params->getQueryParameter("color", colorstr)) { std::string errorMessage; if(!parseColor(colorstr, &color, &errorMessage)) { error400(res, errorMessage); @@ -222,8 +216,14 @@ void WebServer::handleText(httpsserver::HTTPRequest *req, httpsserver::HTTPRespo color = Fader::Color{0, 0, 0, 32}; } + std::string text; + if(!params->getQueryParameter("text", text)) { + error400(res, "Required parameter 'text' not set."); + return; + } + Bitmap bmp; - Font::textToBitmap(params->getRequestParameter("text").c_str(), &bmp, color); + Font::textToBitmap(text.c_str(), &bmp, color); WebServer::instance().m_animController->changeAnimation( std::unique_ptr( @@ -237,7 +237,7 @@ void WebServer::handleUpdate(httpsserver::HTTPRequest *req, httpsserver::HTTPRes httpsserver::ResourceParameters * params = req->getParams(); - if(!params->isRequestParameterSet("content")) { + if(!params->isQueryParameterSet("content")) { error400(res, "Send update image as 'content'."); } @@ -290,12 +290,12 @@ void WebServer::handleAuthTest(httpsserver::HTTPRequest *req, httpsserver::HTTPR httpsserver::ResourceParameters * params = req->getParams(); - if(!params->isRequestParameterSet("response")) { + std::string response; + if(!params->getQueryParameter("response", response)) { error400(res, "Parameter 'response' not set."); return; } - std::string response = params->getRequestParameter("response"); bool result = WebServer::instance().m_cr.verify(response); if(result) { diff --git a/src/main.cpp b/src/main.cpp index 320f936..41fdcbd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include "WebServer.h" @@ -193,6 +193,8 @@ static void ledFSM(void) // UDP packet received -> transition to UDP state nextState = UDP; ledState = TRANSITION; + // ensure the correct animation plays after UDP transfers stop + animController.changeAnimation(loadSavedAnimation(), false); } // change to last used animation after some time