Slight IR JSON simplefication

Check for missing file
No duplicate cmd object
This commit is contained in:
cschwinne 2021-09-09 12:05:02 +02:00
parent a839809eb8
commit f1e2439e66
2 changed files with 48 additions and 45 deletions

View File

@ -215,6 +215,7 @@
#define ERR_FS_BEGIN 10 // Could not init filesystem (no partition?) #define ERR_FS_BEGIN 10 // Could not init filesystem (no partition?)
#define ERR_FS_QUOTA 11 // The FS is full or the maximum file size is reached #define ERR_FS_QUOTA 11 // The FS is full or the maximum file size is reached
#define ERR_FS_PLOAD 12 // It was attempted to load a preset that does not exist #define ERR_FS_PLOAD 12 // It was attempted to load a preset that does not exist
#define ERR_FS_IRLOAD 13 // It was attempted to load an IR JSON cmd, but the "ir.json" file does not exist
#define ERR_FS_GENERAL 19 // A general unspecified filesystem error occured #define ERR_FS_GENERAL 19 // A general unspecified filesystem error occured
#define ERR_OVERTEMP 30 // An attached temperature sensor has measured above threshold temperature (not implemented) #define ERR_OVERTEMP 30 // An attached temperature sensor has measured above threshold temperature (not implemented)
#define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented) #define ERR_OVERCURRENT 31 // An attached current sensor has measured a current above the threshold (not implemented)

View File

@ -568,60 +568,62 @@ void decodeIRJson(uint32_t code)
char objKey[10]; char objKey[10];
const char* cmd; const char* cmd;
String cmdStr; String cmdStr;
byte irError;
DynamicJsonDocument irDoc(JSON_BUFFER_SIZE); DynamicJsonDocument irDoc(JSON_BUFFER_SIZE);
JsonObject fdo; JsonObject fdo;
JsonObject jsonCmdObj; JsonObject jsonCmdObj;
sprintf(objKey, "\"0x%X\":", code); sprintf(objKey, "\"0x%X\":", code);
irError = readObjectFromFile("/ir.json", objKey, &irDoc) ? ERR_NONE : ERR_FS_PLOAD; readObjectFromFile("/ir.json", objKey, &irDoc);
fdo = irDoc.as<JsonObject>(); fdo = irDoc.as<JsonObject>();
lastValidCode = 0; lastValidCode = 0;
if (!irError) if (fdo.isNull()) {
//the received code does not exist
if (!WLED_FS.exists("/ir.json")) errorFlag = ERR_FS_IRLOAD; //warn if IR file itself doesn't exist
return;
}
jsonCmdObj = fdo["cmd"];
cmdStr = String(jsonCmdObj);
if (!cmdStr.isEmpty())
{ {
cmd = fdo["cmd"]; if (cmdStr.startsWith("!")) {
cmdStr = String(cmd); // call limited set of C functions
jsonCmdObj = fdo["cmd"]; if (cmdStr.startsWith(F("!incBri"))) {
if (!cmdStr.isEmpty()) lastValidCode = code;
{ incBrightness();
if (cmdStr.startsWith("!")) { } else if (cmdStr.startsWith(F("!decBri"))) {
// call limited set of C functions lastValidCode = code;
if (cmdStr.startsWith(F("!incBri"))) { decBrightness();
lastValidCode = code; } else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback
incBrightness(); uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1;
} else if (cmdStr.startsWith(F("!decBri"))) { uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(MODE_COUNT);
lastValidCode = code; uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0;
decBrightness(); presetFallback(p1, p2, p3);
} else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback }
uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1; } else {
uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(MODE_COUNT); // HTTP API command
uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0; if (cmdStr.indexOf("~") || fdo["rpt"])
presetFallback(p1, p2, p3); {
} // repeatable action
} else { lastValidCode = code;
// HTTP API command }
if (cmdStr.indexOf("~") || fdo["rpt"]) if (effectCurrent == 0 && cmdStr.indexOf("FP=") > -1) {
{ // setting palette but it wont show because effect is solid
// repeatable action effectCurrent = FX_MODE_GRADIENT;
lastValidCode = code; }
} if (!cmdStr.startsWith("win&")) {
if (effectCurrent == 0 && cmdStr.indexOf("FP=") > -1) { cmdStr = "win&" + cmdStr;
// setting palette but it wont show because effect is solid }
effectCurrent = FX_MODE_GRADIENT; handleSet(nullptr, cmdStr, false);
} }
if (!cmdStr.startsWith("win&")) { } else if (!jsonCmdObj.isNull()) {
cmdStr = "win&" + cmdStr; // command is JSON object
} //allow applyPreset() to reuse JSON buffer, or it would alloc. a second buffer and run out of mem.
handleSet(nullptr, cmdStr, false); fileDoc = &irDoc;
} deserializeState(jsonCmdObj, CALL_MODE_BUTTON);
} else if (!jsonCmdObj.isNull()) { fileDoc = nullptr;
// command is JSON object
//allow applyPreset() to reuse JSON buffer, or it would alloc. a second buffer and run out of mem.
fileDoc = &irDoc;
deserializeState(jsonCmdObj, CALL_MODE_BUTTON);
fileDoc = nullptr;
}
} }
} }