WebServer: Added /api/listanim to list animations

This commit is contained in:
Thomas Kolb 2019-12-14 23:12:57 +01:00
parent b1f1647260
commit 1410124e49
3 changed files with 29 additions and 0 deletions

View file

@ -7,6 +7,7 @@
#include <FreeRTOS.h>
#include <freertos/semphr.h>
class AnimationController
{
public:
@ -17,6 +18,11 @@ class AnimationController
NUM_DEFAULT_ANIMATIONS
};
static const constexpr std::array<const char*, NUM_DEFAULT_ANIMATIONS> AnimationNames{
"Hot Fire",
"Cold Fire"
};
AnimationController(Fader *fader);
void changeAnimation(std::unique_ptr<Animation> anim, bool transition = true);

View file

@ -40,6 +40,7 @@ class WebServer
static void handleRoot(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);
static void handleColor(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);
static void handleSetAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);
static void handleListAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);
static void handleChallenge(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);
static void handleAuthTest(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);
static void handleUpdate(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res);

View file

@ -142,6 +142,25 @@ void WebServer::handleSetAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPRe
true);
}
void WebServer::handleListAnim(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res)
{
res->setHeader("Content-Type", "application/json");
res->print("[");
for(size_t i = 0; i < AnimationController::AnimationNames.size(); i++) {
res->print("{\"id\": ");
res->print(i);
res->print("}");
if(i < AnimationController::AnimationNames.size()-1) {
res->print(",");
}
}
res->print("]");
}
void WebServer::handleUpdate(httpsserver::HTTPRequest *req, httpsserver::HTTPResponse *res)
{
res->setHeader("Content-Type", "text/plain");
@ -243,6 +262,8 @@ void WebServer::serverTask(void *arg)
new httpsserver::ResourceNode("/api/color", "GET", WebServer::handleColor);
httpsserver::ResourceNode *nodeAPISetAnim =
new httpsserver::ResourceNode("/api/setanim", "GET", WebServer::handleSetAnim);
httpsserver::ResourceNode *nodeAPIListAnim =
new httpsserver::ResourceNode("/api/listanim", "GET", WebServer::handleListAnim);
httpsserver::ResourceNode *nodeAPIUpdate =
new httpsserver::ResourceNode("/api/update", "POST", WebServer::handleUpdate);
httpsserver::ResourceNode *nodeAPIChallenge =
@ -259,6 +280,7 @@ void WebServer::serverTask(void *arg)
server.m_server->registerNode(nodeRoot);
server.m_server->registerNode(nodeAPIColor);
server.m_server->registerNode(nodeAPISetAnim);
server.m_server->registerNode(nodeAPIListAnim);
server.m_server->registerNode(nodeAPIUpdate);
server.m_server->registerNode(nodeAPIChallenge);
server.m_server->registerNode(nodeAPIAuthTest);