From 593e55af95803ec98a6324434f90385bbe23da64 Mon Sep 17 00:00:00 2001 From: Blaz Kristan Date: Sat, 20 Jan 2024 23:29:45 +0100 Subject: [PATCH] Cleanup. --- usermods/boblight/boblight.h | 2 +- usermods/wireguard/wireguard.h | 16 +++++----- .../usermod_word_clock_matrix.h | 4 +-- wled00/data/index.js | 2 +- wled00/file.cpp | 30 +++++++++---------- wled00/json.cpp | 6 ++-- wled00/wled_server.cpp | 24 +++++++-------- 7 files changed, 42 insertions(+), 42 deletions(-) diff --git a/usermods/boblight/boblight.h b/usermods/boblight/boblight.h index b11a22a83..55803a24d 100644 --- a/usermods/boblight/boblight.h +++ b/usermods/boblight/boblight.h @@ -445,7 +445,7 @@ void BobLightUsermod::pollBob() { //strip.setPixelColor(light_id, RGBW32(red, green, blue, 0)); setRealtimePixel(light_id, red, green, blue, 0); } // currently no support for interpolation or speed, we just ignore this - } else if (input.startsWith(F("sync"))) { + } else if (input.startsWith("sync")) { BobSync(); } else { // Client sent gibberish diff --git a/usermods/wireguard/wireguard.h b/usermods/wireguard/wireguard.h index a83b9fe78..c4e1fd504 100644 --- a/usermods/wireguard/wireguard.h +++ b/usermods/wireguard/wireguard.h @@ -67,8 +67,8 @@ class WireguardUsermod : public Usermod { JsonObject top = root.createNestedObject(F("WireGuard")); top[F("host")] = endpoint_address; top[F("port")] = endpoint_port; - top[F("ip")] = local_ip.toString(); - top[F("psk")] = preshared_key; + top["ip"] = local_ip.toString(); + top["psk"] = preshared_key; top[F("pem")] = private_key; top[F("pub")] = public_key; top[F("tz")] = posix_tz; @@ -77,11 +77,11 @@ class WireguardUsermod : public Usermod { bool readFromConfig(JsonObject& root) { JsonObject top = root[F("WireGuard")]; - if (top["host"].isNull() || top["port"].isNull() || top["ip"].isNull() || top["pem"].isNull() || top["pub"].isNull() || top["tz"].isNull()) { + if (top[F("host")].isNull() || top[F("port")].isNull() || top["ip"].isNull() || top[F("pem")].isNull() || top[F("pub")].isNull() || top[F("tz")].isNull()) { is_enabled = false; return false; } else { - const char* host = top["host"]; + const char* host = top[F("host")]; strncpy(endpoint_address, host, 100); const char* ip_s = top["ip"]; @@ -89,16 +89,16 @@ class WireguardUsermod : public Usermod { sscanf(ip_s, "%u.%u.%u.%u", &ip[0], &ip[1], &ip[2], &ip[3]); local_ip = IPAddress(ip[0], ip[1], ip[2], ip[3]); - const char* pem = top["pem"]; + const char* pem = top[F("pem")]; strncpy(private_key, pem, 45); - const char* pub = top["pub"]; + const char* pub = top[F("pub")]; strncpy(public_key, pub, 45); - const char* tz = top["tz"]; + const char* tz = top[F("tz")]; strncpy(posix_tz, tz, 150); - endpoint_port = top["port"]; + endpoint_port = top[F("port")]; if (!top["psk"].isNull()) { const char* psk = top["psk"]; diff --git a/usermods/word-clock-matrix/usermod_word_clock_matrix.h b/usermods/word-clock-matrix/usermod_word_clock_matrix.h index 582563004..506c1275e 100644 --- a/usermods/word-clock-matrix/usermod_word_clock_matrix.h +++ b/usermods/word-clock-matrix/usermod_word_clock_matrix.h @@ -325,8 +325,8 @@ public: void addToConfig(JsonObject& root) { JsonObject modName = root.createNestedObject("id"); - modName["mdns"] = "wled-word-clock"; - modName["name"] = "WLED WORD CLOCK"; + modName[F("mdns")] = "wled-word-clock"; + modName[F("name")] = "WLED WORD CLOCK"; } uint16_t getId() diff --git a/wled00/data/index.js b/wled00/data/index.js index ec8fcb23a..bdaa3ed60 100644 --- a/wled00/data/index.js +++ b/wled00/data/index.js @@ -2161,7 +2161,7 @@ function selGrp(g) var sel = gId(`segcont`).querySelectorAll(`div[data-set="${g}"]`); var obj = {"seg":[]}; for (let i=0; i<=lSeg; i++) if (gId(`seg${i}`)) obj.seg.push({"id":i,"sel":false}); - if (sel) for (let s of sel||[]) { + for (let s of (sel||[])) { let i = parseInt(s.id.substring(3)); obj.seg[i] = {"id":i,"sel":true}; } diff --git a/wled00/file.cpp b/wled00/file.cpp index 4edbdd6fb..fc3dc7eeb 100644 --- a/wled00/file.cpp +++ b/wled00/file.cpp @@ -377,27 +377,27 @@ void updateFSInfo() { //Un-comment any file types you need static String getContentType(AsyncWebServerRequest* request, String filename){ - if(request->hasArg("download")) return "application/octet-stream"; - else if(filename.endsWith(".htm")) return "text/html"; - else if(filename.endsWith(".html")) return "text/html"; - else if(filename.endsWith(".css")) return "text/css"; - else if(filename.endsWith(".js")) return "application/javascript"; - else if(filename.endsWith(".json")) return "application/json"; - else if(filename.endsWith(".png")) return "image/png"; - else if(filename.endsWith(".gif")) return "image/gif"; - else if(filename.endsWith(".jpg")) return "image/jpeg"; - else if(filename.endsWith(".ico")) return "image/x-icon"; -// else if(filename.endsWith(".xml")) return "text/xml"; -// else if(filename.endsWith(".pdf")) return "application/x-pdf"; -// else if(filename.endsWith(".zip")) return "application/x-zip"; -// else if(filename.endsWith(".gz")) return "application/x-gzip"; + if(request->hasArg(F("download"))) return SET_F("application/octet-stream"); + else if(filename.endsWith(F(".htm"))) return SET_F("text/html"); + else if(filename.endsWith(F(".html"))) return SET_F("text/html"); + else if(filename.endsWith(F(".css"))) return SET_F("text/css"); + else if(filename.endsWith(F(".js"))) return SET_F("application/javascript"); + else if(filename.endsWith(F(".json"))) return SET_F("application/json"); + else if(filename.endsWith(F(".png"))) return SET_F("image/png"); + else if(filename.endsWith(F(".gif"))) return SET_F("image/gif"); + else if(filename.endsWith(F(".jpg"))) return SET_F("image/jpeg"); + else if(filename.endsWith(F(".ico"))) return SET_F("image/x-icon"); +// else if(filename.endsWith(F(".xml"))) return SET_F("text/xml"); +// else if(filename.endsWith(F(".pdf"))) return SET_F("application/x-pdf"); +// else if(filename.endsWith(F(".zip"))) return SET_F("application/x-zip"); +// else if(filename.endsWith(F(".gz"))) return SET_F("application/x-gzip"); return "text/plain"; } bool handleFileRead(AsyncWebServerRequest* request, String path){ DEBUG_PRINTLN("WS FileRead: " + path); if(path.endsWith("/")) path += "index.htm"; - if(path.indexOf("sec") > -1) return false; + if(path.indexOf(F("sec")) > -1) return false; String contentType = getContentType(request, path); /*String pathWithGz = path + ".gz"; if(WLED_FS.exists(pathWithGz)){ diff --git a/wled00/json.cpp b/wled00/json.cpp index 395ee7cbc..90770f834 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -611,7 +611,7 @@ void serializeInfo(JsonObject root) root[F("vid")] = VERSION; root[F("cn")] = F(WLED_CODENAME); - JsonObject leds = root.createNestedObject("leds"); + JsonObject leds = root.createNestedObject(F("leds")); leds[F("count")] = strip.getLengthTotal(); leds[F("pwr")] = BusManager::currentMilliamps(); leds["fps"] = strip.getFps(); @@ -622,7 +622,7 @@ void serializeInfo(JsonObject root) #ifndef WLED_DISABLE_2D if (strip.isMatrix) { - JsonObject matrix = leds.createNestedObject("matrix"); + JsonObject matrix = leds.createNestedObject(F("matrix")); matrix["w"] = Segment::maxWidth; matrix["h"] = Segment::maxHeight; } @@ -702,7 +702,7 @@ void serializeInfo(JsonObject root) } } - JsonObject wifi_info = root.createNestedObject("wifi"); + JsonObject wifi_info = root.createNestedObject(F("wifi")); wifi_info[F("bssid")] = WiFi.BSSIDstr(); int qrssi = WiFi.RSSI(); wifi_info[F("rssi")] = qrssi; diff --git a/wled00/wled_server.cpp b/wled00/wled_server.cpp index 82cc55014..57e0c84b9 100644 --- a/wled00/wled_server.cpp +++ b/wled00/wled_server.cpp @@ -532,18 +532,18 @@ void serveSettings(AsyncWebServerRequest* request, bool post) { const String& url = request->url(); if (url.indexOf("sett") >= 0) { - if (url.indexOf(".js") > 0) subPage = SUBPAGE_JS; - else if (url.indexOf(".css") > 0) subPage = SUBPAGE_CSS; - else if (url.indexOf("wifi") > 0) subPage = SUBPAGE_WIFI; - else if (url.indexOf("leds") > 0) subPage = SUBPAGE_LEDS; - else if (url.indexOf("ui") > 0) subPage = SUBPAGE_UI; - else if (url.indexOf("sync") > 0) subPage = SUBPAGE_SYNC; - else if (url.indexOf("time") > 0) subPage = SUBPAGE_TIME; - else if (url.indexOf("sec") > 0) subPage = SUBPAGE_SEC; - else if (url.indexOf("dmx") > 0) subPage = SUBPAGE_DMX; - else if (url.indexOf("um") > 0) subPage = SUBPAGE_UM; - else if (url.indexOf("2D") > 0) subPage = SUBPAGE_2D; - else if (url.indexOf("lock") > 0) subPage = SUBPAGE_LOCK; + if (url.indexOf(F(".js")) > 0) subPage = SUBPAGE_JS; + else if (url.indexOf(F(".css")) > 0) subPage = SUBPAGE_CSS; + else if (url.indexOf(F("wifi")) > 0) subPage = SUBPAGE_WIFI; + else if (url.indexOf(F("leds")) > 0) subPage = SUBPAGE_LEDS; + else if (url.indexOf(F("ui")) > 0) subPage = SUBPAGE_UI; + else if (url.indexOf( "sync") > 0) subPage = SUBPAGE_SYNC; + else if (url.indexOf( "time") > 0) subPage = SUBPAGE_TIME; + else if (url.indexOf(F("sec")) > 0) subPage = SUBPAGE_SEC; + else if (url.indexOf( "dmx") > 0) subPage = SUBPAGE_DMX; + else if (url.indexOf( "um") > 0) subPage = SUBPAGE_UM; + else if (url.indexOf( "2D") > 0) subPage = SUBPAGE_2D; + else if (url.indexOf(F("lock")) > 0) subPage = SUBPAGE_LOCK; } else if (url.indexOf("/update") >= 0) subPage = SUBPAGE_UPDATE; // update page, for PIN check //else if (url.indexOf("/edit") >= 0) subPage = 10;