rgbwifi/src/server/api.cpp

43 lines
978 B
C++

/*
* 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)
{
_dln("API :: set/static");
AsyncWebParameter* rParam;
AsyncWebParameter* gParam;
AsyncWebParameter* bParam;
AsyncWebParameter* wParam;
rParam = request->getParam("r");
gParam = request->getParam("g");
bParam = request->getParam("b");
wParam = request->getParam("w");
if (rParam == nullptr || gParam == nullptr || bParam == nullptr || wParam == nullptr)
{
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;
request->send(200);
}
void registerAPIRoutes(AsyncWebServer* server)
{
server->on("/api/set/static", HTTP_GET, handleSetStatic);
}