rgbwifi/src/server/api.cpp

54 lines
1.4 KiB
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 = request->getParam("r");
AsyncWebParameter* gParam = request->getParam("g");
AsyncWebParameter* bParam = request->getParam("b");
AsyncWebParameter* 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 handleSetRainbow(AsyncWebServerRequest *request)
{
_dln("API :: set/rainbow");
AsyncWebParameter* speedParam = request->getParam("speed");
AsyncWebParameter* lightnessParam = request->getParam("lightness");
uint16_t speed = speedParam == nullptr ? 0 : speedParam->value().toInt();
uint8_t lightness = lightnessParam == nullptr ? 0 : lightnessParam->value().toInt();
strip->setRainbow(speed, lightness);
request->send(200);
}
2020-09-19 17:24:34 +00:00
void registerAPIRoutes(AsyncWebServer* server)
{
server->on("/api/set/static", HTTP_GET, handleSetStatic);
server->on("/api/set/rainbow", HTTP_GET, handleSetRainbow);
2020-09-19 17:24:34 +00:00
}