handle JSON API commands also
This commit is contained in:
parent
754e3e092a
commit
5acecda6a0
@ -227,7 +227,6 @@ void applyRepeatActions(){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void decodeIR24(uint32_t code)
|
void decodeIR24(uint32_t code)
|
||||||
{
|
{
|
||||||
switch (code) {
|
switch (code) {
|
||||||
@ -545,15 +544,20 @@ Sample:
|
|||||||
{
|
{
|
||||||
"0xFF629D": {"cmd": "T=2", "rpt": true, "label": "Toggle on/off"},
|
"0xFF629D": {"cmd": "T=2", "rpt": true, "label": "Toggle on/off"},
|
||||||
"0xFF9867": {"cmd": "A=~16", "label": "Inc brightness"},
|
"0xFF9867": {"cmd": "A=~16", "label": "Inc brightness"},
|
||||||
"0xFF22DD": {"cmd": "CY=0&PL=1", "label": "Preset 1"}
|
"0xFF22DD": {"cmd": "CY=0&PL=1", "label": "Preset 1"},
|
||||||
|
"0xFF38C7": {"cmd": {"bri": 10}, "label": "Dim to 10"}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
void decodeIRJson(uint32_t code)
|
void decodeIRJson(uint32_t code)
|
||||||
{
|
{
|
||||||
char objKey[10];
|
|
||||||
sprintf(objKey, "0x%X", code);
|
|
||||||
String cmd = "win&";
|
|
||||||
JsonObject fdo;
|
JsonObject fdo;
|
||||||
|
char objKey[10];
|
||||||
|
const char* cmd;
|
||||||
|
String htmlCmd;
|
||||||
|
JsonObject jsonCmdObj;
|
||||||
|
|
||||||
|
sprintf(objKey, "0x%X", code);
|
||||||
|
|
||||||
if (irDoc) {
|
if (irDoc) {
|
||||||
errorFlag = readObjectFromFile("/ir.json", nullptr, irDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
errorFlag = readObjectFromFile("/ir.json", nullptr, irDoc) ? ERR_NONE : ERR_FS_PLOAD;
|
||||||
fdo = irDoc->as<JsonObject>();
|
fdo = irDoc->as<JsonObject>();
|
||||||
@ -564,21 +568,30 @@ void decodeIRJson(uint32_t code)
|
|||||||
fdo = fDoc.as<JsonObject>();
|
fdo = fDoc.as<JsonObject>();
|
||||||
}
|
}
|
||||||
if (!errorFlag) {
|
if (!errorFlag) {
|
||||||
const char* json_cmd;
|
cmd = fdo[objKey]["cmd"];
|
||||||
json_cmd = fdo[objKey]["cmd"];
|
htmlCmd = String(cmd);
|
||||||
cmd += String(json_cmd);
|
jsonCmdObj = fdo[objKey]["cmd"];
|
||||||
if (cmd != "win&") {
|
if (htmlCmd != "") {
|
||||||
|
if (!htmlCmd.startsWith("{") && !htmlCmd.startsWith("win&")) {
|
||||||
|
htmlCmd = "win&" + htmlCmd;
|
||||||
|
}
|
||||||
if (fdo[objKey]["rpt"]) {
|
if (fdo[objKey]["rpt"]) {
|
||||||
lastRepeatableCommand = cmd;
|
lastRepeatableCommand = htmlCmd;
|
||||||
}
|
}
|
||||||
else if (cmd.indexOf("~")) {
|
else if (htmlCmd.indexOf("~")) {
|
||||||
lastRepeatableCommand = cmd;
|
lastRepeatableCommand = htmlCmd;
|
||||||
} else {
|
} else {
|
||||||
lastRepeatableCommand = "";
|
lastRepeatableCommand = "";
|
||||||
}
|
}
|
||||||
|
Serial.println("exec: " + htmlCmd);
|
||||||
|
handleSet(nullptr, htmlCmd, false);
|
||||||
lastValidCode = code;
|
lastValidCode = code;
|
||||||
handleSet(nullptr, cmd, false);
|
} else if (!jsonCmdObj.isNull()) {
|
||||||
|
Serial.println("exec json cmd:");
|
||||||
|
serializeJson(jsonCmdObj, Serial);
|
||||||
|
deserializeState(jsonCmdObj);
|
||||||
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
colorUpdated(NOTIFIER_CALL_MODE_BUTTON);
|
||||||
|
lastValidCode = code;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,7 +605,6 @@ void initIR()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void handleIR()
|
void handleIR()
|
||||||
{
|
{
|
||||||
if (irEnabled > 0 && millis() - irCheckedTime > 120)
|
if (irEnabled > 0 && millis() - irCheckedTime > 120)
|
||||||
|
Loading…
Reference in New Issue
Block a user