|
| 1 | +#include "FWebserver.h" |
| 2 | + |
| 3 | +#include "Animation.h" |
| 4 | +#include "Fade.h" |
| 5 | +#include "FastLEDHub.h" |
| 6 | + |
| 7 | +#include <Arduino.h> |
| 8 | +#include <ESPEssentials.h> |
| 9 | + |
| 10 | +namespace Webserver |
| 11 | +{ |
| 12 | + |
| 13 | + void initialize() |
| 14 | + { |
| 15 | + ESPEssentials::WebServer.on("/reboot", HTTP_GET, [&]() |
| 16 | + { ESP.restart(); }); |
| 17 | + ESPEssentials::WebServer.on("/sunset", HTTP_GET, [&]() |
| 18 | + { |
| 19 | + Fade::begin(Fade::FadeMode::SUNSET); |
| 20 | + ESPEssentials::WebServer.send(200, "text/plain", "Starting sunset."); |
| 21 | + }); |
| 22 | + ESPEssentials::WebServer.on("/alarm", HTTP_GET, [&]() |
| 23 | + { |
| 24 | + Fade::begin(Fade::FadeMode::ALARM); |
| 25 | + ESPEssentials::WebServer.send(200, "text/plain", "Starting alarm."); |
| 26 | + }); |
| 27 | + ESPEssentials::WebServer.on("/stop", HTTP_GET, [&]() |
| 28 | + { |
| 29 | + Fade::stop(); |
| 30 | + FastLEDHub.stop(); |
| 31 | + ESPEssentials::WebServer.send(200, "text/plain", "Animation stopped."); |
| 32 | + }); |
| 33 | + ESPEssentials::WebServer.on("/pause", HTTP_GET, [&]() |
| 34 | + { |
| 35 | + FastLEDHub.pause(); |
| 36 | + ESPEssentials::WebServer.send(200, "text/plain", "Animation paused."); |
| 37 | + }); |
| 38 | + ESPEssentials::WebServer.on("/resume", HTTP_GET, [&]() |
| 39 | + { |
| 40 | + FastLEDHub.resume(); |
| 41 | + ESPEssentials::WebServer.send(200, "text/plain", "Animation resumed."); |
| 42 | + }); |
| 43 | + ESPEssentials::WebServer.on("/toggle", HTTP_GET, [&]() |
| 44 | + { |
| 45 | + FastLEDHub.toggle(); |
| 46 | + ESPEssentials::WebServer.send(200, "text/plain", "Animation toggled."); |
| 47 | + }); |
| 48 | + ESPEssentials::WebServer.on("/restart", HTTP_GET, [&]() |
| 49 | + { |
| 50 | + FastLEDHub.restart(); |
| 51 | + ESPEssentials::WebServer.send(200, "text/plain", "Animation restarted."); |
| 52 | + }); |
| 53 | + ESPEssentials::WebServer.on("/begin", HTTP_GET, [&]() |
| 54 | + { |
| 55 | + if (ESPEssentials::WebServer.hasArg("animation")) |
| 56 | + { |
| 57 | + String animationName = String(ESPEssentials::WebServer.arg("animation")); |
| 58 | + FastLEDHub.begin(FastLEDHub.getAnimation(animationName)); |
| 59 | + ESPEssentials::WebServer.send(200, "text/plain", "Started '" + animationName + "'"); |
| 60 | + } |
| 61 | + else |
| 62 | + { |
| 63 | + uint8_t animationIndex = ESPEssentials::WebServer.hasArg("index") ? ESPEssentials::WebServer.arg("index").toInt() : 0; |
| 64 | + FastLEDHub.begin(FastLEDHub.getAnimation(animationIndex)); |
| 65 | + ESPEssentials::WebServer.send(200, "text/plain", "Started animation #" + String(animationIndex)); |
| 66 | + } |
| 67 | + }); |
| 68 | + } |
| 69 | + |
| 70 | +} // namespace Webserver |
0 commit comments