From 9dd689b395d988dfcc79aa634af7c39e6e844d75 Mon Sep 17 00:00:00 2001 From: lumapu Date: Mon, 11 Sep 2023 23:15:33 +0200 Subject: [PATCH] 0.7.49 * add option to strip webUI for ESP8266 (reduce code size, add ESP32 special features; `IF_ESP32` directives) * started to get CMT info into `system` - not finished --- src/CHANGES.md | 2 ++ src/app.h | 8 ++++- src/appInterface.h | 9 +++++ src/web/RestApi.h | 25 +++++++++---- src/web/html/convert.py | 31 +++++++++++++++- src/web/html/setup.html | 28 +++++++++------ src/web/html/style.css | 2 +- src/web/html/system.html | 77 +++++++++++++++++++++++++--------------- 8 files changed, 134 insertions(+), 48 deletions(-) diff --git a/src/CHANGES.md b/src/CHANGES.md index 99a11b38..fd8f2e50 100644 --- a/src/CHANGES.md +++ b/src/CHANGES.md @@ -4,6 +4,8 @@ * merge PR: symbolic icons for mono displays, PR #1136 * merge MI code restructuring PR #1145 * merge Prometheus PR #1148 +* add option to strip webUI for ESP8266 (reduce code size, add ESP32 special features; `IF_ESP32` directives) +* started to get CMT info into `system` - not finished ## 0.7.48 - 2023-09-10 * fix SSD1309 2.42" display pinout diff --git a/src/app.h b/src/app.h index e67a9580..b5dccdae 100644 --- a/src/app.h +++ b/src/app.h @@ -9,9 +9,9 @@ #include #include -#include "appInterface.h" #include "config/settings.h" #include "defines.h" +#include "appInterface.h" #include "hm/hmPayload.h" #include "hm/hmSystem.h" #include "hm/hmRadio.h" @@ -75,11 +75,17 @@ class app : public IApp, public ah::Scheduler { void handleIntr(void) { mNrfRadio.handleIntr(); } + const HmRadio<>& getNrfRadioObj(void) const { + return mNrfRadio; + } #ifdef ESP32 void handleHmsIntr(void) { mCmtRadio.handleIntr(); } + const CmtRadioType& getCmtRadioObj(void) const { + return mCmtRadio; + } #endif uint32_t getUptime() { diff --git a/src/appInterface.h b/src/appInterface.h index a6f85e84..a44d884d 100644 --- a/src/appInterface.h +++ b/src/appInterface.h @@ -14,6 +14,11 @@ #include "ESPAsyncWebServer.h" #endif +//#include "hms/hmsRadio.h" +#if defined(ESP32) +//typedef CmtRadio> CmtRadioType; +#endif + // abstract interface to App. Make members of App accessible from child class // like web or API without forward declaration class IApp { @@ -62,6 +67,10 @@ class IApp { virtual void getNrfRadioCounters(uint32_t *sendCnt, uint32_t *retransmits) = 0; //virtual void getCmtRadioCounters(uint32_t *sendCnt, uint32_t *retransmits) = 0; + + #if defined(ESP32) + //virtual const CmtRadioType& getCmtRadioObj(void) const = 0; + #endif }; #endif /*__IAPP_H__*/ diff --git a/src/web/RestApi.h b/src/web/RestApi.h index b5052d37..aea16517 100644 --- a/src/web/RestApi.h +++ b/src/web/RestApi.h @@ -239,6 +239,9 @@ class RestApi { getGeneric(request, obj); getRadioNrf(obj.createNestedObject(F("radio"))); + #if defined(ESP32) + getRadioCmtInfo(obj.createNestedObject(F("radioCmt"))); + #endif getStatistics(obj.createNestedObject(F("statistics"))); #if defined(ESP32) @@ -490,19 +493,25 @@ class RestApi { obj[F("led_high_active")] = mConfig->led.led_high_active; } + #if defined(ESP32) void getRadioCmt(JsonObject obj) { - obj[F("csb")] = mConfig->cmt.pinCsb; - obj[F("fcsb")] = mConfig->cmt.pinFcsb; - obj[F("gpio3")] = mConfig->cmt.pinIrq; - obj[F("en")] = (bool) mConfig->cmt.enabled; + obj[F("csb")] = mConfig->cmt.pinCsb; + obj[F("fcsb")] = mConfig->cmt.pinFcsb; + obj[F("gpio3")] = mConfig->cmt.pinIrq; + obj[F("en")] = (bool) mConfig->cmt.enabled; + } + + void getRadioCmtInfo(JsonObject obj) { + obj[F("en")] = (bool) mConfig->cmt.enabled; } + #endif void getRadioNrf(JsonObject obj) { obj[F("power_level")] = mConfig->nrf.amplifierPower; obj[F("isconnected")] = mRadio->isChipConnected(); - obj[F("DataRate")] = mRadio->getDataRate(); - obj[F("isPVariant")] = mRadio->isPVariant(); - obj[F("en")] = (bool) mConfig->nrf.enabled; + //obj[F("DataRate")] = mRadio->getDataRate(); + //obj[F("isPVariant")] = mRadio->isPVariant(); + obj[F("en")] = (bool) mConfig->nrf.enabled; } void getSerial(JsonObject obj) { @@ -593,7 +602,9 @@ class RestApi { getNtp(obj.createNestedObject(F("ntp"))); getSun(obj.createNestedObject(F("sun"))); getPinout(obj.createNestedObject(F("pinout"))); + #if defined(ESP32) getRadioCmt(obj.createNestedObject(F("radioCmt"))); + #endif getRadioNrf(obj.createNestedObject(F("radioNrf"))); getSerial(obj.createNestedObject(F("serial"))); getStaticIp(obj.createNestedObject(F("static_ip"))); diff --git a/src/web/html/convert.py b/src/web/html/convert.py index 00f398ac..c4471f3f 100644 --- a/src/web/html/convert.py +++ b/src/web/html/convert.py @@ -6,6 +6,7 @@ import shutil from datetime import date from pathlib import Path import subprocess +Import("env") def get_git_sha(): @@ -60,13 +61,41 @@ def htmlParts(file, header, nav, footer, version): link = 'GIT SHA: ' + get_git_sha() + ' :: ' + version + '' p = p.replace("{#VERSION}", version) p = p.replace("{#VERSION_GIT}", link) + + # remove if - endif ESP32 + p = checkIf(p) + f = open("tmp/" + file, "w") f.write(p); f.close(); return p +def checkIf(data): + if (env['PIOENV'][0:5] == "esp32") or env['PIOENV'][0:4] == "open": + data = data.replace("", "") + data = data.replace("", "") + data = data.replace("/*IF_ESP32*/", "") + data = data.replace("/*ENDIF_ESP32*/", "") + else: + while 1: + start = data.find("") + end = data.find("")+18 + if -1 == start: + break + else: + data = data[0:start] + data[end:] + while 1: + start = data.find("/*IF_ESP32*/") + end = data.find("/*ENDIF_ESP32*/")+15 + if -1 == start: + break + else: + data = data[0:start] + data[end:] + + return data + def convert2Header(inFile, version): - fileType = inFile.split(".")[1] + fileType = inFile.split(".")[1] define = inFile.split(".")[0].upper() define2 = inFile.split(".")[1].upper() inFileVarName = inFile.replace(".", "_") diff --git a/src/web/html/setup.html b/src/web/html/setup.html index 7af9fa88..7ae2a952 100644 --- a/src/web/html/setup.html +++ b/src/web/html/setup.html @@ -35,10 +35,10 @@

Radio (NRF24L01+)

- +

Radio (CMT2300A)

(ESP32 only)
- +

Serial Console

print inverter data
@@ -366,6 +366,8 @@ [15, "D8 (GPIO15)"], [16, "D0 (GPIO16 - no IRQ!)"] ]; + + /*IF_ESP32*/ var esp32pins = [ [255, "off / default"], [0, "GPIO0"], @@ -443,6 +445,7 @@ [47, "GPIO47"], [48, "GPIO48"], ]; + /*ENDIF_ESP32*/ var led_high_active = [ [0, "low active"], [1, "high active"], @@ -796,6 +799,7 @@ ); } + /*IF_ESP32*/ function parseCmtRadio(obj, type, system) { var e = document.getElementById("cmt"); var en = inp("cmtEnable", null, null, ["cb"], "cmtEnable", "checkbox"); @@ -819,6 +823,7 @@ ); } } + /*ENDIF_ESP32*/ function parseSerial(obj) { for(var i of [["serEn", "show_live_data"], ["serDbg", "debug"]]) @@ -833,8 +838,9 @@ var e = document.getElementById("dispPins"); //KEEP this order !!! var pins = [['clock', 'disp_clk'], ['data', 'disp_data'], ['cs', 'disp_cs'], ['dc', 'disp_dc'], ['reset', 'disp_rst']]; - if("ESP32" == type) - pins.push(['busy', 'disp_bsy']); + /*IF_ESP32*/ + pins.push(['busy', 'disp_bsy']); + /*ENDIF_ESP32*/ for(p of pins) { e.append( ml("div", {class: "row mb-3", id: "row_" + p[1]}, [ @@ -848,8 +854,9 @@ // keep display types grouped var opts = [[0, "None"], [2, "SH1106 1.3\" 128X64"], [5, "SSD1306 0.66\" 64X48 (Wemos OLED Shield)"], [4, "SSD1306 0.91\" 128X32"], [1, "SSD1306 0.96\" 128X64"], [6, "SSD1309 2.42\" 128X64"], [3, "Nokia5110"]]; - if("ESP32" == type) - opts.push([10, "ePaper"]); + /*IF_ESP32*/ + opts.push([10, "ePaper"]); + /*ENDIF_ESP32*/ var dispType = sel("disp_typ", opts, obj["disp_typ"]); document.getElementById("dispType").append( ml("div", {class: "row mb-3"}, [ @@ -862,10 +869,10 @@ }); opts = [[0, "0°"], [2, "180°"]]; - if("ESP32" == type) { + /*IF_ESP32*/ opts.push([1, "90°"]); opts.push([3, "270°"]); - } + /*ENDIF_ESP32*/ document.getElementById("dispRot").append( ml("div", {class: "row mb-3"}, [ ml("div", {class: "col-12 col-sm-3 my-2"}, "Rotation"), @@ -916,8 +923,9 @@ parseSun(root["sun"]); parsePinout(root["pinout"], root["system"]["esp_type"], root["system"]); parseNrfRadio(root["radioNrf"], root["pinout"], root["system"]["esp_type"], root["system"]); - if(root["generic"]["esp_type"] == "ESP32") - parseCmtRadio(root["radioCmt"], root["system"]["esp_type"], root["system"]); + /*IF_ESP32*/ + parseCmtRadio(root["radioCmt"], root["system"]["esp_type"], root["system"]); + /*ENDIF_ESP32*/ parseSerial(root["serial"]); parseDisplay(root["display"], root["system"]["esp_type"], root["system"]); getAjax("/api/inverter/list", parseIv); diff --git a/src/web/html/style.css b/src/web/html/style.css index 6d19bd21..9824b723 100644 --- a/src/web/html/style.css +++ b/src/web/html/style.css @@ -756,7 +756,7 @@ h5 { .badge { display: inline-block; padding: .25em .4em; - font-size: 75%; + font-size: 85%; font-weight: 700; line-height: 1; text-align: center; diff --git a/src/web/html/system.html b/src/web/html/system.html index c504057f..1cd828b6 100644 --- a/src/web/html/system.html +++ b/src/web/html/system.html @@ -8,10 +8,7 @@ {#HTML_NAV}
-

                 
-
-
@@ -49,8 +46,8 @@ } } - function badge(success, text) { - return ml("span", {class: "badge badge-" + ((success) ? "success" : "error")}, text); + function badge(success, text, second="error") { + return ml("span", {class: "badge badge-" + ((success) ? "success" : second)}, text); } function headline(text) { @@ -68,19 +65,23 @@ function parseRadio(obj, stat) { const pa = ["MIN (recommended)", "LOW", "HIGH", "MAX"]; - const datarate = ["1 MBps", "2 MBps", "250 kbps"]; - document.getElementById("radio").append( + if(obj.en) + lines = [ + tr("NRF24L01", badge(obj.isconnected, ((obj.isconnected) ? "" : "not ") + "connected")), + tr("Power Level", pa[obj.power_level]) + ]; + else + lines = tr("NRF24L01", badge(false, "not enabled")); + + document.getElementById("info").append( headline("NRF Radio"), - ml("table", {class: "table"}, [ - ml("tbody", {}, [ - tr("NRF24L01", badge(obj.isconnected, ((obj.isconnected) ? "" : "not ") + "connected")), - tr("Power Level", pa[obj.power_level]) - ]) - ]), + ml("table", {class: "table"}, + ml("tbody", {}, lines) + ), headline("Statistics"), - ml("table", {class: "table"}, [ + ml("table", {class: "table"}, ml("tbody", {}, [ tr("TX count", stat.tx_cnt), tr("RX success", stat.rx_success), @@ -89,24 +90,41 @@ tr("RX fragments", stat.frame_cnt), tr("TX retransmits", stat.retransmits) ]) - ]) + ) + ); + } + + /*IF_ESP32*/ + function parseCmt(obj) { + if(obj.en) + lines = [ + tr("CMT2300A", badge(obj.isconnected, ((obj.isconnected) ? "" : "not ") + "connected")) + ]; + else + lines = tr("CMT2300A", badge(false, "not enabled")); + + document.getElementById("info").append( + headline("CMT Radio"), + ml("table", {class: "table"}, + ml("tbody", {}, lines) + ) ); } + /*ENDIF_ESP32*/ function parseIndex(obj) { - if(obj["ts_sunrise"] > 0) { - var h = div(["head", "p-2"]); - var r = div(["row"]); - r.appendChild(div(["col", "a-c"], "Sun")); - h.appendChild(r); - - document.getElementById("sun").append ( - h, - genTabRow("Sunrise", new Date(obj["ts_sunrise"] * 1000).toLocaleString('de-DE')), - genTabRow("Sunset", new Date(obj["ts_sunset"] * 1000).toLocaleString('de-DE')), - genTabRow("Communication start", new Date((obj["ts_sunrise"] - obj["ts_offset"]) * 1000).toLocaleString('de-DE')), - genTabRow("Communication stop", new Date((obj["ts_sunset"] + obj["ts_offset"]) * 1000).toLocaleString('de-DE')), - genTabRow("Night Communication", ((obj["disNightComm"]) ? "disabled" : "enabled")) + if(obj.ts_sunrise > 0) { + document.getElementById("info").append( + headline("Sun"), + ml("table", {class: "table"}, + ml("tbody", {}, [ + tr("Sunrise", new Date(obj.ts_sunrise * 1000).toLocaleString('de-DE')), + tr("Sunset", new Date(obj.ts_sunset * 1000).toLocaleString('de-DE')), + tr("Communication start", new Date((obj.ts_sunrise - obj.ts_offset) * 1000).toLocaleString('de-DE')), + tr("Communication stop", new Date((obj.ts_sunset + obj.ts_offset) * 1000).toLocaleString('de-DE')), + tr("Night behaviour", badge(obj.disNightComm, ((obj.disNightComm) ? "not" : "") + " communicating", "warning")) + ]) + ) ); } } @@ -124,6 +142,9 @@ else { parseSysInfo(obj["system"]); parseRadio(obj["system"]["radio"], obj["system"]["statistics"]); + /*IF_ESP32*/ + parseCmt(obj["system"]["radioCmt"]); + /*ENDIF_ESP32*/ getAjax('/api/index', parseIndex); } document.getElementById("html").innerHTML = obj["html"];