diff --git a/include/Animation/AnimationController.h b/include/Animation/AnimationController.h index c4f87aa..cb52c1b 100644 --- a/include/Animation/AnimationController.h +++ b/include/Animation/AnimationController.h @@ -7,6 +7,7 @@ #include #include + class AnimationController { public: @@ -17,6 +18,11 @@ class AnimationController NUM_DEFAULT_ANIMATIONS }; + static const constexpr std::array AnimationNames{ + "Hot Fire", + "Cold Fire" + }; + AnimationController(Fader *fader); void changeAnimation(std::unique_ptr anim, bool transition = true); diff --git a/include/WebServer.h b/include/WebServer.h index a83557d..e41543f 100644 --- a/include/WebServer.h +++ b/include/WebServer.h @@ -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); diff --git a/src/WebServer.cpp b/src/WebServer.cpp index f03c556..0d1e409 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -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);