Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions wled00/presets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,25 @@ void handlePresets()
} else
#endif
{
presetErrFlag = readObjectFromFileUsingId(getPresetsFileName(tmpPreset < 255), tmpPreset, pDoc) ? ERR_NONE : ERR_FS_PLOAD;
presetErrFlag = readObjectFromFileUsingId(getPresetsFileName(tmpPreset < 255), tmpPreset, pDoc) ? ERR_NONE : ERR_FS_PLOAD;
}
fdo = pDoc->as<JsonObject>();

// only reset errorflag if previous error was preset-related
// only reset error flag if previous error was preset-related
if ((errorFlag == ERR_NONE) || (errorFlag == ERR_FS_PLOAD)) errorFlag = presetErrFlag;

// is this the boot preset and will the preset set lor
const bool isBootPreset = (tmpMode==CALL_MODE_INIT || tmpPreset==bootPreset);
const bool presetWillSetLor = (!fdo["lor"].isNull() && fdo["lor"].as<int>() > REALTIME_OVERRIDE_NONE);

// During setup, only allow the boot preset itself or safe boot-preset chains.
const bool shouldAllowPresetApply = (
setupComplete || isBootPreset ||
(currentPreset == bootPreset && realtimeOverride > REALTIME_OVERRIDE_NONE) ||
(currentPreset == bootPreset && currentPlaylist > 0 && presetWillSetLor)
);
if (!shouldAllowPresetApply) return;
Comment thread
smitty078 marked this conversation as resolved.
Outdated

//HTTP API commands
const char* httpwin = fdo["win"];
if (httpwin) {
Expand All @@ -194,8 +206,12 @@ void handlePresets()
changePreset = true;
} else {
if (!fdo["seg"].isNull() || !fdo["on"].isNull() || !fdo["bri"].isNull() || !fdo["nl"].isNull() || !fdo["ps"].isNull() || !fdo[F("playlist")].isNull()) changePreset = true;
if (!(tmpMode == CALL_MODE_BUTTON_PRESET && fdo["ps"].is<const char *>() && strchr(fdo["ps"].as<const char *>(),'~') != strrchr(fdo["ps"].as<const char *>(),'~')))
fdo.remove("ps"); // remove load request for presets to prevent recursive crash (if not called by button and contains preset cycling string "1~5~")

// only allow load requests from boot presets that set lor or button calls
const bool isButtonException = (tmpMode == CALL_MODE_BUTTON_PRESET && fdo["ps"].is<const char *>() && strchr(fdo["ps"].as<const char *>(),'~') != strrchr(fdo["ps"].as<const char *>(),'~'))

const bool shouldAllowLoadRequest = (isBootPreset && presetWillSetLor) || (tmpMode == CALL_MODE_BUTTON_PRESET && fdo["ps"].is<const char *>() && strchr(fdo["ps"].as<const char *>(),'~') != strrchr(fdo["ps"].as<const char *>(),'~'))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
if (!shouldAllowLoadRequest) fdo.remove("ps"); // remove load request for presets to prevent recursive crash
deserializeState(fdo, CALL_MODE_NO_NOTIFY, tmpPreset); // may change presetToApply by calling applyPreset()
}
if (!errorFlag && tmpPreset < 255 && changePreset) currentPreset = tmpPreset;
Expand Down Expand Up @@ -282,4 +298,4 @@ void deletePreset(byte index) {
writeObjectToFileUsingId(getPresetsFileName(), index, &empty);
presetsModifiedTime = toki.second(); //unix time
updateFSInfo();
}
}
9 changes: 9 additions & 0 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ void WLED::disableWatchdog() {

void WLED::setup()
{
setupComplete = false; // flag to indicate setup is in progress
#if defined(ARDUINO_ARCH_ESP32) && defined(WLED_DISABLE_BROWNOUT_DET)
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable brownout detection
#endif
Expand Down Expand Up @@ -503,6 +504,12 @@ void WLED::setup()

if (needsCfgSave) serializeConfigToFS(); // usermods required new parameters; need to wait for strip to be initialised #4752

if (bootPreset > 0) {
handlePresets(); // handle boot preset
handlePlaylist(); // handle playlist if preset queued one
handlePresets(); // handle presets again to give a chance for anything queued by the boot preset or playlist
}

if (strcmp(multiWiFi[0].clientSSID, DEFAULT_CLIENT_SSID) == 0 && !configBackupExists())
showWelcomePage = true;

Expand Down Expand Up @@ -595,6 +602,8 @@ void WLED::setup()
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1); //enable brownout detector
#endif
markOTAvalid();

setupComplete = true; // safety check setup function has completed
}

void WLED::beginStrip()
Expand Down
3 changes: 3 additions & 0 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -890,6 +890,9 @@ WLED_GLOBAL byte optionType;
WLED_GLOBAL bool configNeedsWrite _INIT(false); // flag to initiate saving of config
WLED_GLOBAL bool doReboot _INIT(false); // flag to initiate reboot from async handlers

// setup status
WLED_GLOBAL bool setupComplete _INIT(false); // flag for preset loading safety

// status led
#if defined(STATUSLED)
WLED_GLOBAL unsigned long ledStatusLastMillis _INIT(0);
Expand Down