Skip to content

Commit 8d4636b

Browse files
authored
Merge pull request wled#2170 from scottrbailey/error-12-fix
Fix error 12 issues
2 parents f59c6e7 + f1e2439 commit 8d4636b

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed

wled00/const.h

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

wled00/ir.cpp

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ void decBrightness()
7171
// apply preset or fallback to a effect and palette if it doesn't exist
7272
void presetFallback(uint8_t presetID, uint8_t effectID, uint8_t paletteID)
7373
{
74+
byte prevError = errorFlag;
7475
if (!applyPreset(presetID, CALL_MODE_BUTTON)) {
7576
effectCurrent = effectID;
7677
effectPalette = paletteID;
78+
errorFlag = prevError; //clear error 12 from non-existent preset
7779
}
7880
}
7981

@@ -572,53 +574,56 @@ void decodeIRJson(uint32_t code)
572574

573575
sprintf(objKey, "\"0x%X\":", code);
574576

575-
errorFlag = readObjectFromFile("/ir.json", objKey, &irDoc) ? ERR_NONE : ERR_FS_PLOAD;
577+
readObjectFromFile("/ir.json", objKey, &irDoc);
576578
fdo = irDoc.as<JsonObject>();
577579
lastValidCode = 0;
578-
if (!errorFlag)
580+
if (fdo.isNull()) {
581+
//the received code does not exist
582+
if (!WLED_FS.exists("/ir.json")) errorFlag = ERR_FS_IRLOAD; //warn if IR file itself doesn't exist
583+
return;
584+
}
585+
586+
jsonCmdObj = fdo["cmd"];
587+
cmdStr = String(jsonCmdObj);
588+
589+
if (!cmdStr.isEmpty())
579590
{
580-
cmd = fdo["cmd"];
581-
cmdStr = String(cmd);
582-
jsonCmdObj = fdo["cmd"];
583-
if (!cmdStr.isEmpty())
584-
{
585-
if (cmdStr.startsWith("!")) {
586-
// call limited set of C functions
587-
if (cmdStr.startsWith(F("!incBri"))) {
588-
lastValidCode = code;
589-
incBrightness();
590-
} else if (cmdStr.startsWith(F("!decBri"))) {
591-
lastValidCode = code;
592-
decBrightness();
593-
} else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback
594-
uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1;
595-
uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(100);
596-
uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0;
597-
presetFallback(p1, p2, p3);
598-
}
599-
} else {
600-
// HTTP API command
601-
if (cmdStr.indexOf("~") || fdo["rpt"])
602-
{
603-
// repeatable action
604-
lastValidCode = code;
605-
}
606-
if (effectCurrent == 0 && cmdStr.indexOf("FP=") > -1) {
607-
// setting palette but it wont show because effect is solid
608-
effectCurrent = FX_MODE_GRADIENT;
609-
}
610-
if (!cmdStr.startsWith("win&")) {
611-
cmdStr = "win&" + cmdStr;
612-
}
613-
handleSet(nullptr, cmdStr, false);
614-
}
615-
} else if (!jsonCmdObj.isNull()) {
616-
// command is JSON object
617-
//allow applyPreset() to reuse JSON buffer, or it would alloc. a second buffer and run out of mem.
618-
fileDoc = &irDoc;
619-
deserializeState(jsonCmdObj, CALL_MODE_BUTTON);
620-
fileDoc = nullptr;
621-
}
591+
if (cmdStr.startsWith("!")) {
592+
// call limited set of C functions
593+
if (cmdStr.startsWith(F("!incBri"))) {
594+
lastValidCode = code;
595+
incBrightness();
596+
} else if (cmdStr.startsWith(F("!decBri"))) {
597+
lastValidCode = code;
598+
decBrightness();
599+
} else if (cmdStr.startsWith(F("!presetF"))) { //!presetFallback
600+
uint8_t p1 = fdo["PL"] ? fdo["PL"] : 1;
601+
uint8_t p2 = fdo["FX"] ? fdo["FX"] : random8(MODE_COUNT);
602+
uint8_t p3 = fdo["FP"] ? fdo["FP"] : 0;
603+
presetFallback(p1, p2, p3);
604+
}
605+
} else {
606+
// HTTP API command
607+
if (cmdStr.indexOf("~") || fdo["rpt"])
608+
{
609+
// repeatable action
610+
lastValidCode = code;
611+
}
612+
if (effectCurrent == 0 && cmdStr.indexOf("FP=") > -1) {
613+
// setting palette but it wont show because effect is solid
614+
effectCurrent = FX_MODE_GRADIENT;
615+
}
616+
if (!cmdStr.startsWith("win&")) {
617+
cmdStr = "win&" + cmdStr;
618+
}
619+
handleSet(nullptr, cmdStr, false);
620+
}
621+
} else if (!jsonCmdObj.isNull()) {
622+
// command is JSON object
623+
//allow applyPreset() to reuse JSON buffer, or it would alloc. a second buffer and run out of mem.
624+
fileDoc = &irDoc;
625+
deserializeState(jsonCmdObj, CALL_MODE_BUTTON);
626+
fileDoc = nullptr;
622627
}
623628
}
624629

0 commit comments

Comments
 (0)