@@ -71,9 +71,11 @@ void decBrightness()
7171// apply preset or fallback to a effect and palette if it doesn't exist
7272void 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