From 0bf0377453b8673a0e0eacdc9d8a21589751f3cc Mon Sep 17 00:00:00 2001 From: proddy Date: Mon, 23 Sep 2019 18:16:52 +0200 Subject: [PATCH] clean code changes --- src/MyESP.cpp | 50 +----------------------------- src/MyESP.h | 1 - src/custom.js | 21 ++++++------- src/websrc/myesp.js | 26 +++++++++------- tools/webfilesbuilder/gulp.meta.js | 2 +- 5 files changed, 27 insertions(+), 73 deletions(-) diff --git a/src/MyESP.cpp b/src/MyESP.cpp index d8b40810e..4ac8cb929 100644 --- a/src/MyESP.cpp +++ b/src/MyESP.cpp @@ -1009,9 +1009,6 @@ void MyESP::_telnetCommand(char * commandLine) { crashDump(); } else if (strcmp(cmd, "clear") == 0) { crashClear(); - } else if ((strcmp(cmd, "test") == 0) && (wc == 3)) { - char * value = _telnet_readWord(false); - crashTest(atoi(value)); } else { myDebug_P(PSTR("Error. Usage: crash ")); } @@ -1705,7 +1702,7 @@ bool MyESP::_fs_loadConfig() { JsonObject ntp = doc["ntp"]; _ntp_server = strdup(ntp["server"] | ""); _ntp_interval = ntp["interval"] | 60; - if (_ntp_interval == 0) + if (_ntp_interval < 2) _ntp_interval = 60; _ntp_enabled = ntp["enabled"]; @@ -2131,52 +2128,7 @@ void MyESP::crashDump() { myDebug_P(PSTR("\nTo clean this dump use the command: %scrash clear%s\n"), COLOR_BOLD_ON, COLOR_BOLD_OFF); } -/* - * Force some crashes to test if stack collection works - */ -void MyESP::crashTest(uint8_t t) { - if (t == 1) { - myDebug_P(PSTR("[CRASH] Attempting to divide by zero ...")); - int result, zero; - zero = 0; - result = 1 / zero; - Serial.printf("Result = %d", result); - } - - if (t == 2) { - myDebug_P(PSTR("[CRASH] Attempting to read through a pointer to no object ...")); - int * nullPointer; - nullPointer = nullptr; - // null pointer dereference - read - // attempt to read a value through a null pointer - Serial.println(*nullPointer); - } - - if (t == 3) { - myDebug_P(PSTR("[CRASH] Crashing with hardware WDT (%ld ms) ...\n"), millis()); - ESP.wdtDisable(); - while (true) { - // stay in an infinite loop doing nothing - // this way other process can not be executed - // - // Note: - // Hardware wdt kicks in if software wdt is unable to perfrom - // Nothing will be saved in EEPROM for the hardware wdt - } - } - - if (t == 4) { - myDebug_P(PSTR("[CRASH] Crashing with software WDT (%ld ms) ...\n"), millis()); - while (true) { - // stay in an infinite loop doing nothing - // this way other process can not be executed - } - } -} - #else -void MyESP::crashTest(uint8_t t) { -} void MyESP::crashClear() { } void MyESP::crashDump() { diff --git a/src/MyESP.h b/src/MyESP.h index 7a27e4829..7eb1ea782 100644 --- a/src/MyESP.h +++ b/src/MyESP.h @@ -294,7 +294,6 @@ class MyESP { // Crash void crashClear(); void crashDump(); - void crashTest(uint8_t t); void crashInfo(); // general diff --git a/src/custom.js b/src/custom.js index cc7974bb5..40ae95d10 100644 --- a/src/custom.js +++ b/src/custom.js @@ -10,7 +10,7 @@ var custom_config = { "shower_alert": false, "publish_time": 120 } -} +}; function custom_commit() { websock.send(JSON.stringify(custom_config)); @@ -95,16 +95,15 @@ function listCustomStats() { for (var i = 0; i < obj.length; i++) { var l = document.createElement("li"); var type = obj[i].type; - if (type == 1) { - var color = "list-group-item-success"; - } else if (type == 2) { - var color = "list-group-item-info"; - } else if (type == 3) { - var color = "list-group-item-warning"; - } else if (type == 4) { - var color = "list-group-item-success"; - } else { - var color = ""; + var color = ""; + if (type === 1) { + color = "list-group-item-success"; + } else if (type === 2) { + color = "list-group-item-info"; + } else if (type === 3) { + color = "list-group-item-warning"; + } else if (type === 4) { + color = "list-group-item-success"; } l.innerHTML = obj[i].model + " (Version:" + obj[i].version + " ProductID:" + obj[i].productid + " DeviceID:0x" + obj[i].deviceid + ")"; l.className = "list-group-item " + color; diff --git a/src/websrc/myesp.js b/src/websrc/myesp.js index 7533b8463..9f5d3af55 100644 --- a/src/websrc/myesp.js +++ b/src/websrc/myesp.js @@ -6,6 +6,8 @@ var utcSeconds; var data = []; var ajaxobj; +var custom_config = {}; + var config = { "command": "configfile", "network": { @@ -68,6 +70,14 @@ function syncBrowserTime() { $("#ntp").click(); } +function handleNTPON() { + document.getElementById("forcentp").style.display = "block"; +} + +function handleNTPOFF() { + document.getElementById("forcentp").style.display = "none"; +} + function listntp() { websock.send("{\"command\":\"gettime\"}"); @@ -247,14 +257,6 @@ function handleAP() { document.getElementById("inputtohide").style.display = "block"; } -function handleNTPON() { - document.getElementById("forcentp").style.display = "block"; -} - -function handleNTPOFF() { - document.getElementById("forcentp").style.display = "none"; -} - function listnetwork() { document.getElementById("inputtohide").value = config.network.ssid; document.getElementById("wifipass").value = config.network.password; @@ -435,16 +437,18 @@ function getContent(contentname) { var customname2 = " " + ajaxobj.customname; $("#customname2").text(customname2); + var elem; + if (config.network.wmode === 0) { - var elem = document.getElementById("helpurl"); - var helpurl = ajaxobj.appurl + "/wiki" + elem = document.getElementById("helpurl"); + var helpurl = ajaxobj.appurl + "/wiki"; elem.setAttribute("href", helpurl); document.getElementById("helpurl").style.display = "block"; } else { document.getElementById("helpurl").style.display = "none"; } - var elem = document.getElementById("appurl"); + elem = document.getElementById("appurl"); elem.setAttribute("href", ajaxobj.appurl); $("#appurl2").text(ajaxobj.appurl); diff --git a/tools/webfilesbuilder/gulp.meta.js b/tools/webfilesbuilder/gulp.meta.js index 2e7f3dc5b..24f7dcbb4 100644 --- a/tools/webfilesbuilder/gulp.meta.js +++ b/tools/webfilesbuilder/gulp.meta.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; module.exports = function () { return {