From b45f4f73566ac8b87faba9f0c39fd07b217a727a Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 19 Jul 2023 12:07:25 +0200 Subject: [PATCH] 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;