clean code changes

This commit is contained in:
proddy
2019-09-23 18:16:52 +02:00
parent 8c779600a2
commit 0bf0377453
5 changed files with 27 additions and 73 deletions

View File

@@ -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 <dump | clear | test [n]>"));
}
@@ -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() {

View File

@@ -294,7 +294,6 @@ class MyESP {
// Crash
void crashClear();
void crashDump();
void crashTest(uint8_t t);
void crashInfo();
// general

View File

@@ -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;

View File

@@ -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);

View File

@@ -1,4 +1,4 @@
'use strict';
"use strict";
module.exports = function () {
return {