moar topics

This commit is contained in:
2018-09-17 15:34:24 +02:00
parent 939f167dad
commit ad8ba61986
7 changed files with 91 additions and 12 deletions

View File

@@ -32,6 +32,38 @@ struct NeoPixelConfig : public JsonStruct {
}
};
struct NeoPatternMsg : public JsonStruct {
String pattern;
String payload;
String topic;
uint color;
uint color2;
uint totalSteps;
void mapJsonObject(JsonObject& root) {
root["topic"] = topic;
root["pattern"] = pattern;
root["payload"] = payload;
root["color"] = color;
root["color2"] = color2;
root["totalSteps"] = totalSteps;
}
// Map a json object to this struct.
void fromJsonObject(JsonObject& json){
if(!verifyJsonObject(json)){
PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON");
valid = 0;
return;
}
topic = getAttrFromJson(json, "topic");
color = getIntAttrFromJson(json, "color");
color2 = getIntAttrFromJson(json, "color2");
pattern = getAttrFromJson(json, "pattern");
payload = getAttrFromJson(json, "payload");
totalSteps = getIntAttrFromJson(json, "totalSteps", 255);
valid = 1;
};
};
struct NeoPatternDto : public JsonStruct {
uint mode;
uint value;
@@ -51,12 +83,14 @@ struct NeoPatternDto : public JsonStruct {
void fromJsonObject(JsonObject& json){
if(!verifyJsonObject(json)){
PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON");
valid = 0;
return;
}
mode = atoi(json[JSON_MODE_NODE]);
mode = mode < ARRAY_LENGTH(PIXEL_FNCS) ? mode : 0;
value = json[JSON_VALUE];
valueStr = json[JSON_VALUE];
valid = 1;
};
};