mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-16 01:58:47 +01:00
load pixel config from json file
This commit is contained in:
63
lib/NeoPattern/NeoPatternDto.h
Normal file
63
lib/NeoPattern/NeoPatternDto.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef __NEOPATTERN_STATE__
|
||||
#define __NEOPATTERN_STATE__
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include "NeoPattern_api_json.h"
|
||||
#include "NeoPattern_api_modes.cpp"
|
||||
#include "utils_print.h"
|
||||
#include "JsonStruct.h"
|
||||
|
||||
// TODO move ARRAY_LENGTH to core lib
|
||||
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
|
||||
|
||||
struct NeoPixelConfig : public JsonStruct {
|
||||
int pin;
|
||||
int length;
|
||||
int brightness;
|
||||
int updateInterval;
|
||||
int defaultColor;
|
||||
void mapJsonObject(JsonObject& root) {
|
||||
root["pin"] = pin;
|
||||
root["length"] = length;
|
||||
root["brightness"] = brightness;
|
||||
root["updateInterval"] = updateInterval;
|
||||
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");
|
||||
}
|
||||
};
|
||||
|
||||
struct NeoPatternDto : public JsonStruct {
|
||||
uint mode;
|
||||
uint value;
|
||||
const char* valueStr;
|
||||
// ------------------------------------------------------------------------------------------
|
||||
//Check if given object is valid and contains fields: JSON_MODE_NODE, JSON_VALUE
|
||||
int verifyJsonObject(JsonObject& json){
|
||||
return json.success()
|
||||
&& json.containsKey(JSON_MODE_NODE)
|
||||
&& json.containsKey(JSON_VALUE);
|
||||
};
|
||||
void mapJsonObject(JsonObject& root) {
|
||||
root[JSON_MODE_NODE] = mode;
|
||||
root[JSON_VALUE] = value;
|
||||
}
|
||||
// Map a json object to this struct.
|
||||
void fromJsonObject(JsonObject& json){
|
||||
if(!verifyJsonObject(json)){
|
||||
PRINT_MSG(Serial, "PatternState.fromJsonObject", "cannot parse JSON");
|
||||
return;
|
||||
}
|
||||
mode = atoi(json[JSON_MODE_NODE]);
|
||||
mode = mode < ARRAY_LENGTH(PIXEL_FNCS) ? mode : 0;
|
||||
value = json[JSON_VALUE];
|
||||
valueStr = json[JSON_VALUE];
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user