From 1a5a1e694de96886b7e75bd40225241d34d4d2f0 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Fri, 28 Oct 2022 06:11:20 -0500 Subject: [PATCH 1/6] Added Prettier for JavaScript formatting --- .vscode/extensions.json | 7 ++++--- .vscode/settings.json | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 5a9a3973b..09744810c 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,5 +1,6 @@ { - "recommendations": [ - "ms-vscode.cpptools" - ] + "recommendations": [ + "ms-vscode.cpptools", + "esbenp.prettier-vscode" + ] } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 7fa9d6216..d9094df0b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -12,5 +12,8 @@ "editor.insertSpaces": false, "editor.tabSize": 4, "editor.detectIndentation": false, - "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Always, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }" + "C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: LLVM, UseTab: Always, IndentWidth: 4, TabWidth: 4, BreakBeforeBraces: Attach, AllowShortIfStatementsOnASingleLine: false, IndentCaseLabels: false, ColumnLimit: 0, AccessModifierOffset: -4, NamespaceIndentation: All, FixNamespaceComments: false }", + "prettier.tabWidth": 4, + "prettier.useTabs": true, + "prettier.printWidth": 120 } \ No newline at end of file From 0a2c4d19b0bf6b9683d77375baf09bb7c18873e1 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Fri, 28 Oct 2022 06:11:50 -0500 Subject: [PATCH 2/6] Added element check, formatting --- src/httpserver/script.js | 112 +++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 53 deletions(-) diff --git a/src/httpserver/script.js b/src/httpserver/script.js index bc1d32ea7..b99cab678 100644 --- a/src/httpserver/script.js +++ b/src/httpserver/script.js @@ -1,8 +1,8 @@ //The content of this file get set into htmlHeadStyle (new_http.cs) var firstTime, - lastTime, - req = null; + lastTime, + req = null; var onlineFor; var onlineForEl = null; @@ -10,73 +10,79 @@ var getElement = (id) => document.getElementById(id); // refresh status section every 3 seconds function showState() { - clearTimeout(firstTime); - clearTimeout(lastTime); - if (req != null) { - req.abort(); - } - req = new XMLHttpRequest(); - req.onreadystatechange = () => { - if (req.readyState == 4 && req.status == 200) { - if ( - !( - document.activeElement.tagName == "INPUT" && - (document.activeElement.type == "number" || document.activeElement.type == "color") - ) - ) { - getElement("state").innerHTML = req.responseText; - } - clearTimeout(firstTime); - clearTimeout(lastTime); - lastTime = setTimeout(showState, 3e3); - } - }; - req.open("GET", "index?state=1", true); - req.send(); - firstTime = setTimeout(showState, 3e3); + clearTimeout(firstTime); + clearTimeout(lastTime); + if (req != null) { + req.abort(); + } + req = new XMLHttpRequest(); + req.onreadystatechange = () => { + if (req.readyState == 4 && req.status == 200) { + if ( + !( + document.activeElement.tagName == "INPUT" && + (document.activeElement.type == "number" || document.activeElement.type == "color") + ) + ) { + var stateEl = getElement("state"); + if (stateEl) { + stateEl.innerHTML = req.responseText; + } + } + clearTimeout(firstTime); + clearTimeout(lastTime); + lastTime = setTimeout(showState, 3e3); + } + }; + req.open("GET", "index?state=1", true); + req.send(); + firstTime = setTimeout(showState, 3e3); } function fmtUpTime(totalSeconds) { - var days, hours, minutes, seconds; + var days, hours, minutes, seconds; - days = Math.floor(totalSeconds / (24 * 60 * 60)); - totalSeconds = totalSeconds % (24 * 60 * 60); - hours = Math.floor(totalSeconds / (60 * 60)); - totalSeconds = totalSeconds % (60 * 60); - minutes = Math.floor(totalSeconds / 60); - seconds = totalSeconds % 60; + days = Math.floor(totalSeconds / (24 * 60 * 60)); + totalSeconds = totalSeconds % (24 * 60 * 60); + hours = Math.floor(totalSeconds / (60 * 60)); + totalSeconds = totalSeconds % (60 * 60); + minutes = Math.floor(totalSeconds / 60); + seconds = totalSeconds % 60; - if (days > 0) { - return `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; - } - if (hours > 0) { - return `${hours} hours, ${minutes} minutes and ${seconds} seconds`; - } - if (minutes > 0) { - return `${minutes} minutes and ${seconds} seconds`; - } - return `just ${seconds} seconds`; + if (days > 0) { + return `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`; + } + if (hours > 0) { + return `${hours} hours, ${minutes} minutes and ${seconds} seconds`; + } + if (minutes > 0) { + return `${minutes} minutes and ${seconds} seconds`; + } + return `just ${seconds} seconds`; } function updateOnlineFor() { - onlineForEl.textContent = fmtUpTime(++onlineFor); + onlineForEl.textContent = fmtUpTime(++onlineFor); } function onLoad() { - onlineForEl = getElement("onlineFor"); - if (onlineForEl) { - onlineFor = parseInt(onlineForEl.dataset.initial, 10); //We have some valid value - if (onlineFor) { - setInterval(updateOnlineFor, 1000); - } - } + onlineForEl = getElement("onlineFor"); + if (onlineForEl) { + onlineFor = parseInt(onlineForEl.dataset.initial, 10); //We have some valid value + if (onlineFor) { + setInterval(updateOnlineFor, 1000); + } + } - showState(); + showState(); } window.addEventListener("load", onLoad); history.pushState(null, "", "index"); // drop actions like 'toggle' from URL setTimeout(() => { - getElement("changed").innerHTML = ""; + var changedEl = getElement("changed"); + if (changedEl) { + changedEl.innerHTML = ""; + } }, 5e3); // hide change info From e19523510fa7dd1be46739dca3dca26c4e10de2c Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Fri, 28 Oct 2022 06:16:08 -0500 Subject: [PATCH 3/6] Changed button caption --- src/httpserver/http_fns.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/httpserver/http_fns.c b/src/httpserver/http_fns.c index f1c6d38ea..86c5d67bd 100644 --- a/src/httpserver/http_fns.c +++ b/src/httpserver/http_fns.c @@ -36,8 +36,8 @@ #endif #if defined(PLATFORM_BK7231T) || defined(PLATFORM_BK7231N) -int tuya_os_adapt_wifi_all_ap_scan(AP_IF_S **ap_ary, unsigned int *num); -int tuya_os_adapt_wifi_release_ap(AP_IF_S *ap); +int tuya_os_adapt_wifi_all_ap_scan(AP_IF_S** ap_ary, unsigned int* num); +int tuya_os_adapt_wifi_release_ap(AP_IF_S* ap); #endif static char* UNIQUE_ID_FORMAT = " - unique_id: \"%s\"\n"; @@ -548,10 +548,10 @@ int http_fn_index(http_request_t* request) { hprintf255(request, "
Ping watchdog - %i lost, %i ok!
", PingWatchDog_GetTotalLost(), PingWatchDog_GetTotalReceived()); - if (Main_HasWiFiConnected()) - { - hprintf255(request, "
Wifi RSSI: %s (%idBm)
", str_rssi[wifi_rssi_scale(HAL_GetWifiStrength())], HAL_GetWifiStrength()); - } + if (Main_HasWiFiConnected()) + { + hprintf255(request, "
Wifi RSSI: %s (%idBm)
", str_rssi[wifi_rssi_scale(HAL_GetWifiStrength())], HAL_GetWifiStrength()); + } hprintf255(request, "
MQTT State: %s RES: %d(%s)
", (Main_HasMQTTConnected() == 1) ? "connected" : "disconnected", MQTT_GetConnectResult(), get_error_name(MQTT_GetConnectResult())); hprintf255(request, "MQTT ErrMsg: %s
", (MQTT_GetStatusMessage() != NULL) ? MQTT_GetStatusMessage() : ""); @@ -576,8 +576,8 @@ int http_fn_index(http_request_t* request) { { hprintf255(request, "P%02i: NA ", i); } - else - { + else + { hprintf255(request, "P%02i: %i ", i, (int)HAL_PIN_ReadDigitalInput(i)); } if (i % 10 == 9) @@ -589,10 +589,10 @@ int http_fn_index(http_request_t* request) { } #if defined(PLATFORM_BK7231T) || defined(PLATFORM_BK7231N) - if (ota_progress()>=0) - { - hprintf255(request, "
OTA In Progress. Status: %06lXh
", ota_progress()); - } + if (ota_progress() >= 0) + { + hprintf255(request, "
OTA In Progress. Status: %06lXh
", ota_progress()); + } #endif // for normal page loads, show the rest of the HTML @@ -1670,7 +1670,7 @@ int http_fn_cfg(http_request_t* request) { postFormAction(request, "cfg_mac", "Change MAC"); postFormAction(request, "cfg_ping", "Ping Watchdog (Network lost restarter)"); postFormAction(request, "cfg_webapp", "Configure Webapp"); - postFormAction(request, "ha_cfg", "Generate Home Assistant cfg"); + postFormAction(request, "ha_cfg", "Home Assistant Configuration"); postFormAction(request, "ota", "OTA (update software by WiFi)"); postFormAction(request, "cmd_tool", "Execute custom command"); postFormAction(request, "flash_read_tool", "Flash Read Tool"); From 14d8348cd311fa708d89aba5c8e72264b8f3c274 Mon Sep 17 00:00:00 2001 From: Indu Prakash Date: Fri, 28 Oct 2022 06:39:27 -0500 Subject: [PATCH 4/6] Regenerated pageScript --- src/httpserver/new_http.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/httpserver/new_http.c b/src/httpserver/new_http.c index 04227736f..5514d7a9f 100644 --- a/src/httpserver/new_http.c +++ b/src/httpserver/new_http.c @@ -617,9 +617,9 @@ const char htmlHeadStyle[] = "