Sporttafel-old/src/core/http.cpp

66 lines
1.4 KiB
C++

#include "http.h"
#include <ESPAsyncWebServer.h>
#include <app/App.h>
#include "log.h"
AsyncWebServer server(80);
void httpIndex(AsyncWebServerRequest *request) {
info(request->url().c_str());
request->send(LittleFS, "/index.html", "text/html");
}
void httpActionLeft(AsyncWebServerRequest *request) {
request->send(200);
if (app != nullptr) {
app->left();
}
}
void httpActionUp(AsyncWebServerRequest *request) {
request->send(200);
if (app != nullptr) {
app->up();
}
}
void httpActionDown(AsyncWebServerRequest *request) {
request->send(200);
if (app != nullptr) {
app->down();
}
}
void httpActionRight(AsyncWebServerRequest *request) {
request->send(200);
if (app != nullptr) {
app->right();
}
}
void httpActionCancel(AsyncWebServerRequest *request) {
request->send(200);
if (app != nullptr) {
app->cancel();
}
}
void httpActionConfirm(AsyncWebServerRequest *request) {
request->send(200);
if (app != nullptr) {
app->confirm();
}
}
void httpSetup() {
server.on("/", HTTP_GET, httpIndex);
server.on("/action/left", HTTP_GET, httpActionLeft);
server.on("/action/up", HTTP_GET, httpActionUp);
server.on("/action/down", HTTP_GET, httpActionDown);
server.on("/action/right", HTTP_GET, httpActionRight);
server.on("/action/cancel", HTTP_GET, httpActionCancel);
server.on("/action/confirm", HTTP_GET, httpActionConfirm);
server.begin();
}