rgbwifi/src/server/api.cpp

43 lines
978 B
C++
Raw Normal View History

2020-09-19 17:24:34 +00:00
/*
* ESP8266 RGBW controller
* Copyright 2020 (c) Mark van Renswoude
*
* https://git.x2software.net/pub/RGBWifi
*/
#include "./api.h"
#include "../debug.h"
#include "../global.h"
void handleSetStatic(AsyncWebServerRequest *request)
2020-09-19 17:24:34 +00:00
{
_dln("API :: set/static");
2020-09-19 17:24:34 +00:00
AsyncWebParameter* rParam;
AsyncWebParameter* gParam;
AsyncWebParameter* bParam;
AsyncWebParameter* wParam;
2020-09-19 17:24:34 +00:00
rParam = request->getParam("r");
gParam = request->getParam("g");
bParam = request->getParam("b");
wParam = request->getParam("w");
2020-09-19 17:24:34 +00:00
if (rParam == nullptr || gParam == nullptr || bParam == nullptr || wParam == nullptr)
2020-09-19 17:24:34 +00:00
{
request->send(400);
return;
}
RgbwColor* color = new RgbwColor(rParam->value().toInt(), gParam->value().toInt(), bParam->value().toInt(), wParam->value().toInt());
strip->setStatic(*color);
delete color;
2020-09-19 17:24:34 +00:00
request->send(200);
}
void registerAPIRoutes(AsyncWebServer* server)
{
server->on("/api/set/static", HTTP_GET, handleSetStatic);
2020-09-19 17:24:34 +00:00
}