Skip to content

Commit 586d3c2

Browse files
committed
another attempt to prevent glitches caused by file access
wait for LEDs send out to finish, then access presets.json
1 parent f9c7828 commit 586d3c2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

wled00/file.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,12 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){
547547
}
548548
#endif
549549

550+
// wait for strip to finish updating, accessing FS during sendout causes glitches
551+
#ifdef ARDUINO_ARCH_ESP32
552+
unsigned wait_start = millis();
553+
while (strip.isUpdating() && (millis() - wait_start < 40)) delay(1); // wait max 40ms
554+
#endif
555+
550556
if(WLED_FS.exists(path) || WLED_FS.exists(path + ".gz")) {
551557
request->send(WLED_FS, path, String(), request->hasArg(F("download")));
552558
return true;

wled00/presets.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ static void doSaveState() {
4949
return;
5050
}
5151

52+
// wait for strip to finish updating, accessing FS during sendout causes glitches
53+
#ifdef ARDUINO_ARCH_ESP32
54+
unsigned wait_start = millis();
55+
while (strip.isUpdating() && (millis() - wait_start < 40)) delay(1); // wait max 40ms
56+
#endif
57+
5258
initPresetsFile(); // just in case if someone deleted presets.json using /edit
5359
JsonObject sObj = doc.to<JsonObject>();
5460

@@ -357,6 +363,12 @@ void savePreset(byte index, const char* pname, JsonObject sObj)
357363
sObj.remove(F("psave"));
358364
if (sObj["n"].isNull()) sObj["n"] = saveName;
359365

366+
// wait for strip to finish updating, accessing FS during sendout causes glitches
367+
#ifdef ARDUINO_ARCH_ESP32
368+
unsigned wait_start = millis();
369+
while (strip.isUpdating() && (millis() - wait_start < 40)) delay(1); // wait max 40ms
370+
#endif
371+
360372
initPresetsFile(); // just in case if someone deleted presets.json using /edit
361373
writeObjectToFileUsingId(getFileName(index<255), index, fileDoc);
362374

0 commit comments

Comments
 (0)