mirror of
https://gitlab.com/zwirbel/illucat.git
synced 2025-12-18 02:36:40 +01:00
49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#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 {
|
|
int pin;
|
|
int length;
|
|
int brightness;
|
|
int updateInterval;
|
|
int 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 |