From 88ceba59cfe40d3d1b010b9e89001c0bc7ddccbf Mon Sep 17 00:00:00 2001 From: Scott Bailey Date: Thu, 2 Sep 2021 22:56:49 -0700 Subject: [PATCH 1/3] Fix error 12 issues --- wled00/ir.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wled00/ir.cpp b/wled00/ir.cpp index 30dae3db8..63b5410f1 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -71,9 +71,11 @@ void decBrightness() // apply preset or fallback to a effect and palette if it doesn't exist void presetFallback(uint8_t presetID, uint8_t effectID, uint8_t paletteID) { + byte prevError = errorFlag; if (!applyPreset(presetID, CALL_MODE_BUTTON)) { effectCurrent = effectID; effectPalette = paletteID; + errorFlag = prevError; //clear error 12 from non-existent preset } } @@ -566,16 +568,17 @@ void decodeIRJson(uint32_t code) char objKey[10]; const char* cmd; String cmdStr; + byte irError; DynamicJsonDocument irDoc(JSON_BUFFER_SIZE); JsonObject fdo; JsonObject jsonCmdObj; sprintf(objKey, "\"0x%X\":", code); - errorFlag = readObjectFromFile("/ir.json", objKey, &irDoc) ? ERR_NONE : ERR_FS_PLOAD; + irError = readObjectFromFile("/ir.json", objKey, &irDoc) ? ERR_NONE : ERR_FS_PLOAD; fdo = irDoc.as(); lastValidCode = 0; - if (!errorFlag) + if (!irError) { cmd = fdo["cmd"]; cmdStr = String(cmd); From a839809eb8b706ac6415175c79534b7705fe5036 Mon Sep 17 00:00:00 2001 From: Scott Bailey Date: Fri, 3 Sep 2021 00:14:07 -0700 Subject: [PATCH 2/3] change random mode choice on presetFallback --- wled00/ir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wled00/ir.cpp b/wled00/ir.cpp index 63b5410f1..b1812caa2 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -595,7 +595,7 @@ void decodeIRJson(uint32_t code) decBrightness(); } else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1; - uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(100); + uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(MODE_COUNT); uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0; presetFallback(p1, p2, p3); } From f1e2439e669ba064de221f84fc25a2bbb11f5e6a Mon Sep 17 00:00:00 2001 From: cschwinne Date: Thu, 9 Sep 2021 12:05:02 +0200 Subject: [PATCH 3/3] Slight IR JSON simplefication Check for missing file No duplicate cmd object --- wled00/const.h | 1 + wled00/ir.cpp | 92 ++++++++++++++++++++++++++------------------------ 2 files changed, 48 insertions(+), 45 deletions(-) diff --git a/wled00/const.h b/wled00/const.h index b8b54dc54..e50616271 100644 --- a/wled00/const.h +++ b/wled00/const.h @@ -215,6 +215,7 @@ #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_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_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) diff --git a/wled00/ir.cpp b/wled00/ir.cpp index b1812caa2..ba22421d2 100644 --- a/wled00/ir.cpp +++ b/wled00/ir.cpp @@ -568,60 +568,62 @@ void decodeIRJson(uint32_t code) char objKey[10]; const char* cmd; String cmdStr; - byte irError; DynamicJsonDocument irDoc(JSON_BUFFER_SIZE); JsonObject fdo; JsonObject jsonCmdObj; sprintf(objKey, "\"0x%X\":", code); - irError = readObjectFromFile("/ir.json", objKey, &irDoc) ? ERR_NONE : ERR_FS_PLOAD; + readObjectFromFile("/ir.json", objKey, &irDoc); fdo = irDoc.as(); 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"]; - cmdStr = String(cmd); - jsonCmdObj = fdo["cmd"]; - if (!cmdStr.isEmpty()) - { - if (cmdStr.startsWith("!")) { - // call limited set of C functions - if (cmdStr.startsWith(F("!incBri"))) { - lastValidCode = code; - incBrightness(); - } else if (cmdStr.startsWith(F("!decBri"))) { - lastValidCode = code; - decBrightness(); - } else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback - uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1; - uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(MODE_COUNT); - uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0; - presetFallback(p1, p2, p3); - } - } else { - // HTTP API command - if (cmdStr.indexOf("~") || fdo["rpt"]) - { - // repeatable action - lastValidCode = code; - } - if (effectCurrent == 0 && cmdStr.indexOf("FP=") > -1) { - // setting palette but it wont show because effect is solid - effectCurrent = FX_MODE_GRADIENT; - } - if (!cmdStr.startsWith("win&")) { - cmdStr = "win&" + cmdStr; - } - handleSet(nullptr, cmdStr, false); - } - } else if (!jsonCmdObj.isNull()) { - // 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; - } + if (cmdStr.startsWith("!")) { + // call limited set of C functions + if (cmdStr.startsWith(F("!incBri"))) { + lastValidCode = code; + incBrightness(); + } else if (cmdStr.startsWith(F("!decBri"))) { + lastValidCode = code; + decBrightness(); + } else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback + uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1; + uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(MODE_COUNT); + uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0; + presetFallback(p1, p2, p3); + } + } else { + // HTTP API command + if (cmdStr.indexOf("~") || fdo["rpt"]) + { + // repeatable action + lastValidCode = code; + } + if (effectCurrent == 0 && cmdStr.indexOf("FP=") > -1) { + // setting palette but it wont show because effect is solid + effectCurrent = FX_MODE_GRADIENT; + } + if (!cmdStr.startsWith("win&")) { + cmdStr = "win&" + cmdStr; + } + handleSet(nullptr, cmdStr, false); + } + } else if (!jsonCmdObj.isNull()) { + // 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; } }