slightly reduce flickering during file access

it seems that reading/writing "larger" files from LittleFS causes LED flickering.

This change adds a simple cache for "file not found" results, so that repeated file.exists() calls are avoided.
This commit is contained in:
Frank
2024-04-28 18:57:05 +02:00
parent 3567243d18
commit d058e33df3
4 changed files with 34 additions and 1 deletions

View File

@@ -93,6 +93,7 @@ bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest);
void updateFSInfo();
void closeFile();
void invalidateFileNameCache(); // WLEDMM call when new files were uploaded
//hue.cpp
void handleHue();

View File

@@ -407,10 +407,33 @@ static String getContentType(AsyncWebServerRequest* request, String filename){
return "text/plain";
}
// WLEDMM
static bool haveLedmapFile = true;
static bool haveIndexFile = true;
static bool haveSkinFile = true;
static bool haveICOFile = true;
static bool haveCpalFile = true;
void invalidateFileNameCache() { // reset "file not found" cache
haveLedmapFile = true;
haveIndexFile = true;
haveSkinFile = true;
haveICOFile = true;
haveCpalFile = true;
}
bool handleFileRead(AsyncWebServerRequest* request, String path){
DEBUG_PRINTLN("WS FileRead: " + path);
if(path.endsWith("/")) path += "index.htm";
if(path.indexOf("sec") > -1) return false;
// WLEDMM shortcuts
if ((haveLedmapFile == false) && path.equals("/ledmap.json")) return false;
if ((haveIndexFile == false) && path.equals("/index.htm")) return false;
if ((haveSkinFile == false) && path.equals("/skin.css")) return false;
if ((haveICOFile == false) && path.equals("/favicon.ico")) return false;
if ((haveCpalFile == false) && path.equals("/cpal.htm")) return false;
// WLEDMM toDO: add file caching (PSRAM) for /presets.json an /cfg.json
String contentType = getContentType(request, path);
/*String pathWithGz = path + ".gz";
if(WLED_FS.exists(pathWithGz)){
@@ -421,5 +444,13 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){
request->send(WLED_FS, path, contentType);
return true;
}
//USER_PRINTLN("WS FileRead failed: " + path + " (" + contentType + ")");
// WLEDMM cache "file not found" results (reduces LED flickering during UI activities)
if (path.equals("/ledmap.json")) haveLedmapFile = false;
if (path.equals("/index.htm")) haveIndexFile = false;
if (path.equals("/skin.css")) haveSkinFile = false;
if (path.equals("/favicon.ico")) haveICOFile = false;
if (path.equals("/cpal.htm")) haveCpalFile = false;
return false;
}

View File

@@ -8,7 +8,7 @@
*/
// version code in format yymmddb (b = daily build)
#define VERSION 2404260
#define VERSION 2404280
// WLEDMM - you can check for this define in usermods, to only enabled WLEDMM specific code in the "right" fork. Its not defined in AC WLED.
#define _MoonModules_WLED_

View File

@@ -58,6 +58,7 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t
request->_tempFile.close();
USER_PRINT(F("File uploaded: ")); // WLEDMM
USER_PRINTLN(filename); // WLEDMM
invalidateFileNameCache(); // WLEDMM
if (filename.equalsIgnoreCase("/cfg.json") || filename.equalsIgnoreCase("cfg.json")) { // WLEDMM
request->send(200, "text/plain", F("Configuration restore successful.\nRebooting..."));
doReboot = true;