From cc69f8a469f347a285099dc9064f3b8a5ebf91d4 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 17 Jan 2023 14:53:02 +0100 Subject: [PATCH 01/10] pointers can always be be casted to long --- examples/gui-generic-api/gui-generic-api.ino | 2 +- examples/gui/gui.ino | 2 +- examples/tabbedGui/tabbedGui.ino | 2 +- pio_examples/gui/src/gui.ino | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/gui-generic-api/gui-generic-api.ino b/examples/gui-generic-api/gui-generic-api.ino index 44f0119..c268280 100644 --- a/examples/gui-generic-api/gui-generic-api.ino +++ b/examples/gui-generic-api/gui-generic-api.ino @@ -57,7 +57,7 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(int(param))); + Serial.println(String("param: ") + String(long(param))); switch (type) { case B_DOWN: diff --git a/examples/gui/gui.ino b/examples/gui/gui.ino index 2356fd6..f4315be 100644 --- a/examples/gui/gui.ino +++ b/examples/gui/gui.ino @@ -62,7 +62,7 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(int(param))); + Serial.println(String("param: ") + String(long(param))); switch (type) { case B_DOWN: diff --git a/examples/tabbedGui/tabbedGui.ino b/examples/tabbedGui/tabbedGui.ino index b02ae4b..f3ff7d8 100644 --- a/examples/tabbedGui/tabbedGui.ino +++ b/examples/tabbedGui/tabbedGui.ino @@ -56,7 +56,7 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(int(param))); + Serial.println(String("param: ") + String(long(param))); switch (type) { case B_DOWN: diff --git a/pio_examples/gui/src/gui.ino b/pio_examples/gui/src/gui.ino index d5a9e7c..2fd6460 100644 --- a/pio_examples/gui/src/gui.ino +++ b/pio_examples/gui/src/gui.ino @@ -62,7 +62,7 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(int(param))); + Serial.println(String("param: ") + String(long(param))); switch (type) { case B_DOWN: From be8cf73d550ac534f12407082ca986f0a21c8998 Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 12 May 2023 15:02:32 -0400 Subject: [PATCH 02/10] Exposed WebServer instance --- src/ESPUI.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ESPUI.h b/src/ESPUI.h index b68c74d..fb42039 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -206,6 +206,7 @@ public: void jsonDom(uint16_t startidx, AsyncWebSocketClient* client = nullptr, bool Updating = false); Verbosity verbosity; + AsyncWebServer* server; protected: friend class ESPUIclient; @@ -217,7 +218,6 @@ protected: void RemoveToBeDeletedControls(); - AsyncWebServer* server; AsyncWebSocket* ws; const char* basicAuthUsername = nullptr; From c3bf9c5d00df75cac7c6a353ff4b346413584112 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Tue, 18 Jul 2023 19:49:58 +0200 Subject: [PATCH 03/10] reduce memory footprint --- README.md | 2 +- src/ESPUI.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++-- src/ESPUI.h | 24 ++++++++---------- src/ESPUIclient.cpp | 48 ++++++++++++++++++++++++++++++------ 4 files changed, 109 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index f4d5978..4659d70 100644 --- a/README.md +++ b/README.md @@ -495,7 +495,7 @@ ESPUI includes a range of advanced features that can customise your UIs. ### Dynamic Visibility -Cotrols can be made visible or invisible at runtime with the `updateVisibility()` function. +Controls can be made visible or invisible at runtime with the `updateVisibility()` function. ``` ESPUI.updateVisibility(controlId, false); diff --git a/src/ESPUI.cpp b/src/ESPUI.cpp index abbe40a..90f84e3 100644 --- a/src/ESPUI.cpp +++ b/src/ESPUI.cpp @@ -13,6 +13,61 @@ #include "dataTabbedcontentJS.h" #include "dataZeptoJS.h" +#if ESP8266 +#include +#endif + +static String heapInfo (const __FlashStringHelper* mode) +{ +#if ESP8266 + + uint32_t hfree; + uint32_t hmax; + uint8_t hfrag; + String result; + result.reserve(128); + +#ifdef UMM_HEAP_IRAM + // here esp8266 is configurerd to use an extra 16KB (i)ram + { + HeapSelectIram useInstructionRamHere; + ESP.getHeapStats(&hfree, &hmax, &hfrag); + } + result += F("IRAM: free: "); + result += hfree; + result += F(" max: "); + result += hmax; + result += F(" frag: "); + result += hfrag; + result += "%\n"; +#endif // !UMM_HEAP_IRAM + { + HeapSelectDram useRegularRamHere; + ESP.getHeapStats(&hfree, &hmax, &hfrag); + } + result += F("DRAM: free: "); + result += hfree; + result += F(" max: "); + result += hmax; + result += F(" frag: "); + result += hfrag; + result += "%\n"; + +#else // !ESP8266 + + result += ESP.getFreeHeap(); + result += ' '; + +#endif // !ESP8266 + + result += mode; + + return result; +} + + + + // ################# LITTLEFS functions #if defined(ESP32) void listDir(const char* dirname, uint8_t levels) @@ -1260,7 +1315,8 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c return request->requestAuthentication(); } - request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In LITTLEFS mode"); + request->send(200, "text/plain", heapInfo(F("In LITTLEFS mode"))); + }); server->onNotFound([this](AsyncWebServerRequest* request) { @@ -1418,7 +1474,7 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas return request->requestAuthentication(); } - request->send(200, "text/plain", String(ESP.getFreeHeap()) + " In Memorymode"); + request->send(200, "text/plain", heapInfo(F("In Memorymode"))); }); server->onNotFound([this](AsyncWebServerRequest* request) { diff --git a/src/ESPUI.h b/src/ESPUI.h index fb42039..878097f 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -87,20 +87,20 @@ enum Verbosity : uint8_t class ESPUIClass { public: + +#ifdef ESP32 ESPUIClass() { - verbosity = Verbosity::Quiet; - jsonUpdateDocumentSize = 2000; - jsonInitialDocumentSize = 8000; - sliderContinuous = false; -#ifdef ESP32 ControlsSemaphore = xSemaphoreCreateMutex(); xSemaphoreGive(ControlsSemaphore); -#endif // def ESP32 } - unsigned int jsonUpdateDocumentSize; - unsigned int jsonInitialDocumentSize; - bool sliderContinuous; + SemaphoreHandle_t ControlsSemaphore = NULL; +#endif // def ESP32 + + unsigned int jsonUpdateDocumentSize = 2000; + unsigned int jsonInitialDocumentSize = 8000; + unsigned int jsonChunkNumberMax = 0; + bool sliderContinuous = false; void onWsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len); bool captivePortal = true; @@ -205,17 +205,13 @@ public: void jsonReload(); void jsonDom(uint16_t startidx, AsyncWebSocketClient* client = nullptr, bool Updating = false); - Verbosity verbosity; + Verbosity verbosity = Verbosity::Quiet; AsyncWebServer* server; protected: friend class ESPUIclient; friend class ESPUIcontrol; -#ifdef ESP32 - SemaphoreHandle_t ControlsSemaphore = NULL; -#endif // def ESP32 - void RemoveToBeDeletedControls(); AsyncWebSocket* ws; diff --git a/src/ESPUIclient.cpp b/src/ESPUIclient.cpp index 9b7d561..9bce217 100644 --- a/src/ESPUIclient.cpp +++ b/src/ESPUIclient.cpp @@ -2,6 +2,42 @@ #include "ESPUIclient.h" #include "ESPUIcontrol.h" +// JSONSlave: +// helper to process exact JSON serialization size +// it takes ~2ms on esp8266 and avoid large String reallocation which is really worth the cost +class JSONSlave: public Print +{ +public: + size_t write (uint8_t c) override { counter++; return 1; } + size_t write (const uint8_t* buf, size_t count) override { counter += count; return count; } + size_t get_counter () { return counter; } + + static size_t serializedSize (JsonDocument& doc) + { + JSONSlave counter; + serializeJson(doc, counter); + return counter.get_counter(); + } + + static size_t serialize (JsonDocument& doc, String& str) + { + size_t s = serializedSize(doc) + 10; // 10 is paranoid + str.reserve(s); + serializeJson(doc, str); + return s; + } + + static String toString (JsonDocument& doc) + { + String str; + serialize(doc, str); + return str; + } + +protected: + size_t counter = 0; +}; + ESPUIclient::ESPUIclient(AsyncWebSocketClient * _client): client(_client) { @@ -309,7 +345,7 @@ uint32_t ESPUIclient::prepareJSONChunk(uint16_t startindex, elementcount++; control->MarshalControl(item, InUpdateMode); - if (rootDoc.overflowed()) + if (rootDoc.overflowed() || (ESPUI.jsonChunkNumberMax > 0 && (elementcount % ESPUI.jsonChunkNumberMax) == 0)) { // String("prepareJSONChunk: too much data in the message. Remove the last entry"); if (1 == elementcount) @@ -407,9 +443,8 @@ bool ESPUIclient::SendControlsToClient(uint16_t startidx, if (ESPUI.verbosity >= Verbosity::VerboseJSON) { Serial.println(F("ESPUIclient:SendControlsToClient: Sending elements --------->")); - String json; - serializeJson(document, json); - Serial.println(json); + serializeJson(document, Serial); + Serial.println(); } #endif @@ -454,10 +489,7 @@ bool ESPUIclient::SendJsonDocToWebSocket(DynamicJsonDocument& document) break; } - String json; - json.reserve(document.size() / 2); - json.clear(); - serializeJson(document, json); + String json = JSONSlave::toString(document); #if defined(DEBUG_ESPUI) if (ESPUI.verbosity >= Verbosity::VerboseJSON) From b45f4f73566ac8b87faba9f0c39fd07b217a727a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 19 Jul 2023 12:07:25 +0200 Subject: [PATCH 04/10] update examples with esp8266 specifics --- examples/completeExample/completeExample.cpp | 20 ++++++++++++++++++++ examples/completeExample/completeExample.ino | 1 + examples/gui-generic-api/gui-generic-api.ino | 18 ++++++++++++++++++ examples/gui/gui.ino | 18 ++++++++++++++++++ examples/tabbedGui/tabbedGui.ino | 18 ++++++++++++++++++ src/ESPUI.h | 5 +++++ 6 files changed, 80 insertions(+) create mode 100644 examples/completeExample/completeExample.ino diff --git a/examples/completeExample/completeExample.cpp b/examples/completeExample/completeExample.cpp index ecae5c2..364a4f9 100644 --- a/examples/completeExample/completeExample.cpp +++ b/examples/completeExample/completeExample.cpp @@ -26,8 +26,18 @@ #include #include #else +// esp8266 #include #include +#include +#ifndef MMU_IRAM_HEAP +#warning Try MMU option '2nd heap shared' in 'tools' IDE menu (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#option-summary) +#warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) +#warning then check http:///heap +#endif // MMU_IRAM_HEAP +#ifndef DEBUG_ESP_OOM +#error on ESP8266 and ESPUI, you must define OOM debug option when developping +#endif #endif //Settings @@ -62,6 +72,11 @@ volatile bool updates = false; // This is the main function which builds our GUI void setUpUI() { + +#ifdef ESP8266 + { HeapSelectIram doAllocationsInIRAM; +#endif + //Turn off verbose debugging ESPUI.setVerbosity(Verbosity::Quiet); @@ -274,6 +289,11 @@ void setUpUI() { //Finally, start up the UI. //This should only be called once we are connected to WiFi. ESPUI.begin(HOSTNAME); + +#ifdef ESP8266 + } // HeapSelectIram +#endif + } //This callback generates and applies inline styles to a bunch of controls to change their colour. diff --git a/examples/completeExample/completeExample.ino b/examples/completeExample/completeExample.ino new file mode 100644 index 0000000..ff7bd09 --- /dev/null +++ b/examples/completeExample/completeExample.ino @@ -0,0 +1 @@ +// placeholder diff --git a/examples/gui-generic-api/gui-generic-api.ino b/examples/gui-generic-api/gui-generic-api.ino index c268280..815e66d 100644 --- a/examples/gui-generic-api/gui-generic-api.ino +++ b/examples/gui-generic-api/gui-generic-api.ino @@ -8,7 +8,17 @@ DNSServer dnsServer; #if defined(ESP32) #include #else +// esp8266 #include +#include +#ifndef MMU_IRAM_HEAP +#warning Try MMU option '2nd heap shared' in 'tools' IDE menu (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#option-summary) +#warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) +#warning then check http:///heap +#endif // MMU_IRAM_HEAP +#ifndef DEBUG_ESP_OOM +#error on ESP8266 and ESPUI, you must define OOM debug option when developping +#endif #endif const char* ssid = "ESPUI"; @@ -235,6 +245,10 @@ void setup(void) Serial.print("IP address: "); Serial.println(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP()); +#ifdef ESP8266 + { HeapSelectIram doAllocationsInIRAM; +#endif + status = ESPUI.addControl(ControlType::Label, "Status:", "Stop", ControlColor::Turquoise); uint16_t select1 = ESPUI.addControl( @@ -281,6 +295,10 @@ void setup(void) */ ESPUI.begin("ESPUI Control"); + +#ifdef ESP8266 + } // HeapSelectIram +#endif } void loop(void) diff --git a/examples/gui/gui.ino b/examples/gui/gui.ino index f4315be..1aca2f1 100644 --- a/examples/gui/gui.ino +++ b/examples/gui/gui.ino @@ -8,7 +8,17 @@ DNSServer dnsServer; #if defined(ESP32) #include #else +// esp8266 #include +#include +#ifndef MMU_IRAM_HEAP +#warning Try MMU option '2nd heap shared' in 'tools' IDE menu (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#option-summary) +#warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) +#warning then check http:///heap +#endif // MMU_IRAM_HEAP +#ifndef DEBUG_ESP_OOM +#error on ESP8266 and ESPUI, you must define OOM debug option when developping +#endif #endif const char* ssid = "ESPUI"; @@ -225,6 +235,10 @@ void setup(void) Serial.print("IP address: "); Serial.println(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP()); +#ifdef ESP8266 + { HeapSelectIram doAllocationsInIRAM; +#endif + statusLabelId = ESPUI.label("Status:", ControlColor::Turquoise, "Stop"); millisLabelId = ESPUI.label("Millis:", ControlColor::Emerald, "0"); ESPUI.button("Push Button", &buttonCallback, ControlColor::Peterriver, "Press"); @@ -257,6 +271,10 @@ void setup(void) * password, for example begin("ESPUI Control", "username", "password") */ ESPUI.begin("ESPUI Control"); + +#ifdef ESP8266 + } // HeapSelectIram +#endif } void loop(void) diff --git a/examples/tabbedGui/tabbedGui.ino b/examples/tabbedGui/tabbedGui.ino index f3ff7d8..7aa0b2f 100644 --- a/examples/tabbedGui/tabbedGui.ino +++ b/examples/tabbedGui/tabbedGui.ino @@ -8,7 +8,17 @@ DNSServer dnsServer; #if defined(ESP32) #include #else +// esp8266 #include +#include +#ifndef MMU_IRAM_HEAP +#warning Try MMU option '2nd heap shared' in 'tools' IDE menu (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#option-summary) +#warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) +#warning then check http:///heap +#endif // MMU_IRAM_HEAP +#ifndef DEBUG_ESP_OOM +#error on ESP8266 and ESPUI, you must define OOM debug option when developping +#endif #endif const char* ssid = "ESPUI"; @@ -233,6 +243,10 @@ void setup(void) Serial.print("IP address: "); Serial.println(WiFi.getMode() == WIFI_AP ? WiFi.softAPIP() : WiFi.localIP()); +#ifdef ESP8266 + { HeapSelectIram doAllocationsInIRAM; +#endif + uint16_t tab1 = ESPUI.addControl(ControlType::Tab, "Settings 1", "Settings 1"); uint16_t tab2 = ESPUI.addControl(ControlType::Tab, "Settings 2", "Settings 2"); uint16_t tab3 = ESPUI.addControl(ControlType::Tab, "Settings 3", "Settings 3"); @@ -279,6 +293,10 @@ void setup(void) */ ESPUI.begin("ESPUI Control"); + +#ifdef ESP8266 + } // HeapSelectIram +#endif } void loop(void) diff --git a/src/ESPUI.h b/src/ESPUI.h index 878097f..43464fe 100644 --- a/src/ESPUI.h +++ b/src/ESPUI.h @@ -98,8 +98,13 @@ public: #endif // def ESP32 unsigned int jsonUpdateDocumentSize = 2000; +#ifdef ESP8266 + unsigned int jsonInitialDocumentSize = 2000; + unsigned int jsonChunkNumberMax = 5; +#else unsigned int jsonInitialDocumentSize = 8000; unsigned int jsonChunkNumberMax = 0; +#endif bool sliderContinuous = false; void onWsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len); bool captivePortal = true; From f08cd5c51a7f9bcef94ef98da433fa28bd44540f Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Mon, 13 Mar 2023 19:25:41 +0100 Subject: [PATCH 05/10] =?UTF-8?q?Icon=20changes,=20thanks=20to=20Mark?= =?UTF-8?q?=C2=A0Kinsley?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Lukas Bachschwell --- src/dataIndexHTML.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/dataIndexHTML.h b/src/dataIndexHTML.h index 4cdf77a..08b5cb8 100644 --- a/src/dataIndexHTML.h +++ b/src/dataIndexHTML.h @@ -1,5 +1,27 @@ +// Old PNG File +//const char HTML_INDEX[] PROGMEM = R"=====( +// Control

Control
Offline


+//)====="; + +// SVG Water Drop Icon +//const char HTML_INDEX[] PROGMEM = R"=====( +// Control

Control
Offline


+//)====="; + +// Apple icon only +//const char HTML_INDEX[] PROGMEM = R"=====( +// Control

Control
Offline


+//)====="; + +// SVG Logo Only +//const char HTML_INDEX[] PROGMEM = R"=====( +// Control

Control
Offline


+//)====="; + +// SVG Logo & Apple icon const char HTML_INDEX[] PROGMEM = R"=====( - Control

Control
Offline


+Control

Control
Offline


)====="; + const uint8_t HTML_INDEX_GZIP[916] PROGMEM = { 31,139,8,0,210,8,51,99,2,255,133,148,235,115,162,58,20,192,255,21,174,159,238,157,221,22,95,181,237,174,56,19,20,108,85,68,64,240,241,45,64,42,193,240,40,9,162,254,245,155,128,157,238,157,189,211,235,12,201,201,57,191,243,200,17,206,240,175,137,57,94,239,86,154,20,177,132,140,134,245,42,13,35,4,195,209,48,65,12,74,65,4,11,138,152,82,178,183,187,167,209,144,97,70,208,104,156,165,172,200,200,80,110,142,13,153,194,4,41,39,140,170,60,43,152,20,112,4,165,76,105,85,56,100,145,18,162,19,14,208,93,125,248,46,225,20,51,12,201,29,13,32,65,74,167,53,26,18,156,30,165,2,17,165,69,35,238,30,148,76,194,60,68,75,138,10,244,166,132,144,193,31,56,129,7,36,231,233,225,167,15,41,26,244,191,99,79,53,237,170,61,159,30,50,192,127,75,199,141,52,247,192,37,85,28,129,53,6,134,216,179,133,245,188,22,130,58,13,213,181,171,1,176,152,174,198,242,57,82,45,174,28,171,177,163,207,150,220,58,152,113,223,195,43,87,174,68,188,49,24,240,53,20,158,102,46,162,14,18,190,232,189,113,80,18,237,73,196,91,233,170,225,105,110,205,118,188,141,221,237,188,91,93,130,237,158,254,46,30,167,231,149,118,207,227,114,179,155,221,78,226,116,59,165,83,219,248,195,229,89,119,58,183,184,31,231,57,163,139,188,170,220,155,150,143,34,190,150,218,206,154,24,64,205,64,239,184,82,171,235,19,126,152,95,113,118,62,244,151,94,224,246,74,109,246,82,223,116,51,91,216,109,11,96,224,134,78,173,32,149,163,147,171,232,73,167,2,96,18,6,170,133,177,143,106,91,216,118,220,142,174,126,211,116,45,10,52,227,219,75,190,171,68,35,212,157,227,218,170,167,198,235,104,39,207,38,20,28,198,154,195,250,36,223,202,167,231,120,97,237,103,131,119,253,153,245,142,17,184,196,157,243,214,157,251,86,95,245,178,106,82,189,155,187,131,118,62,30,55,125,188,27,144,21,212,219,3,251,221,120,218,189,50,179,180,125,3,94,7,231,216,167,37,157,128,141,28,22,57,81,15,253,199,120,53,120,30,4,91,237,201,95,129,14,114,39,104,222,21,213,205,182,182,190,121,177,143,187,173,77,204,100,121,217,111,244,246,222,2,23,99,162,245,22,107,208,89,172,181,190,55,121,189,154,49,104,155,177,123,158,95,193,133,203,213,89,123,120,70,149,248,43,188,182,237,69,237,253,148,251,173,115,230,119,237,124,159,30,129,17,131,243,242,210,174,150,78,251,108,234,214,197,184,102,213,114,146,117,12,135,86,70,156,85,198,194,93,159,131,64,148,176,15,53,111,23,234,203,211,62,181,123,187,237,140,128,151,176,23,94,30,114,63,97,215,93,87,175,246,206,195,41,72,144,255,24,87,176,110,169,70,244,245,209,41,173,100,60,254,237,77,166,236,66,16,141,16,98,205,75,44,7,148,202,105,86,36,144,224,43,186,231,167,255,131,107,101,3,210,160,192,57,147,104,17,40,114,76,229,43,202,89,118,159,224,244,62,230,70,185,177,254,65,81,130,67,84,124,137,28,10,152,71,95,18,65,243,173,211,47,33,6,125,31,133,183,111,254,223,164,92,15,19,105,232,103,225,69,202,82,146,193,80,137,225,9,54,246,31,148,193,130,253,253,207,79,78,132,248,36,102,79,191,17,37,28,42,9,196,233,11,119,71,197,231,200,105,40,154,195,84,16,60,165,195,32,43,169,20,16,72,169,66,160,143,200,200,124,123,227,157,69,188,8,142,113,90,174,131,222,92,163,226,150,160,241,16,69,243,52,168,248,76,91,100,213,205,216,18,98,121,247,86,18,210,204,46,62,170,110,97,74,34,80,126,113,154,194,143,88,45,46,226,3,100,56,75,165,79,241,78,64,127,68,41,201,103,66,1,220,154,247,17,233,119,213,127,23,240,177,137,198,214,119,172,103,247,47,103,53,186,226,210,5,0,0 }; From fd1cc14e87cbac240fa07575cebd1985281b0a81 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Tue, 1 Aug 2023 13:01:49 +0200 Subject: [PATCH 06/10] Bump Version Signed-off-by: Lukas Bachschwell --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 893c5be..dbf1db1 100644 --- a/library.json +++ b/library.json @@ -31,7 +31,7 @@ "frameworks": "arduino" } ], - "version": "2.2.1", + "version": "2.2.2", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index 17aa5df..6fd96d1 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESPUI -version=2.2.1 +version=2.2.2 author=Lukas Bachschwell maintainer=Lukas Bachschwell sentence=ESP32 and ESP8266 Web Interface Library From f8fbcf887af6cf1fede688a1ea15a63307565a48 Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Thu, 3 Aug 2023 16:32:54 +0200 Subject: [PATCH 07/10] Fix compile issues #243 Also fix pio example Signed-off-by: Lukas Bachschwell --- pio_examples/gui/platformio.ini | 4 +- src/ESPUI.cpp | 469 ++++++++++++++++---------------- 2 files changed, 243 insertions(+), 230 deletions(-) diff --git a/pio_examples/gui/platformio.ini b/pio_examples/gui/platformio.ini index 0f5497c..62f30c8 100644 --- a/pio_examples/gui/platformio.ini +++ b/pio_examples/gui/platformio.ini @@ -18,7 +18,7 @@ board_build.filesystem = littlefs lib_extra_dirs = ../../ lib_deps = bblanchon/ArduinoJson @ ^6.18.5 - https://github.com/esphome/ESPAsyncWebServer @ 3.0.0 ; Updated lib, seems to have recent patches. + https://github.com/bmedici/ESPAsyncWebServer ; Use a fork of the library that has a bugfix for the compile.... https://github.com/esphome/ESPAsyncWebServer/pull/17 lib_ignore = ESP Async WebServer ; force the use of the esphome version @@ -40,4 +40,4 @@ monitor_filters = esp32_exception_decoder board_build.flash_mode = dout lib_deps = ${env.lib_deps} - me-no-dev/AsyncTCP@1.1.1 + me-no-dev/AsyncTCP diff --git a/src/ESPUI.cpp b/src/ESPUI.cpp index 90f84e3..3223898 100644 --- a/src/ESPUI.cpp +++ b/src/ESPUI.cpp @@ -17,14 +17,14 @@ #include #endif -static String heapInfo (const __FlashStringHelper* mode) +static String heapInfo(const __FlashStringHelper* mode) { + String result; #if ESP8266 uint32_t hfree; - uint32_t hmax; + uint16_t hmax; uint8_t hfrag; - String result; result.reserve(128); #ifdef UMM_HEAP_IRAM @@ -65,9 +65,6 @@ static String heapInfo (const __FlashStringHelper* mode) return result; } - - - // ################# LITTLEFS functions #if defined(ESP32) void listDir(const char* dirname, uint8_t levels) @@ -80,11 +77,11 @@ void listDir(const char* dirname, uint8_t levels) #endif #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - File root = LittleFS.open(dirname); - #else - File root = LITTLEFS.open(dirname); - #endif +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + File root = LittleFS.open(dirname); +#else + File root = LITTLEFS.open(dirname); +#endif #else File root = LittleFS.open(dirname); #endif @@ -129,11 +126,11 @@ void listDir(const char* dirname, uint8_t levels) if (levels) { - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - listDir(file.path(), levels - 1); - #else - listDir(file.name(), levels - 1); - #endif +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + listDir(file.path(), levels - 1); +#else + listDir(file.name(), levels - 1); +#endif } } else @@ -178,13 +175,13 @@ void listDir(const char* dirname, uint8_t levels) #endif if (levels) { - File file = dir.openFile("r"); - listDir(file.fullName(), levels - 1); - file.close(); - } - } - else - { + File file = dir.openFile("r"); + listDir(file.fullName(), levels - 1); + file.close(); + } + } + else + { #if defined(DEBUG_ESPUI) if (ESPUI.verbosity) { @@ -194,7 +191,7 @@ void listDir(const char* dirname, uint8_t levels) Serial.println(dir.fileSize()); } #endif - } + } } } @@ -203,11 +200,11 @@ void listDir(const char* dirname, uint8_t levels) void ESPUIClass::list() { #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - if (!LittleFS.begin()) - #else +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + if (!LittleFS.begin()) +#else if (!LITTLEFS.begin()) - #endif +#endif { Serial.println(F("LITTLEFS Mount Failed")); return; @@ -223,27 +220,27 @@ void ESPUIClass::list() listDir("/", 1); #if defined(ESP32) - Serial.print(F("Total KB: ")); - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - Serial.println(LittleFS.totalBytes()/1024); - #else - Serial.println(LITTLEFS.totalBytes()/1024); - #endif - Serial.print(F("Used KB: ")); - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - Serial.println(LittleFS.usedBytes()/1024); - #else - Serial.println(LITTLEFS.usedBytes()/1024); - #endif + Serial.print(F("Total KB: ")); +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + Serial.println(LittleFS.totalBytes() / 1024); +#else + Serial.println(LITTLEFS.totalBytes() / 1024); +#endif + Serial.print(F("Used KB: ")); +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + Serial.println(LittleFS.usedBytes() / 1024); +#else + Serial.println(LITTLEFS.usedBytes() / 1024); +#endif #else FSInfo fs_info; LittleFS.info(fs_info); - Serial.print(F("Total KB: ")); - Serial.println(fs_info.totalBytes/1024); - Serial.print(F("Used KB: ")); - Serial.println(fs_info.usedBytes/1024); + Serial.print(F("Total KB: ")); + Serial.println(fs_info.totalBytes / 1024); + Serial.print(F("Used KB: ")); + Serial.println(fs_info.usedBytes / 1024); #endif } @@ -251,11 +248,11 @@ void ESPUIClass::list() void deleteFile(const char* path) { #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - bool exists = LittleFS.exists(path); - #else - bool exists = LITTLEFS.exists(path); - #endif +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + bool exists = LittleFS.exists(path); +#else + bool exists = LITTLEFS.exists(path); +#endif #else bool exists = LittleFS.exists(path); #endif @@ -279,11 +276,11 @@ void deleteFile(const char* path) #endif #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - bool didRemove = LittleFS.remove(path); - #else - bool didRemove = LITTLEFS.remove(path); - #endif +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + bool didRemove = LittleFS.remove(path); +#else + bool didRemove = LITTLEFS.remove(path); +#endif #else bool didRemove = LittleFS.remove(path); #endif @@ -317,11 +314,11 @@ void writeFile(const char* path, const char* data) #endif #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - File file = LittleFS.open(path, FILE_WRITE); - #else - File file = LITTLEFS.open(path, FILE_WRITE); - #endif +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + File file = LittleFS.open(path, FILE_WRITE); +#else + File file = LITTLEFS.open(path, FILE_WRITE); +#endif #else File file = LittleFS.open(path, FILE_WRITE); #endif @@ -398,40 +395,40 @@ void ESPUIClass::prepareFileSystem(bool format) #if defined(ESP32) #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - if(!LittleFS.begin(false)) //Test for an already formatted LittleFS by a mount failure + if (!LittleFS.begin(false)) // Test for an already formatted LittleFS by a mount failure #else - if(!LITTLEFS.begin(false)) //Test for an already formatted LittleFS by a mount failure + if (!LITTLEFS.begin(false)) // Test for an already formatted LittleFS by a mount failure #endif { #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - if(!LittleFS.begin(true)) //Attempt to format LittleFS + if (!LittleFS.begin(true)) // Attempt to format LittleFS #else - if(!LITTLEFS.begin(true)) //Attempt to format LittleFS + if (!LITTLEFS.begin(true)) // Attempt to format LittleFS #endif - { + { #if defined(DEBUG_ESPUI) - if (verbosity) - { - Serial.println(F("LittleFS Format Failed")); - } + if (verbosity) + { + Serial.println(F("LittleFS Format Failed")); + } #endif - return; - } + return; + } } - else if(format) - { + else if (format) + { #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - LittleFS.format(); + LittleFS.format(); #else - LITTLEFS.format(); + LITTLEFS.format(); #endif #if defined(DEBUG_ESPUI) - if (verbosity) - { - Serial.println(F("LittleFS Formatted")); - } + if (verbosity) + { + Serial.println(F("LittleFS Formatted")); + } #endif - } + } #if defined(DEBUG_ESPUI) if (verbosity) @@ -443,38 +440,38 @@ void ESPUIClass::prepareFileSystem(bool format) #else - if (!LittleFS.begin()) //Test for an already formatted LittleFS by a mount failure + if (!LittleFS.begin()) // Test for an already formatted LittleFS by a mount failure { - if(LittleFS.format()) //Attempt to format LittleFS - { + if (LittleFS.format()) // Attempt to format LittleFS + { #if defined(DEBUG_ESPUI) - if (verbosity) - { - Serial.println(F("LittleFS Formatted")); - } + if (verbosity) + { + Serial.println(F("LittleFS Formatted")); + } #endif - } - else - { + } + else + { #if defined(DEBUG_ESPUI) - if (verbosity) - { - Serial.println(F("LittleFS Mount Failed")); - } + if (verbosity) + { + Serial.println(F("LittleFS Mount Failed")); + } #endif - return; - } + return; + } } - else if(format) - { - LittleFS.format(); + else if (format) + { + LittleFS.format(); #if defined(DEBUG_ESPUI) - if (verbosity) - { - Serial.println(F("LittleFS Formatted")); - } + if (verbosity) + { + Serial.println(F("LittleFS Formatted")); + } #endif - } + } #if defined(DEBUG_ESPUI) if (verbosity) @@ -505,33 +502,33 @@ void ESPUIClass::prepareFileSystem(bool format) #endif // Now write - #ifdef ESP32 - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - writeFile("/index.htm", HTML_INDEX); - LittleFS.mkdir("/css"); - writeFile("/css/style.css", CSS_STYLE); - writeFile("/css/normalize.css", CSS_NORMALIZE); - LittleFS.mkdir("/js"); - writeFile("/js/zepto.min.js", JS_ZEPTO); - writeFile("/js/controls.js", JS_CONTROLS); - writeFile("/js/slider.js", JS_SLIDER); - writeFile("/js/graph.js", JS_GRAPH); +#ifdef ESP32 +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + writeFile("/index.htm", HTML_INDEX); + LittleFS.mkdir("/css"); + writeFile("/css/style.css", CSS_STYLE); + writeFile("/css/normalize.css", CSS_NORMALIZE); + LittleFS.mkdir("/js"); + writeFile("/js/zepto.min.js", JS_ZEPTO); + writeFile("/js/controls.js", JS_CONTROLS); + writeFile("/js/slider.js", JS_SLIDER); + writeFile("/js/graph.js", JS_GRAPH); - writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT); - #else - writeFile("/index.htm", HTML_INDEX); - LITTLEFS.mkdir("/css"); - writeFile("/css/style.css", CSS_STYLE); - writeFile("/css/normalize.css", CSS_NORMALIZE); - LITTLEFS.mkdir("/js"); - writeFile("/js/zepto.min.js", JS_ZEPTO); - writeFile("/js/controls.js", JS_CONTROLS); - writeFile("/js/slider.js", JS_SLIDER); - writeFile("/js/graph.js", JS_GRAPH); + writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT); +#else + writeFile("/index.htm", HTML_INDEX); + LITTLEFS.mkdir("/css"); + writeFile("/css/style.css", CSS_STYLE); + writeFile("/css/normalize.css", CSS_NORMALIZE); + LITTLEFS.mkdir("/js"); + writeFile("/js/zepto.min.js", JS_ZEPTO); + writeFile("/js/controls.js", JS_CONTROLS); + writeFile("/js/slider.js", JS_SLIDER); + writeFile("/js/graph.js", JS_GRAPH); - writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT); - #endif - #else + writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT); +#endif +#else writeFile("/index.htm", HTML_INDEX); writeFile("/css/style.css", CSS_STYLE); @@ -543,7 +540,7 @@ void ESPUIClass::prepareFileSystem(bool format) writeFile("/js/graph.js", JS_GRAPH); writeFile("/js/tabbedcontent.js", JS_TABBEDCONTENT); - #endif +#endif #if defined(DEBUG_ESPUI) if (verbosity) @@ -564,33 +561,33 @@ void ESPUIClass::prepareFileSystem(bool format) #endif #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - LittleFS.end(); - #else +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + LittleFS.end(); +#else LITTLEFS.end(); - #endif +#endif #else LittleFS.end(); #endif - } // Handle Websockets Communication -void ESPUIClass::onWsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) +void ESPUIClass::onWsEvent( + AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) { // Serial.println(String("ESPUIClass::OnWsEvent: type: ") + String(type)); RemoveToBeDeletedControls(); - if(WS_EVT_DISCONNECT == type) + if (WS_EVT_DISCONNECT == type) { - #if defined(DEBUG_ESPUI) - if (verbosity) - { - Serial.println(F("WS_EVT_DISCONNECT")); - } - #endif +#if defined(DEBUG_ESPUI) + if (verbosity) + { + Serial.println(F("WS_EVT_DISCONNECT")); + } +#endif - if(MapOfClients.end() != MapOfClients.find(client->id())) + if (MapOfClients.end() != MapOfClients.find(client->id())) { // Serial.println("Delete client."); delete MapOfClients[client->id()]; @@ -599,7 +596,7 @@ void ESPUIClass::onWsEvent(AsyncWebSocket* server, AsyncWebSocketClient* client, } else { - if(MapOfClients.end() == MapOfClients.find(client->id())) + if (MapOfClients.end() == MapOfClients.find(client->id())) { // Serial.println("ESPUIClass::OnWsEvent:Create new client."); MapOfClients[client->id()] = new ESPUIclient(client); @@ -627,12 +624,14 @@ uint16_t ESPUIClass::addControl(ControlType type, const char* label, const Strin return addControl(type, label, value, color, Control::noParent); } -uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl) +uint16_t ESPUIClass::addControl( + ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl) { return addControl(type, label, value, color, parentControl, nullptr); } -uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, void (*callback)(Control*, int)) +uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, + uint16_t parentControl, void (*callback)(Control*, int)) { uint16_t id = addControl(type, label, value, color, parentControl, nullptr, nullptr); // set the original style callback @@ -640,7 +639,8 @@ uint16_t ESPUIClass::addControl(ControlType type, const char* label, const Strin return id; } -uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, uint16_t parentControl, void (*callback)(Control*, int, void *), void * UserData) +uint16_t ESPUIClass::addControl(ControlType type, const char* label, const String& value, ControlColor color, + uint16_t parentControl, void (*callback)(Control*, int, void*), void* UserData) { #ifdef ESP32 xSemaphoreTake(ControlsSemaphore, portMAX_DELAY); @@ -686,7 +686,7 @@ bool ESPUIClass::removeControl(uint16_t id, bool force_rebuild_ui) control->DeleteControl(); controlCount--; - if(force_rebuild_ui) + if (force_rebuild_ui) { jsonReload(); } @@ -707,9 +707,9 @@ bool ESPUIClass::removeControl(uint16_t id, bool force_rebuild_ui) void ESPUIClass::RemoveToBeDeletedControls() { - #ifdef ESP32 +#ifdef ESP32 xSemaphoreTake(ControlsSemaphore, portMAX_DELAY); - #endif // def ESP32 +#endif // def ESP32 Control* PreviousControl = nullptr; Control* CurrentControl = controls; @@ -737,9 +737,9 @@ void ESPUIClass::RemoveToBeDeletedControls() CurrentControl = NextControl; } } - #ifdef ESP32 +#ifdef ESP32 xSemaphoreGive(ControlsSemaphore); - #endif // def ESP32 +#endif // def ESP32 } uint16_t ESPUIClass::label(const char* label, ControlColor color, const String& value) @@ -752,16 +752,19 @@ uint16_t ESPUIClass::graph(const char* label, ControlColor color) return addControl(ControlType::Graph, label, "", color); } -uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max) +uint16_t ESPUIClass::slider( + const char* label, void (*callback)(Control*, int), ControlColor color, int value, int min, int max) { uint16_t id = slider(label, nullptr, color, value, min, max, nullptr); getControl(id)->callback = callback; return id; } -uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value, int min, int max, void* userData) +uint16_t ESPUIClass::slider(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int value, + int min, int max, void* userData) { - uint16_t sliderId = addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback, userData); + uint16_t sliderId + = addControl(ControlType::Slider, label, String(value), color, Control::noParent, callback, userData); addControl(ControlType::Min, label, String(min), ControlColor::None, sliderId); addControl(ControlType::Max, label, String(max), ControlColor::None, sliderId); @@ -773,7 +776,8 @@ uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int), return addControl(ControlType::Button, label, value, color, Control::noParent, callback); } -uint16_t ESPUIClass::button(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData) +uint16_t ESPUIClass::button( + const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData) { return addControl(ControlType::Button, label, value, color, Control::noParent, callback, UserData); } @@ -783,9 +787,11 @@ uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int) return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback); } -uint16_t ESPUIClass::switcher(const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData) +uint16_t ESPUIClass::switcher( + const char* label, void (*callback)(Control*, int, void*), ControlColor color, bool startState, void* UserData) { - return addControl(ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback, UserData); + return addControl( + ControlType::Switcher, label, startState ? "1" : "0", color, Control::noParent, callback, UserData); } uint16_t ESPUIClass::pad(const char* label, void (*callback)(Control*, int), ControlColor color) @@ -803,12 +809,14 @@ uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback); } -uint16_t ESPUIClass::padWithCenter(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData) +uint16_t ESPUIClass::padWithCenter( + const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData) { return addControl(ControlType::PadWithCenter, label, "", color, Control::noParent, callback, UserData); } -uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max) +uint16_t ESPUIClass::number( + const char* label, void (*callback)(Control*, int), ControlColor color, int number, int min, int max) { uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback); addControl(ControlType::Min, label, String(min), ControlColor::None, numberId); @@ -816,9 +824,11 @@ uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int), return numberId; } -uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int number, int min, int max, void* UserData) +uint16_t ESPUIClass::number(const char* label, void (*callback)(Control*, int, void*), ControlColor color, int number, + int min, int max, void* UserData) { - uint16_t numberId = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback, UserData); + uint16_t numberId + = addControl(ControlType::Number, label, String(number), color, Control::noParent, callback, UserData); addControl(ControlType::Min, label, String(min), ControlColor::None, numberId); addControl(ControlType::Max, label, String(max), ControlColor::None, numberId); return numberId; @@ -832,7 +842,8 @@ uint16_t ESPUIClass::gauge(const char* label, ControlColor color, int number, in return numberId; } -uint16_t ESPUIClass::separator(const char* label) { +uint16_t ESPUIClass::separator(const char* label) +{ return addControl(ControlType::Separator, label, "", ControlColor::Alizarin, Control::noParent, nullptr); } @@ -841,7 +852,8 @@ uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*, return addControl(ControlType::Accel, label, "", color, Control::noParent, callback); } -uint16_t ESPUIClass::accelerometer(const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData) +uint16_t ESPUIClass::accelerometer( + const char* label, void (*callback)(Control*, int, void*), ControlColor color, void* UserData) { return addControl(ControlType::Accel, label, "", color, Control::noParent, callback, UserData); } @@ -851,7 +863,8 @@ uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int), Co return addControl(ControlType::Text, label, value, color, Control::noParent, callback); } -uint16_t ESPUIClass::text(const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData) +uint16_t ESPUIClass::text( + const char* label, void (*callback)(Control*, int, void*), ControlColor color, const String& value, void* UserData) { return addControl(ControlType::Text, label, value, color, Control::noParent, callback, UserData); } @@ -880,7 +893,7 @@ Control* ESPUIClass::getControlNoLock(uint16_t id) { if (control->id == id) { - if(!control->ToBeDeleted()) + if (!control->ToBeDeleted()) { Response = control; } @@ -942,7 +955,8 @@ void ESPUIClass::setPanelWide(uint16_t id, bool wide) } } -void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId) { +void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId) +{ Control* control = getControl(id); if (control) { @@ -952,7 +966,8 @@ void ESPUIClass::setEnabled(uint16_t id, bool enabled, int clientId) { } } -void ESPUIClass::setVertical(uint16_t id, bool vert) { +void ESPUIClass::setVertical(uint16_t id, bool vert) +{ Control* control = getControl(id); if (control) { @@ -1007,12 +1022,12 @@ void ESPUIClass::updateControlValue(uint16_t id, const String& value, int client updateControlValue(control, value, clientId); } -void ESPUIClass::updateControlLabel(uint16_t id, const char * value, int clientId) +void ESPUIClass::updateControlLabel(uint16_t id, const char* value, int clientId) { updateControlLabel(getControl(id), value, clientId); } -void ESPUIClass::updateControlLabel(Control* control, const char * value, int clientId) +void ESPUIClass::updateControlLabel(Control* control, const char* value, int clientId) { if (!control) { @@ -1028,9 +1043,10 @@ void ESPUIClass::updateControlLabel(Control* control, const char * value, int cl updateControl(control, clientId); } -void ESPUIClass::updateVisibility(uint16_t id, bool visibility, int clientId) { +void ESPUIClass::updateVisibility(uint16_t id, bool visibility, int clientId) +{ Control* control = getControl(id); - if(control) + if (control) { control->visible = visibility; updateControl(control, clientId); @@ -1047,7 +1063,8 @@ void ESPUIClass::updateLabel(uint16_t id, const String& value) updateControlValue(id, value); } -void ESPUIClass::updateButton(uint16_t id, const String& value) { +void ESPUIClass::updateButton(uint16_t id, const String& value) +{ updateControlValue(id, value); } @@ -1086,7 +1103,8 @@ void ESPUIClass::updateTime(uint16_t id, int clientId) updateControl(id, clientId); } -void ESPUIClass::clearGraph(uint16_t id, int clientId) { +void ESPUIClass::clearGraph(uint16_t id, int clientId) +{ do // once { Control* control = getControl(id); @@ -1104,8 +1122,8 @@ void ESPUIClass::clearGraph(uint16_t id, int clientId) { SendJsonDocToWebSocket(document, clientId); - } while(false); - } + } while (false); +} void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId) { @@ -1126,23 +1144,23 @@ void ESPUIClass::addGraphPoint(uint16_t id, int nValue, int clientId) SendJsonDocToWebSocket(document, clientId); - } while(false); + } while (false); } bool ESPUIClass::SendJsonDocToWebSocket(ArduinoJson::DynamicJsonDocument& document, uint16_t clientId) { bool Response = false; - if(0 > clientId) + if (0 > clientId) { - if(MapOfClients.end() != MapOfClients.find(clientId)) + if (MapOfClients.end() != MapOfClients.find(clientId)) { Response = MapOfClients[clientId]->SendJsonDocToWebSocket(document); } } else { - for(auto CurrentClient : MapOfClients) + for (auto CurrentClient : MapOfClients) { Response |= CurrentClient.second->SendJsonDocToWebSocket(document); } @@ -1169,19 +1187,19 @@ void ESPUIClass::ClearControlUpdateFlags() { bool CanClearUpdateFlags = true; - for(auto& CurrentClient : MapOfClients) + for (auto& CurrentClient : MapOfClients) { - if(!CurrentClient.second->IsSyncronized()) + if (!CurrentClient.second->IsSyncronized()) { CanClearUpdateFlags = false; break; } } - if(CanClearUpdateFlags) + if (CanClearUpdateFlags) { Control* control = controls; - while(nullptr != control) + while (nullptr != control) { control->HasBeenSynchronized(); control = control->next; @@ -1191,7 +1209,7 @@ void ESPUIClass::ClearControlUpdateFlags() void ESPUIClass::jsonReload() { - for(auto& CurrentClient : MapOfClients) + for (auto& CurrentClient : MapOfClients) { // Serial.println("Requesting Reload"); CurrentClient.second->NotifyClient(ClientUpdateType_t::ReloadNeeded); @@ -1223,11 +1241,11 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c ws = new AsyncWebSocket("/ws"); #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - bool fsBegin = LittleFS.begin(); - #else +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + bool fsBegin = LittleFS.begin(); +#else bool fsBegin = LITTLEFS.begin(); - #endif +#endif #else bool fsBegin = LittleFS.begin(); #endif @@ -1252,11 +1270,11 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c #endif #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - bool indexExists = LittleFS.exists("/index.htm"); - #else +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + bool indexExists = LittleFS.exists("/index.htm"); +#else bool indexExists = LITTLEFS.exists("/index.htm"); - #endif +#endif #else bool indexExists = LittleFS.exists("/index.htm"); #endif @@ -1273,10 +1291,8 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c return; } - ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) - { - ESPUI.onWsEvent(server, client, type, arg, data, len); - }); + ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, + size_t len) { ESPUI.onWsEvent(server, client, type, arg, data, len); }); server->addHandler(ws); if (basicAuth) @@ -1286,11 +1302,11 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c ws->setAuthentication(basicAuthUsername, basicAuthPassword); } #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); - #else +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); +#else server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); - #endif +#endif #else server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm").setAuthentication(username, password); #endif @@ -1298,11 +1314,11 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c else { #if defined(ESP32) - #if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 - server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); - #else +#if (ESP_IDF_VERSION_MAJOR == 4 && ESP_IDF_VERSION_MINOR >= 4) || ESP_IDF_VERSION_MAJOR > 4 + server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); +#else server->serveStatic("/", LITTLEFS, "/").setDefaultFile("index.htm"); - #endif +#endif #else server->serveStatic("/", LittleFS, "/").setDefaultFile("index.htm"); #endif @@ -1316,19 +1332,18 @@ void ESPUIClass::beginLITTLEFS(const char* _title, const char* username, const c } request->send(200, "text/plain", heapInfo(F("In LITTLEFS mode"))); - }); server->onNotFound([this](AsyncWebServerRequest* request) { - if(captivePortal) - { - request->redirect("/"); - } - else - { - request->send(404); - } - }); + if (captivePortal) + { + request->redirect("/"); + } + else + { + request->send(404); + } + }); server->begin(); @@ -1359,10 +1374,8 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas server = new AsyncWebServer(port); ws = new AsyncWebSocket("/ws"); - ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) - { - ESPUI.onWsEvent(server, client, type, arg, data, len); - }); + ws->onEvent([](AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, + size_t len) { ESPUI.onWsEvent(server, client, type, arg, data, len); }); server->addHandler(ws); @@ -1478,15 +1491,15 @@ void ESPUIClass::begin(const char* _title, const char* username, const char* pas }); server->onNotFound([this](AsyncWebServerRequest* request) { - if(captivePortal) - { - request->redirect("/"); - } - else - { - request->send(404); - } - }); + if (captivePortal) + { + request->redirect("/"); + } + else + { + request->send(404); + } + }); server->begin(); From 679a3b5a8d0f446615a5d05fe6c93c6fce305f9b Mon Sep 17 00:00:00 2001 From: Lukas Bachschwell Date: Thu, 3 Aug 2023 16:33:27 +0200 Subject: [PATCH 08/10] Version 2.2.3 Signed-off-by: Lukas Bachschwell --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index dbf1db1..76d3173 100644 --- a/library.json +++ b/library.json @@ -31,7 +31,7 @@ "frameworks": "arduino" } ], - "version": "2.2.2", + "version": "2.2.3", "frameworks": "arduino", "platforms": "*" } diff --git a/library.properties b/library.properties index 6fd96d1..05c272b 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=ESPUI -version=2.2.2 +version=2.2.3 author=Lukas Bachschwell maintainer=Lukas Bachschwell sentence=ESP32 and ESP8266 Web Interface Library From 68c251226d2173f0bf0d0ac6b6cf6abd5ef254f1 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 6 Sep 2023 22:35:41 +0200 Subject: [PATCH 09/10] minor fixes for restoring warning-less emulation on host for debugging (using emuAsync, see main readme) --- examples/completeExample/completeExample.cpp | 5 +++-- examples/completeExample/completeExample.ino | 3 +++ examples/gui-generic-api/gui-generic-api.ino | 2 +- examples/gui/gui.ino | 2 +- examples/tabbedGui/tabbedGui.ino | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/completeExample/completeExample.cpp b/examples/completeExample/completeExample.cpp index 364a4f9..f81231c 100644 --- a/examples/completeExample/completeExample.cpp +++ b/examples/completeExample/completeExample.cpp @@ -35,7 +35,7 @@ #warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) #warning then check http:///heap #endif // MMU_IRAM_HEAP -#ifndef DEBUG_ESP_OOM +#if !defined(DEBUG_ESP_OOM) && !defined(CORE_MOCK) #error on ESP8266 and ESPUI, you must define OOM debug option when developping #endif #endif @@ -396,7 +396,7 @@ void extendedCallback(Control* sender, int type, void* param) Serial.print(sender->label); Serial.print("' = "); Serial.println(sender->value); - Serial.println(String("param = ") + String((int)param)); + Serial.println(String("param = ") + String((long)param)); } void setup() { @@ -443,6 +443,7 @@ void loop() { #if !defined(ESP32) ((void (*)())0xf00fdead)(); #endif + break; default: Serial.print('#'); break; diff --git a/examples/completeExample/completeExample.ino b/examples/completeExample/completeExample.ino index ff7bd09..a4db808 100644 --- a/examples/completeExample/completeExample.ino +++ b/examples/completeExample/completeExample.ino @@ -1 +1,4 @@ // placeholder +#if CORE_MOCK +#include "completeExample.cpp" +#endif diff --git a/examples/gui-generic-api/gui-generic-api.ino b/examples/gui-generic-api/gui-generic-api.ino index 815e66d..003ce48 100644 --- a/examples/gui-generic-api/gui-generic-api.ino +++ b/examples/gui-generic-api/gui-generic-api.ino @@ -16,7 +16,7 @@ DNSServer dnsServer; #warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) #warning then check http:///heap #endif // MMU_IRAM_HEAP -#ifndef DEBUG_ESP_OOM +#if !defined(DEBUG_ESP_OOM) && !defined(CORE_MOCK) #error on ESP8266 and ESPUI, you must define OOM debug option when developping #endif #endif diff --git a/examples/gui/gui.ino b/examples/gui/gui.ino index 1aca2f1..bcccd82 100644 --- a/examples/gui/gui.ino +++ b/examples/gui/gui.ino @@ -16,7 +16,7 @@ DNSServer dnsServer; #warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) #warning then check http:///heap #endif // MMU_IRAM_HEAP -#ifndef DEBUG_ESP_OOM +#if !defined(DEBUG_ESP_OOM) && !defined(CORE_MOCK) #error on ESP8266 and ESPUI, you must define OOM debug option when developping #endif #endif diff --git a/examples/tabbedGui/tabbedGui.ino b/examples/tabbedGui/tabbedGui.ino index 7aa0b2f..d19cebe 100644 --- a/examples/tabbedGui/tabbedGui.ino +++ b/examples/tabbedGui/tabbedGui.ino @@ -16,7 +16,7 @@ DNSServer dnsServer; #warning use decorators: { HeapSelectIram doAllocationsInIRAM; ESPUI.addControl(...) ... } (cf. https://arduino-esp8266.readthedocs.io/en/latest/mmu.html#how-to-select-heap) #warning then check http:///heap #endif // MMU_IRAM_HEAP -#ifndef DEBUG_ESP_OOM +#if !defined(DEBUG_ESP_OOM) && !defined(CORE_MOCK) #error on ESP8266 and ESPUI, you must define OOM debug option when developping #endif #endif From 03c30fa75c02d11b5c76ae682d92b081920e3b1b Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 6 Sep 2023 22:50:42 +0200 Subject: [PATCH 10/10] more minor changes for #249 --- examples/completeExample/completeExample.cpp | 3 ++- examples/gui-generic-api/gui-generic-api.ino | 3 ++- examples/gui/gui.ino | 3 ++- examples/tabbedGui/tabbedGui.ino | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/examples/completeExample/completeExample.cpp b/examples/completeExample/completeExample.cpp index f81231c..7617e94 100644 --- a/examples/completeExample/completeExample.cpp +++ b/examples/completeExample/completeExample.cpp @@ -396,7 +396,8 @@ void extendedCallback(Control* sender, int type, void* param) Serial.print(sender->label); Serial.print("' = "); Serial.println(sender->value); - Serial.println(String("param = ") + String((long)param)); + Serial.print("param = "); + Serial.println((long)param); } void setup() { diff --git a/examples/gui-generic-api/gui-generic-api.ino b/examples/gui-generic-api/gui-generic-api.ino index 003ce48..54f003b 100644 --- a/examples/gui-generic-api/gui-generic-api.ino +++ b/examples/gui-generic-api/gui-generic-api.ino @@ -67,7 +67,8 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(long(param))); + Serial.print("param: "); + Serial.println(long(param)); switch (type) { case B_DOWN: diff --git a/examples/gui/gui.ino b/examples/gui/gui.ino index bcccd82..759ed07 100644 --- a/examples/gui/gui.ino +++ b/examples/gui/gui.ino @@ -72,7 +72,8 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(long(param))); + Serial.print("param: "); + Serial.println(long(param)); switch (type) { case B_DOWN: diff --git a/examples/tabbedGui/tabbedGui.ino b/examples/tabbedGui/tabbedGui.ino index d19cebe..a862aa9 100644 --- a/examples/tabbedGui/tabbedGui.ino +++ b/examples/tabbedGui/tabbedGui.ino @@ -66,7 +66,8 @@ void buttonCallback(Control* sender, int type) void buttonExample(Control* sender, int type, void* param) { - Serial.println(String("param: ") + String(long(param))); + Serial.print("param: "); + Serial.println(long(param)); switch (type) { case B_DOWN: