Merge branch 'main' into 51-button-actions

This commit is contained in:
Raffael Wolf 2025-02-16 17:59:02 +01:00 committed by GitHub
commit 4db484e0f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 41 additions and 0 deletions

View file

@ -17,6 +17,7 @@
#include <LittleFS.h>
#include "routes/config.h"
#include "routes/networks.h"
#include "routes/channels.h"
DMXESPSerial dmx1;
DMXESPSerial dmx2;
@ -335,6 +336,9 @@ void setup()
server.on("/networks", HTTP_GET, [](AsyncWebServerRequest *request)
{ onGetNetworks(request); });
server.on("/dmx", HTTP_GET, [](AsyncWebServerRequest *request)
{ onGetChannels(request, dmx1, dmx2); });
server.onRequestBody([](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
{
if (request->url() == "/config" && request->method() == HTTP_PUT) {

29
src/routes/channels.cpp Normal file
View file

@ -0,0 +1,29 @@
#include "channels.h"
void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSerial dmx2)
{
JsonDocument doc;
for (int channel = 1; channel <= DMXCHANNELS; channel++)
{
uint8_t value = dmx1.read(channel);
if (value != 0)
{
doc["dmx1"][String(channel)] = value;
}
}
for (int channel = 1; channel <= DMXCHANNELS; channel++)
{
uint8_t value = dmx2.read(channel);
if (value != 0)
{
doc["dmx2"][String(channel)] = value;
}
}
String jsonBuffer;
serializeJson(doc, jsonBuffer);
request->send(200, "application/json", jsonBuffer);
}

8
src/routes/channels.h Normal file
View file

@ -0,0 +1,8 @@
#include <Preferences.h>
#include <ArduinoJson.h>
#include <AsyncWebServer_ESP32_W5500.h>
#include "ESPDMX.h"
extern Preferences config;
void onGetChannels(AsyncWebServerRequest *request, DMXESPSerial dmx1, DMXESPSerial dmx2);