mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 10:04:30 +01:00
uncouple generic web stuff into api plugin
This commit is contained in:
@@ -11,11 +11,12 @@
|
||||
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
|
||||
|
||||
struct NeoPixelConfig : public JsonStruct {
|
||||
int pin;
|
||||
int length;
|
||||
int brightness;
|
||||
int updateInterval;
|
||||
int defaultColor;
|
||||
// FIXME constants!
|
||||
int pin = 4;
|
||||
int length = 8;
|
||||
int brightness = 100;
|
||||
int updateInterval = 100;
|
||||
int defaultColor = 100; // FIXME remove unused
|
||||
void mapJsonObject(JsonObject& root) {
|
||||
root["pin"] = pin;
|
||||
root["length"] = length;
|
||||
@@ -24,11 +25,11 @@ struct NeoPixelConfig : public JsonStruct {
|
||||
root["defaultColor"] = defaultColor;
|
||||
}
|
||||
void fromJsonObject(JsonObject& json) {
|
||||
pin = getIntAttrFromJson(json, "pin");
|
||||
length = getIntAttrFromJson(json, "length");
|
||||
brightness = getIntAttrFromJson(json, "brightness");
|
||||
updateInterval = getIntAttrFromJson(json, "updateInterval");
|
||||
defaultColor = getIntAttrFromJson(json, "defaultColor");
|
||||
pin = getIntAttrFromJson(json, "pin", pin);
|
||||
length = getIntAttrFromJson(json, "length", length);
|
||||
brightness = getIntAttrFromJson(json, "brightness", brightness);
|
||||
updateInterval = getIntAttrFromJson(json, "updateInterval", updateInterval);
|
||||
defaultColor = getIntAttrFromJson(json, "defaultColor", defaultColor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
#ifndef __WSUTILS_H___
|
||||
#define __WSUTILS_H___
|
||||
#ifndef __WebUtils_H___
|
||||
#define __WebUtils_H___
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <AsyncWebSocket.h>
|
||||
#include <ESPAsyncTCP.h>
|
||||
|
||||
class WsUtils {
|
||||
class WebUtils {
|
||||
public:
|
||||
static String getRequestParameterOrDefault(AsyncWebServerRequest *request, String param, String defaultValue, bool isPost = true){
|
||||
if(request->hasParam(param, isPost)) {
|
||||
return request->getParam(param, isPost)->value();
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
static String parseFrame(AwsEventType type, void * arg, uint8_t *data, size_t len) {
|
||||
String msg = "";
|
||||
if(type == WS_EVT_DATA){
|
||||
Reference in New Issue
Block a user