From 586d3c27325cc8f232e1f0cfc8249f8650c514ee Mon Sep 17 00:00:00 2001 From: Frank <91616163+softhack007@users.noreply.github.com> Date: Mon, 5 Jan 2026 11:22:53 +0100 Subject: [PATCH] another attempt to prevent glitches caused by file access wait for LEDs send out to finish, then access presets.json --- wled00/file.cpp | 6 ++++++ wled00/presets.cpp | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/wled00/file.cpp b/wled00/file.cpp index bf8ef929..6ac56161 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -547,6 +547,12 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){ } #endif + // wait for strip to finish updating, accessing FS during sendout causes glitches + #ifdef ARDUINO_ARCH_ESP32 + unsigned wait_start = millis(); + while (strip.isUpdating() && (millis() - wait_start < 40)) delay(1); // wait max 40ms + #endif + if(WLED_FS.exists(path) || WLED_FS.exists(path + ".gz")) { request->send(WLED_FS, path, String(), request->hasArg(F("download"))); return true; diff --git a/wled00/presets.cpp b/wled00/presets.cpp index c4fe6574..e675b63b 100644 --- a/wled00/presets.cpp +++ b/wled00/presets.cpp @@ -49,6 +49,12 @@ static void doSaveState() { return; } + // wait for strip to finish updating, accessing FS during sendout causes glitches + #ifdef ARDUINO_ARCH_ESP32 + unsigned wait_start = millis(); + while (strip.isUpdating() && (millis() - wait_start < 40)) delay(1); // wait max 40ms + #endif + initPresetsFile(); // just in case if someone deleted presets.json using /edit JsonObject sObj = doc.to(); @@ -357,6 +363,12 @@ void savePreset(byte index, const char* pname, JsonObject sObj) sObj.remove(F("psave")); if (sObj["n"].isNull()) sObj["n"] = saveName; + // wait for strip to finish updating, accessing FS during sendout causes glitches + #ifdef ARDUINO_ARCH_ESP32 + unsigned wait_start = millis(); + while (strip.isUpdating() && (millis() - wait_start < 40)) delay(1); // wait max 40ms + #endif + initPresetsFile(); // just in case if someone deleted presets.json using /edit writeObjectToFileUsingId(getFileName(index<255), index, fileDoc);