From 0e164ae46c637fc69822397d8eae57e24b217cbd Mon Sep 17 00:00:00 2001 From: Scott Powell Date: Wed, 18 Nov 2026 18:18:06 +1100 Subject: [PATCH] * refactored UITask from repeater/room/sensor to /helpers/ui/server * added BaseUITask for common behaviours * ui_task now instantiated in one of the variant's target-*.cpp modules --- examples/simple_repeater/MyMesh.h | 4 +- examples/simple_repeater/UITask.h | 22 --- examples/simple_repeater/main.cpp | 7 +- examples/simple_room_server/MyMesh.h | 4 +- examples/simple_room_server/UITask.cpp | 125 ------------------ examples/simple_room_server/UITask.h | 19 --- examples/simple_room_server/main.cpp | 7 +- examples/simple_sensor/SensorMesh.h | 4 +- examples/simple_sensor/UITask.cpp | 125 ------------------ examples/simple_sensor/UITask.h | 19 --- examples/simple_sensor/main.cpp | 7 +- src/helpers/ui/BaseUITask.cpp | 17 +++ src/helpers/ui/BaseUITask.h | 19 +++ .../helpers/ui/server}/UITask.cpp | 25 ++-- src/helpers/ui/server/UITask.h | 23 ++++ variants/heltec_v3/platformio.ini | 28 +++- variants/heltec_v3/target-companion.cpp | 9 ++ variants/heltec_v3/target-other.cpp | 9 ++ variants/heltec_v3/target.cpp | 5 - variants/heltec_v3/target.h | 2 + 20 files changed, 117 insertions(+), 363 deletions(-) delete mode 100644 examples/simple_repeater/UITask.h delete mode 100644 examples/simple_room_server/UITask.cpp delete mode 100644 examples/simple_room_server/UITask.h delete mode 100644 examples/simple_sensor/UITask.cpp delete mode 100644 examples/simple_sensor/UITask.h create mode 100644 src/helpers/ui/BaseUITask.cpp create mode 100644 src/helpers/ui/BaseUITask.h rename {examples/simple_repeater => src/helpers/ui/server}/UITask.cpp (91%) create mode 100644 src/helpers/ui/server/UITask.h create mode 100644 variants/heltec_v3/target-companion.cpp create mode 100644 variants/heltec_v3/target-other.cpp diff --git a/examples/simple_repeater/MyMesh.h b/examples/simple_repeater/MyMesh.h index 7e4cfd4f2..dcaa71db5 100644 --- a/examples/simple_repeater/MyMesh.h +++ b/examples/simple_repeater/MyMesh.h @@ -74,8 +74,6 @@ struct NeighbourInfo { #define FIRMWARE_VERSION "v1.18.0" #endif -#define FIRMWARE_ROLE "repeater" - #define PACKET_LOG_FILE "/packet_log" class MyMesh : public mesh::Mesh, public CommonCLICallbacks { @@ -189,7 +187,7 @@ public: void sendNodeDiscoverReq(); const char* getFirmwareVer() override { return FIRMWARE_VERSION; } const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; } - const char* getRole() override { return FIRMWARE_ROLE; } + const char* getRole() override { return "repeater"; } const char* getNodeName() { return _prefs.node_name; } NodePrefs* getNodePrefs() { return &_prefs; diff --git a/examples/simple_repeater/UITask.h b/examples/simple_repeater/UITask.h deleted file mode 100644 index d8e3ce1d2..000000000 --- a/examples/simple_repeater/UITask.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include - -class UITask { - mesh::MainBoard* _board; - DisplayDriver* _display; - unsigned long _next_read, _next_refresh, _auto_off; - int _prevBtnState; - NodePrefs* _node_prefs; - char _version_info[32]; - unsigned long _powering_off_at = 0; - unsigned long _started_at = 0; - - void renderCurrScreen(); -public: - UITask(mesh::MainBoard& board, DisplayDriver& display) : _board(&board), _display(&display) { _next_read = _next_refresh = 0; } - void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version); - - void loop(); -}; \ No newline at end of file diff --git a/examples/simple_repeater/main.cpp b/examples/simple_repeater/main.cpp index d475b13d8..cb1a7d693 100644 --- a/examples/simple_repeater/main.cpp +++ b/examples/simple_repeater/main.cpp @@ -3,11 +3,6 @@ #include "MyMesh.h" -#ifdef DISPLAY_CLASS - #include "UITask.h" - static UITask ui_task(board, display); -#endif - #ifdef ETHERNET_ENABLED #define ETHERNET_CLI_BANNER "MeshCore Repeater CLI" #include @@ -107,7 +102,7 @@ void setup() { the_mesh.begin(fs); #ifdef DISPLAY_CLASS - ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); + ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION, "< Repeater >"); #endif #ifdef ETHERNET_ENABLED diff --git a/examples/simple_room_server/MyMesh.h b/examples/simple_room_server/MyMesh.h index 507b42b1a..1a81340af 100644 --- a/examples/simple_room_server/MyMesh.h +++ b/examples/simple_room_server/MyMesh.h @@ -77,8 +77,6 @@ #define TXT_ACK_DELAY 200 #endif -#define FIRMWARE_ROLE "room_server" - #define PACKET_LOG_FILE "/packet_log" #define MAX_POST_TEXT_LEN (160-9) @@ -189,7 +187,7 @@ public: const char* getFirmwareVer() override { return FIRMWARE_VERSION; } const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; } - const char* getRole() override { return FIRMWARE_ROLE; } + const char* getRole() override { return "room_server"; } const char* getNodeName() { return _prefs.node_name; } NodePrefs* getNodePrefs() { return &_prefs; diff --git a/examples/simple_room_server/UITask.cpp b/examples/simple_room_server/UITask.cpp deleted file mode 100644 index 8e4c2fcf6..000000000 --- a/examples/simple_room_server/UITask.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "UITask.h" -#include -#include - -#ifndef USER_BTN_PRESSED -#define USER_BTN_PRESSED LOW -#endif - -#define AUTO_OFF_MILLIS 20000 // 20 seconds -#define BOOT_SCREEN_MILLIS 4000 // 4 seconds - -// 'meshcore', 128x13px -static const uint8_t meshcore_logo [] PROGMEM = { - 0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, - 0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe, - 0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc, - 0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00, - 0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00, - 0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, - 0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, - 0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0, - 0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00, - 0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00, - 0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8, - 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8, - 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, -}; - -void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) { - _prevBtnState = HIGH; - _auto_off = millis() + AUTO_OFF_MILLIS; - _node_prefs = node_prefs; - _display->turnOn(); - - // strip off dash and commit hash by changing dash to null terminator - // e.g: v1.2.3-abcdef -> v1.2.3 - char *version = strdup(firmware_version); - char *dash = strchr(version, '-'); - if(dash){ - *dash = 0; - } - - // v1.2.3 (1 Jan 2025) - snprintf(_version_info, sizeof(_version_info), "%s (%s)", version, build_date); - free(version); -} - -void UITask::renderCurrScreen() { - char tmp[80]; - if (millis() < BOOT_SCREEN_MILLIS) { // boot screen - // meshcore logo - _display->setColor(UIColor::corp_blue); - int logoWidth = 128; - _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); - - // meshcore website - const char* website = "https://meshcore.io"; - _display->setColor(UIColor::primary_txt); - _display->setTextSize(1); - uint16_t websiteWidth = _display->getTextWidth(website); - _display->setCursor((_display->width() - websiteWidth) / 2, 22); - _display->print(website); - - // version info - _display->setTextSize(1); - uint16_t versionWidth = _display->getTextWidth(_version_info); - _display->setCursor((_display->width() - versionWidth) / 2, 35); - _display->print(_version_info); - - // node type - const char* node_type = "< Room Server >"; - uint16_t typeWidth = _display->getTextWidth(node_type); - _display->setCursor((_display->width() - typeWidth) / 2, 48); - _display->print(node_type); - } else { // home screen - // node name - _display->setCursor(0, 0); - _display->setTextSize(1); - _display->setColor(UIColor::primary_txt); - _display->print(_node_prefs->node_name); - - // freq / sf - _display->setCursor(0, 20); - sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf); - _display->print(tmp); - - // bw / cr - _display->setCursor(0, 30); - sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr); - _display->print(tmp); - } -} - -void UITask::loop() { -#ifdef PIN_USER_BTN - if (millis() >= _next_read) { - int btnState = digitalRead(PIN_USER_BTN); - if (btnState != _prevBtnState) { - if (btnState == USER_BTN_PRESSED) { // pressed? - if (_display->isOn()) { - // TODO: any action ? - } else { - _display->turnOn(); - } - _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer - } - _prevBtnState = btnState; - } - _next_read = millis() + 200; // 5 reads per second - } -#endif - - if (_display->isOn()) { - if (millis() >= _next_refresh) { - _display->startFrame(); - renderCurrScreen(); - _display->endFrame(); - - _next_refresh = millis() + 1000; // refresh every second - } - if (millis() > _auto_off) { - _display->turnOff(); - } - } -} diff --git a/examples/simple_room_server/UITask.h b/examples/simple_room_server/UITask.h deleted file mode 100644 index a27259f11..000000000 --- a/examples/simple_room_server/UITask.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include - -class UITask { - DisplayDriver* _display; - unsigned long _next_read, _next_refresh, _auto_off; - int _prevBtnState; - NodePrefs* _node_prefs; - char _version_info[32]; - - void renderCurrScreen(); -public: - UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; } - void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version); - - void loop(); -}; \ No newline at end of file diff --git a/examples/simple_room_server/main.cpp b/examples/simple_room_server/main.cpp index 4bfad4e54..dad05bba2 100644 --- a/examples/simple_room_server/main.cpp +++ b/examples/simple_room_server/main.cpp @@ -8,11 +8,6 @@ #include #endif -#ifdef DISPLAY_CLASS - #include "UITask.h" - static UITask ui_task(display); -#endif - StdRNG fast_rng; SimpleMeshTables tables; MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables); @@ -88,7 +83,7 @@ void setup() { the_mesh.begin(fs); #ifdef DISPLAY_CLASS - ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); + ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION, "< Room Server >"); #endif #ifdef ETHERNET_ENABLED diff --git a/examples/simple_sensor/SensorMesh.h b/examples/simple_sensor/SensorMesh.h index e6746d470..2dc610cc0 100644 --- a/examples/simple_sensor/SensorMesh.h +++ b/examples/simple_sensor/SensorMesh.h @@ -41,8 +41,6 @@ #define FIRMWARE_VERSION "v1.18.0" #endif -#define FIRMWARE_ROLE "sensor" - #define MAX_SEARCH_RESULTS 24 #define MAX_CONCURRENT_ALERTS 4 @@ -56,7 +54,7 @@ public: // CommonCLI callbacks const char* getFirmwareVer() override { return FIRMWARE_VERSION; } const char* getBuildDate() override { return FIRMWARE_BUILD_DATE; } - const char* getRole() override { return FIRMWARE_ROLE; } + const char* getRole() override { return "sensor"; } const char* getNodeName() { return _prefs.node_name; } NodePrefs* getNodePrefs() { return &_prefs; } void savePrefs() override { _cli.savePrefs(_fs); } diff --git a/examples/simple_sensor/UITask.cpp b/examples/simple_sensor/UITask.cpp deleted file mode 100644 index 75a0b4650..000000000 --- a/examples/simple_sensor/UITask.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "UITask.h" -#include -#include - -#ifndef USER_BTN_PRESSED -#define USER_BTN_PRESSED LOW -#endif - -#define AUTO_OFF_MILLIS 20000 // 20 seconds -#define BOOT_SCREEN_MILLIS 4000 // 4 seconds - -// 'meshcore', 128x13px -static const uint8_t meshcore_logo [] PROGMEM = { - 0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, - 0x3c, 0x03, 0xe3, 0xff, 0xc7, 0xff, 0x8e, 0x03, 0x8f, 0xfe, 0x3f, 0xfe, 0x1f, 0xff, 0x1f, 0xfe, - 0x3e, 0x03, 0xc3, 0xff, 0x8f, 0xff, 0x0e, 0x07, 0x8f, 0xfe, 0x7f, 0xfe, 0x1f, 0xff, 0x1f, 0xfc, - 0x3e, 0x07, 0xc7, 0x80, 0x0e, 0x00, 0x0e, 0x07, 0x9e, 0x00, 0x78, 0x0e, 0x3c, 0x0f, 0x1c, 0x00, - 0x3e, 0x0f, 0xc7, 0x80, 0x1e, 0x00, 0x0e, 0x07, 0x1e, 0x00, 0x70, 0x0e, 0x38, 0x0f, 0x3c, 0x00, - 0x7f, 0x0f, 0xc7, 0xfe, 0x1f, 0xfc, 0x1f, 0xff, 0x1c, 0x00, 0x70, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, - 0x7f, 0x1f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x0e, 0x38, 0x0e, 0x3f, 0xf8, - 0x7f, 0x3f, 0xc7, 0xfe, 0x0f, 0xff, 0x1f, 0xff, 0x1c, 0x00, 0xf0, 0x1e, 0x3f, 0xfe, 0x3f, 0xf0, - 0x77, 0x3b, 0x87, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xfc, 0x38, 0x00, - 0x77, 0xfb, 0x8f, 0x00, 0x00, 0x07, 0x1c, 0x0f, 0x3c, 0x00, 0xe0, 0x1c, 0x7f, 0xf8, 0x38, 0x00, - 0x73, 0xf3, 0x8f, 0xff, 0x0f, 0xff, 0x1c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x78, 0x7f, 0xf8, - 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfe, 0x3c, 0x0e, 0x3f, 0xf8, 0xff, 0xfc, 0x70, 0x3c, 0x7f, 0xf8, - 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, -}; - -void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) { - _prevBtnState = HIGH; - _auto_off = millis() + AUTO_OFF_MILLIS; - _node_prefs = node_prefs; - _display->turnOn(); - - // strip off dash and commit hash by changing dash to null terminator - // e.g: v1.2.3-abcdef -> v1.2.3 - char *version = strdup(firmware_version); - char *dash = strchr(version, '-'); - if(dash){ - *dash = 0; - } - - // v1.2.3 (1 Jan 2025) - snprintf(_version_info, sizeof(_version_info), "%s (%s)", version, build_date); - free(version); -} - -void UITask::renderCurrScreen() { - char tmp[80]; - if (millis() < BOOT_SCREEN_MILLIS) { // boot screen - // meshcore logo - _display->setColor(UIColor::corp_blue); - int logoWidth = 128; - _display->drawXbm((_display->width() - logoWidth) / 2, 3, meshcore_logo, logoWidth, 13); - - // meshcore website - const char* website = "https://meshcore.io"; - _display->setColor(UIColor::primary_txt); - _display->setTextSize(1); - uint16_t websiteWidth = _display->getTextWidth(website); - _display->setCursor((_display->width() - websiteWidth) / 2, 22); - _display->print(website); - - // version info - _display->setTextSize(1); - uint16_t versionWidth = _display->getTextWidth(_version_info); - _display->setCursor((_display->width() - versionWidth) / 2, 35); - _display->print(_version_info); - - // node type - const char* node_type = "< Sensor >"; - uint16_t typeWidth = _display->getTextWidth(node_type); - _display->setCursor((_display->width() - typeWidth) / 2, 48); - _display->print(node_type); - } else { // home screen - // node name - _display->setCursor(0, 0); - _display->setTextSize(1); - _display->setColor(UIColor::primary_txt); - _display->print(_node_prefs->node_name); - - // freq / sf - _display->setCursor(0, 20); - sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf); - _display->print(tmp); - - // bw / cr - _display->setCursor(0, 30); - sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr); - _display->print(tmp); - } -} - -void UITask::loop() { -#ifdef PIN_USER_BTN - if (millis() >= _next_read) { - int btnState = digitalRead(PIN_USER_BTN); - if (btnState != _prevBtnState) { - if (btnState == USER_BTN_PRESSED) { // pressed? - if (_display->isOn()) { - // TODO: any action ? - } else { - _display->turnOn(); - } - _auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer - } - _prevBtnState = btnState; - } - _next_read = millis() + 200; // 5 reads per second - } -#endif - - if (_display->isOn()) { - if (millis() >= _next_refresh) { - _display->startFrame(); - renderCurrScreen(); - _display->endFrame(); - - _next_refresh = millis() + 1000; // refresh every second - } - if (millis() > _auto_off) { - _display->turnOff(); - } - } -} diff --git a/examples/simple_sensor/UITask.h b/examples/simple_sensor/UITask.h deleted file mode 100644 index a27259f11..000000000 --- a/examples/simple_sensor/UITask.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include - -class UITask { - DisplayDriver* _display; - unsigned long _next_read, _next_refresh, _auto_off; - int _prevBtnState; - NodePrefs* _node_prefs; - char _version_info[32]; - - void renderCurrScreen(); -public: - UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; } - void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version); - - void loop(); -}; \ No newline at end of file diff --git a/examples/simple_sensor/main.cpp b/examples/simple_sensor/main.cpp index 66991daad..5a99dcbf5 100644 --- a/examples/simple_sensor/main.cpp +++ b/examples/simple_sensor/main.cpp @@ -1,10 +1,5 @@ #include "SensorMesh.h" -#ifdef DISPLAY_CLASS - #include "UITask.h" - static UITask ui_task(display); -#endif - class MyMesh : public SensorMesh { public: MyMesh(mesh::MainBoard& board, mesh::Radio& radio, mesh::MillisecondClock& ms, mesh::RNG& rng, mesh::RTCClock& rtc, mesh::MeshTables& tables) @@ -111,7 +106,7 @@ void setup() { the_mesh.begin(fs); #ifdef DISPLAY_CLASS - ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION); + ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION, "< Sensor >"); #endif // send out initial zero hop Advertisement to the mesh diff --git a/src/helpers/ui/BaseUITask.cpp b/src/helpers/ui/BaseUITask.cpp new file mode 100644 index 000000000..4df2d37bb --- /dev/null +++ b/src/helpers/ui/BaseUITask.cpp @@ -0,0 +1,17 @@ +#include "BaseUITask.h" +#include + +void BaseUITask::loop() { + if (_display->isOn()) { + if (millis() >= _next_refresh) { + _display->startFrame(); + long interval = renderCurrScreen(); + _display->endFrame(); + + _next_refresh = millis() + interval; + } + if (millis() > _auto_off) { + _display->turnOff(); + } + } +} \ No newline at end of file diff --git a/src/helpers/ui/BaseUITask.h b/src/helpers/ui/BaseUITask.h new file mode 100644 index 000000000..433e8ba50 --- /dev/null +++ b/src/helpers/ui/BaseUITask.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +// #include + +class BaseUITask { +protected: + mesh::MainBoard* _board; + DisplayDriver* _display; + unsigned long _next_refresh, _auto_off; + + BaseUITask(mesh::MainBoard* board, DisplayDriver* display) : _board(board), _display(display) { _next_refresh = 0; } + + virtual long renderCurrScreen() = 0; + +public: + virtual void loop(); +}; diff --git a/examples/simple_repeater/UITask.cpp b/src/helpers/ui/server/UITask.cpp similarity index 91% rename from examples/simple_repeater/UITask.cpp rename to src/helpers/ui/server/UITask.cpp index e0b6a41df..b6a08270e 100644 --- a/examples/simple_repeater/UITask.cpp +++ b/src/helpers/ui/server/UITask.cpp @@ -29,7 +29,7 @@ static const uint8_t meshcore_logo [] PROGMEM = { 0xe3, 0xe3, 0x8f, 0xff, 0x1f, 0xfc, 0x3c, 0x0e, 0x1f, 0xf8, 0xff, 0xf8, 0x70, 0x3c, 0x7f, 0xf8, }; -void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) { +void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, const char* role_lbl) { _prevBtnState = HIGH; _auto_off = millis() + AUTO_OFF_MILLIS; _started_at = millis(); @@ -44,16 +44,18 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi // e.g: v1.2.3-abcdef -> v1.2.3 char *version = strdup(firmware_version); char *dash = strchr(version, '-'); - if(dash){ + if (dash){ *dash = 0; } // v1.2.3 (1 Jan 2025) snprintf(_version_info, sizeof(_version_info), "%s (%s)", version, build_date); free(version); + + _role_label = role_lbl; } -void UITask::renderCurrScreen() { +long UITask::renderCurrScreen() { char tmp[80]; if (millis() < _started_at + BOOT_SCREEN_MILLIS) { // boot screen // meshcore logo @@ -72,8 +74,7 @@ void UITask::renderCurrScreen() { _display->drawTextCentered(_display->width() / 2, 35, _version_info); // node type - const char* node_type = "< Repeater >"; - _display->drawTextCentered(_display->width() / 2, 48, node_type); + _display->drawTextCentered(_display->width() / 2, 48, _role_label); } else if (_powering_off_at > 0) { // meshcore logo _display->setColor(UIColor::corp_blue); @@ -107,6 +108,7 @@ void UITask::renderCurrScreen() { sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr); _display->print(tmp); } + return 1000; // 1 sec interval } void UITask::loop() { @@ -126,18 +128,7 @@ void UITask::loop() { } #endif - if (_display->isOn()) { - if (millis() >= _next_refresh) { - _display->startFrame(); - renderCurrScreen(); - _display->endFrame(); - - _next_refresh = millis() + 1000; // refresh every second - } - if (millis() > _auto_off) { - _display->turnOff(); - } - } + BaseUITask::loop(); if (_powering_off_at > 0) { // power off timer armed #if defined(LED_PIN) && defined(LED_STATE_ON) diff --git a/src/helpers/ui/server/UITask.h b/src/helpers/ui/server/UITask.h new file mode 100644 index 000000000..57e649ac8 --- /dev/null +++ b/src/helpers/ui/server/UITask.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include + +class UITask : public BaseUITask { + unsigned long _next_read; + int _prevBtnState; + NodePrefs* _node_prefs; + char _version_info[32]; + const char* _role_label; + unsigned long _powering_off_at = 0; + unsigned long _started_at = 0; + +protected: + long renderCurrScreen() override; + +public: + UITask(mesh::MainBoard& board, DisplayDriver& display) : BaseUITask(&board, &display) { _next_read = 0; } + void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, const char* role_lbl); + + void loop() override; +}; diff --git a/variants/heltec_v3/platformio.ini b/variants/heltec_v3/platformio.ini index 06c028569..a5978c3ee 100644 --- a/variants/heltec_v3/platformio.ini +++ b/variants/heltec_v3/platformio.ini @@ -31,7 +31,8 @@ build_flags = -D PIN_GPS_TX=48 -D PIN_GPS_EN=26 build_src_filter = ${esp32_base.build_src_filter} - +<../variants/heltec_v3> + +<../variants/heltec_v3/target.cpp> + + + lib_deps = ${esp32_base.lib_deps} @@ -41,6 +42,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} + -I src/helpers/ui/server -D DISPLAY_CLASS=SSD1306Display -D ADVERT_NAME='"Heltec Repeater"' -D ADVERT_LAT=0.0 @@ -51,7 +53,9 @@ build_flags = ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + +<../examples/simple_repeater> + +<../variants/heltec_v3/target-other.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} ${esp32_ota.lib_deps} @@ -76,7 +80,9 @@ build_flags = build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + + +<../examples/simple_repeater> + +<../variants/heltec_v3/target-other.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} ${esp32_ota.lib_deps} @@ -98,7 +104,9 @@ build_flags = build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + + +<../examples/simple_repeater> + +<../variants/heltec_v3/target-other.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} ${esp32_ota.lib_deps} @@ -107,6 +115,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} + -I src/helpers/ui/server -D DISPLAY_CLASS=SSD1306Display -D ADVERT_NAME='"Heltec Room"' -D ADVERT_LAT=0.0 @@ -117,7 +126,9 @@ build_flags = ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + +<../examples/simple_room_server> + +<../variants/heltec_v3/target-other.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} ${esp32_ota.lib_deps} @@ -140,7 +151,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} - -I examples/companion_radio/ui-new +; -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=SSD1306Display @@ -150,8 +161,10 @@ build_flags = build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> + +<../variants/heltec_v3/target-companion.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} densaugeo/base64 @ ~1.4.0 @@ -160,7 +173,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} - -I examples/companion_radio/ui-new +; -I examples/companion_radio/ui-new -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 -D DISPLAY_CLASS=SSD1306Display @@ -174,10 +187,12 @@ build_flags = build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + + + + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> + +<../variants/heltec_v3/target-companion.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} densaugeo/base64 @ ~1.4.0 @@ -186,7 +201,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} - -I examples/companion_radio/ui-new +; -I examples/companion_radio/ui-new -D ENABLE_WIFI_INTERFACE -D MAX_CONTACTS=350 -D MAX_GROUP_CHANNELS=40 @@ -200,10 +215,12 @@ build_flags = build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + + + + +<../examples/companion_radio/*.cpp> +<../examples/companion_radio/ui-new/*.cpp> + +<../variants/heltec_v3/target-companion.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} densaugeo/base64 @ ~1.4.0 @@ -212,6 +229,7 @@ lib_deps = extends = Heltec_lora32_v3 build_flags = ${Heltec_lora32_v3.build_flags} + -I src/helpers/ui/server -D ADVERT_NAME='"Heltec v3 Sensor"' -D ADVERT_LAT=0.0 -D ADVERT_LON=0.0 @@ -223,7 +241,9 @@ build_flags = ; -D MESH_DEBUG=1 build_src_filter = ${Heltec_lora32_v3.build_src_filter} + + + +<../examples/simple_sensor> + +<../variants/heltec_v3/target-other.cpp> lib_deps = ${Heltec_lora32_v3.lib_deps} ${esp32_ota.lib_deps} diff --git a/variants/heltec_v3/target-companion.cpp b/variants/heltec_v3/target-companion.cpp new file mode 100644 index 000000000..571abbb9f --- /dev/null +++ b/variants/heltec_v3/target-companion.cpp @@ -0,0 +1,9 @@ +#include +#include "target.h" + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display; + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); + + // TODO: UITask +#endif diff --git a/variants/heltec_v3/target-other.cpp b/variants/heltec_v3/target-other.cpp new file mode 100644 index 000000000..bccc29b00 --- /dev/null +++ b/variants/heltec_v3/target-other.cpp @@ -0,0 +1,9 @@ +#include +#include "target.h" + +#ifdef DISPLAY_CLASS + DISPLAY_CLASS display; + MomentaryButton user_btn(PIN_USER_BTN, 1000, true); + + UITask ui_task(board, display); +#endif diff --git a/variants/heltec_v3/target.cpp b/variants/heltec_v3/target.cpp index f2f712eb0..e2cca8689 100644 --- a/variants/heltec_v3/target.cpp +++ b/variants/heltec_v3/target.cpp @@ -24,11 +24,6 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock); EnvironmentSensorManager sensors; #endif -#ifdef DISPLAY_CLASS - DISPLAY_CLASS display; - MomentaryButton user_btn(PIN_USER_BTN, 1000, true); -#endif - bool radio_init() { fallback_clock.begin(); rtc_clock.begin(Wire); diff --git a/variants/heltec_v3/target.h b/variants/heltec_v3/target.h index 2944b3843..242a51e5b 100644 --- a/variants/heltec_v3/target.h +++ b/variants/heltec_v3/target.h @@ -11,6 +11,7 @@ #ifdef DISPLAY_CLASS #include #include + #include // needs -I(nclude) path setting #endif extern HeltecV3Board board; @@ -21,6 +22,7 @@ extern EnvironmentSensorManager sensors; #ifdef DISPLAY_CLASS extern DISPLAY_CLASS display; extern MomentaryButton user_btn; + extern UITask ui_task; #endif bool radio_init();