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:
@@ -93,6 +93,7 @@ bool readObjectFromFileUsingId(const char* file, uint16_t id, JsonDocument* dest
|
|||||||
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest);
|
bool readObjectFromFile(const char* file, const char* key, JsonDocument* dest);
|
||||||
void updateFSInfo();
|
void updateFSInfo();
|
||||||
void closeFile();
|
void closeFile();
|
||||||
|
void invalidateFileNameCache(); // WLEDMM call when new files were uploaded
|
||||||
|
|
||||||
//hue.cpp
|
//hue.cpp
|
||||||
void handleHue();
|
void handleHue();
|
||||||
|
|||||||
@@ -407,10 +407,33 @@ static String getContentType(AsyncWebServerRequest* request, String filename){
|
|||||||
return "text/plain";
|
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){
|
bool handleFileRead(AsyncWebServerRequest* request, String path){
|
||||||
DEBUG_PRINTLN("WS FileRead: " + path);
|
DEBUG_PRINTLN("WS FileRead: " + path);
|
||||||
if(path.endsWith("/")) path += "index.htm";
|
if(path.endsWith("/")) path += "index.htm";
|
||||||
if(path.indexOf("sec") > -1) return false;
|
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 contentType = getContentType(request, path);
|
||||||
/*String pathWithGz = path + ".gz";
|
/*String pathWithGz = path + ".gz";
|
||||||
if(WLED_FS.exists(pathWithGz)){
|
if(WLED_FS.exists(pathWithGz)){
|
||||||
@@ -421,5 +444,13 @@ bool handleFileRead(AsyncWebServerRequest* request, String path){
|
|||||||
request->send(WLED_FS, path, contentType);
|
request->send(WLED_FS, path, contentType);
|
||||||
return true;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// version code in format yymmddb (b = daily build)
|
// 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.
|
// 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_
|
#define _MoonModules_WLED_
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t
|
|||||||
request->_tempFile.close();
|
request->_tempFile.close();
|
||||||
USER_PRINT(F("File uploaded: ")); // WLEDMM
|
USER_PRINT(F("File uploaded: ")); // WLEDMM
|
||||||
USER_PRINTLN(filename); // WLEDMM
|
USER_PRINTLN(filename); // WLEDMM
|
||||||
|
invalidateFileNameCache(); // WLEDMM
|
||||||
if (filename.equalsIgnoreCase("/cfg.json") || filename.equalsIgnoreCase("cfg.json")) { // WLEDMM
|
if (filename.equalsIgnoreCase("/cfg.json") || filename.equalsIgnoreCase("cfg.json")) { // WLEDMM
|
||||||
request->send(200, "text/plain", F("Configuration restore successful.\nRebooting..."));
|
request->send(200, "text/plain", F("Configuration restore successful.\nRebooting..."));
|
||||||
doReboot = true;
|
doReboot = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user