Move MeshPocket V2 role UIs into the board variant

This commit is contained in:
Quency-D committed 2026-11-20 15:16:59 +08:00
1 parent 7f9597fe44
commit 97b1c33609
20 files changed
+1820 -308

No files matched your search

-6
View File
@@ -42,8 +42,6 @@ namespace mesh {
#define BD_STARTUP_NORMAL 0 // getStartupReason() codes
#define BD_STARTUP_RX_PACKET 1
class BoardUiExtension;
class MainBoard {
public:
virtual uint16_t getBattMilliVolts() = 0;
@@ -72,7 +70,6 @@ public:
virtual bool isExternalPowered() { return false; }
// True while a board can identify an active battery-charging source.
virtual bool isChargerActive() { return false; }
virtual bool hasChargerStatus() const { return false; }
// Optional, source-specific power detection. Boards that can distinguish a USB
// supply from a solar charger override these; defaults keep every other board
@@ -88,9 +85,6 @@ public:
virtual uint8_t getShutdownReason() const { return 0; }
virtual const char* getShutdownReasonString(uint8_t reason) { return "Not available"; }
// Optional full-screen board UI. The returned object remains owned by the board.
virtual BoardUiExtension* getUiExtension() { return nullptr; }
virtual bool handleCommand(const char* command, uint32_t sender_timestamp, char* reply) { return false; }
// Called from the example main loops. Lets a board feed its watchdog and
+2 -1
View File
@@ -4,6 +4,7 @@
void BaseUITask::loop() {
if (_display->isOn()) {
if (millis() >= _next_refresh) {
_display->startFrame();
long interval = renderCurrScreen();
_display->endFrame();
@@ -13,4 +14,4 @@ void BaseUITask::loop() {
_display->turnOff();
}
}
}
}
-1
View File
@@ -12,7 +12,6 @@ protected:
BaseUITask(mesh::MainBoard* board, DisplayDriver* display) : _board(board), _display(display) { _next_refresh = 0; }
// The renderer starts its frame when a clear is needed. The loop ends it.
virtual long renderCurrScreen() = 0;
public:
-27
View File
@@ -1,27 +0,0 @@
#pragma once
#include <stdint.h>
class DisplayDriver;
namespace mesh {
class BoardUiExtension {
public:
enum Event : uint8_t {
EVENT_NONE = 0,
EVENT_SHOW_PAGE = 1 << 0,
EVENT_PAGE_ACTION = 1 << 1,
EVENT_REQUEST_FOCUS = 1 << 2,
};
// Consume and return all board-owned input and focus events for this loop.
virtual uint8_t pollEvents() = 0;
virtual void handlePageAction() {}
// The extension owns startFrame() and any coordinate-mode changes. The UI
// host calls endFrame() after render() returns.
virtual uint32_t render(DisplayDriver& display, bool fullRefresh) = 0;
};
}
-74
View File
@@ -1,74 +0,0 @@
#pragma once
#include <MeshCore.h>
#include "BoardUiExtension.h"
#include "DisplayDriver.h"
class BoardUiScreen {
mesh::BoardUiExtension* extension = nullptr;
DisplayDriver* display = nullptr;
bool selected = false;
bool fullRefresh = true;
void selectPage() {
if (!selected) {
selected = true;
fullRefresh = true;
}
}
public:
void begin(mesh::MainBoard& board, DisplayDriver& screen) {
extension = board.getUiExtension();
display = &screen;
}
bool available() const { return extension != nullptr; }
uint8_t pollEvents() {
if (!extension) return mesh::BoardUiExtension::EVENT_NONE;
if (!display->isOn()) fullRefresh = true;
return extension->pollEvents();
}
bool handleInput(uint8_t events, bool canOperate) {
if (!extension || !canOperate) return false;
const bool awake = display->isOn();
if (events & mesh::BoardUiExtension::EVENT_SHOW_PAGE) {
if (!awake) display->turnOn();
selectPage();
return true;
}
if ((events & mesh::BoardUiExtension::EVENT_PAGE_ACTION) && awake && selected) {
extension->handlePageAction();
return true;
}
return false;
}
bool handleFocusRequest(uint8_t events, bool canTakeFocus, bool handlingInput) {
if (!extension || !(events & mesh::BoardUiExtension::EVENT_REQUEST_FOCUS) ||
!canTakeFocus || handlingInput) return false;
const bool awake = display->isOn();
if (!awake) display->turnOn();
selectPage();
if (!awake) fullRefresh = true;
return true;
}
bool togglePage() {
if (!extension) return false;
selected = !selected;
fullRefresh = true;
return true;
}
bool renderIfSelected(uint32_t& interval) {
if (!extension || !selected) return false;
interval = extension->render(*display, fullRefresh);
fullRefresh = false;
return true;
}
};
-3
View File
@@ -22,9 +22,6 @@ public:
int width() const { return _w; }
int height() const { return _h; }
// Optional physical-pixel coordinate mode. Unsupported displays keep their
// existing logical coordinate system.
virtual void setNativePixels(bool) {}
virtual bool isOn() = 0;
virtual bool isEink() { return false; } // default to non-eink, override in eink drivers
virtual void forceFullRefresh() {} // next refresh will be full for eink
+1 -1
View File
@@ -66,7 +66,7 @@ public:
#endif
bool begin();
void setNativePixels(bool enabled) override;
void setNativePixels(bool enabled);
static const char* driverName() { return "NV3001B"; }
static uint16_t physicalWidth() { return NV3001B_PANEL_WIDTH; }
static uint16_t physicalHeight() { return NV3001B_PANEL_HEIGHT; }
+11 -74
View File
@@ -142,7 +142,6 @@ class HomeScreen : public UIScreen {
#ifndef UI_NO_HIBERNATE
SHUTDOWN,
#endif
BOARD_PAGE,
Count // keep as last
};
@@ -150,10 +149,8 @@ class HomeScreen : public UIScreen {
mesh::RTCClock* _rtc;
SensorManager* _sensors;
NodePrefs* _node_prefs;
mesh::BoardUiExtension* _board_ui;
uint8_t _page;
bool _shutdown_init;
bool boardPageFullRefresh;
int recent_next_idx;
AdvertPath recent[UI_RECENT_LIST_SIZE];
#if UI_DISCOVER_SCREEN
@@ -196,7 +193,7 @@ class HomeScreen : public UIScreen {
// while charging, show a bolt (or a plug once full) just left of the battery,
// keeping the fill bar itself clean and uninterrupted
bool charging = board.hasChargerStatus() ? board.isChargerActive() : board.isExternalPowered();
bool charging = board.isExternalPowered();
if (charging) {
// There's no charge-complete signal on most boards, so "full" is a high
// voltage band rather than an exact 100% (a real pack rarely reads 4.2V).
@@ -243,10 +240,9 @@ class HomeScreen : public UIScreen {
}
public:
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs,
mesh::BoardUiExtension* board_ui)
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _board_ui(board_ui), _page(0),
_shutdown_init(false), boardPageFullRefresh(true), sensors_lpp(200)
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, NodePrefs* node_prefs)
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
_shutdown_init(false), sensors_lpp(200)
{
memset(recent, 0, sizeof(recent));
recent_next_idx = 0;
@@ -300,28 +296,7 @@ public:
}
}
uint8_t pageCount() const { return _board_ui ? HomePage::Count : HomePage::BOARD_PAGE; }
bool isBoardPage() const { return _board_ui && _page == BOARD_PAGE; }
void invalidateBoardPage() { if (_board_ui) boardPageFullRefresh = true; }
bool showBoardPage() {
if (!_board_ui || _shutdown_init) return false;
#ifndef UI_NO_HIBERNATE
if (_page == SHUTDOWN) return false;
#endif
if (_page != BOARD_PAGE) {
_page = BOARD_PAGE;
boardPageFullRefresh = true;
}
return true;
}
int render(DisplayDriver& display) override {
if (isBoardPage()) {
const int interval = _board_ui->render(display, boardPageFullRefresh);
boardPageFullRefresh = false;
return interval;
}
display.setColor(UIColor::title_bkg);
display.fillRect(0, 0, display.width(), 12);
char tmp[80];
@@ -343,9 +318,8 @@ public:
display.setColor(UIColor::title_bkg);
}
int y = 14;
const uint8_t count = pageCount();
int x = display.width() / 2 - 5 * (count-1);
for (uint8_t i = 0; i < count; i++, x += 10) {
int x = display.width() / 2 - 5 * (HomePage::Count-1);
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) {
if (i == _page) {
display.fillRect(x-1, y-1, 4, 4);
} else {
@@ -645,14 +619,11 @@ public:
bool handleInput(char c) override {
if (c == KEY_LEFT || c == KEY_PREV) {
const uint8_t count = pageCount();
_page = (_page + count - 1) % count;
invalidateBoardPage();
_page = (_page + HomePage::Count - 1) % HomePage::Count;
return true;
}
if (c == KEY_NEXT || c == KEY_RIGHT) {
_page = (_page + 1) % pageCount();
invalidateBoardPage();
_page = (_page + 1) % HomePage::Count;
if (_page == HomePage::RECENT) {
_task->showAlert("Recent adverts", 800);
}
@@ -821,7 +792,6 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
{
_display = display;
_sensors = sensors;
_board_ui = _board->getUiExtension();
_interfaceManager = serial;
the_mesh = mesh;
_ble_pin = ble_pin;
@@ -858,7 +828,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
_alert_expiry = 0;
splash = new SplashScreen(this, ver, build_date);
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs, _board_ui);
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs);
msg_preview = new MsgPreviewScreen(this, &rtc_clock);
setCurrScreen(splash);
}
@@ -988,7 +958,6 @@ void UITask::userLedHandler() {
}
void UITask::setCurrScreen(UIScreen* c) {
if (curr && curr == home && c != home) static_cast<HomeScreen*>(home)->invalidateBoardPage();
curr = c;
_next_refresh = 100;
}
@@ -1030,16 +999,8 @@ bool UITask::isButtonPressed() const {
#endif
}
void UITask::handleBoardUiFocus(uint8_t events, bool handlingInput) {
// Consume even when busy: an old event must not steal focus later.
if (!(events & mesh::BoardUiExtension::EVENT_REQUEST_FOCUS) || handlingInput ||
!_display || curr != home || millis() < _alert_expiry) return;
if (static_cast<HomeScreen*>(home)->showBoardPage()) checkDisplayOn(0);
}
void UITask::loop() {
char c = 0;
bool boardInputHandled = false;
#if UI_HAS_JOYSTICK
int ev = user_btn.check();
if (ev == BUTTON_EVENT_CLICK) {
@@ -1097,21 +1058,6 @@ void UITask::loop() {
}
}
#endif
const uint8_t boardEvents = _board_ui ? _board_ui->pollEvents() : mesh::BoardUiExtension::EVENT_NONE;
HomeScreen* homeScreen = static_cast<HomeScreen*>(home);
if ((boardEvents & mesh::BoardUiExtension::EVENT_SHOW_PAGE) && c == 0 &&
curr == home && homeScreen->showBoardPage()) {
checkDisplayOn(0);
boardInputHandled = true;
}
else if ((boardEvents & mesh::BoardUiExtension::EVENT_PAGE_ACTION) && c == 0 &&
_display && _display->isOn() && curr == home && homeScreen->isBoardPage() &&
millis() >= _alert_expiry) {
_board_ui->handlePageAction();
_auto_off = millis() + _node_prefs->ui_auto_off_delay * 1000;
_next_refresh = 0;
boardInputHandled = true;
}
#if defined(PIN_USER_BTN_ANA)
if (abs(millis() - _analogue_pin_read_millis) > 10) {
int ev = analog_btn.check();
@@ -1170,7 +1116,6 @@ void UITask::loop() {
#endif
#endif
handleBoardUiFocus(boardEvents, c != 0 || boardInputHandled);
if (c != 0 && curr) {
curr->handleInput(c);
_auto_off = millis() + _node_prefs->ui_auto_off_delay * 1000; // extend auto-off timer
@@ -1188,15 +1133,9 @@ void UITask::loop() {
if (_display != NULL && _display->isOn()) {
if (millis() >= _next_refresh && curr) {
HomeScreen* homeScreen = static_cast<HomeScreen*>(home);
const bool boardFrame = curr == home && homeScreen->isBoardPage();
const bool alertVisible = millis() < _alert_expiry;
// A board page may keep its pixels for field-level updates.
if (!boardFrame || (boardPageHadAlert && !alertVisible)) homeScreen->invalidateBoardPage();
if (!boardFrame) _display->startFrame();
boardPageHadAlert = boardFrame && alertVisible;
_display->startFrame();
int delay_millis = curr->render(*_display);
if (alertVisible) { // render alert popup
if (millis() < _alert_expiry) { // render alert popup
_display->setTextSize(1);
int y = _display->height() / 3;
int p = _display->height() / 32;
@@ -1222,7 +1161,6 @@ void UITask::loop() {
}
#endif
if (millis() > _auto_off) {
static_cast<HomeScreen*>(home)->invalidateBoardPage();
if (_node_prefs->ui_auto_off_blank &&
!(_node_prefs->ui_auto_off_keep_msgs
&& curr == msg_preview)) {
@@ -1264,7 +1202,6 @@ void UITask::loop() {
char UITask::checkDisplayOn(char c) {
if (_display != NULL) {
if (!_display->isOn()) {
static_cast<HomeScreen*>(home)->invalidateBoardPage();
_display->turnOn(_node_prefs->ui_max_partial); // turn display on and consume event
c = 0;
}
+1 -6
View File
@@ -1,7 +1,6 @@
#pragma once
#include <MeshCore.h>
#include <helpers/ui/BoardUiExtension.h>
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/UIScreen.h>
#include <helpers/SensorManager.h>
@@ -81,8 +80,6 @@ class UITask : public AbstractUITask {
UIScreen* home;
UIScreen* msg_preview;
UIScreen* curr;
mesh::BoardUiExtension* _board_ui;
bool boardPageHadAlert = false;
void userLedHandler();
@@ -93,12 +90,10 @@ class UITask : public AbstractUITask {
char handleTripleClick(char c);
void setCurrScreen(UIScreen* c);
void handleBoardUiFocus(uint8_t events, bool handlingInput);
public:
UITask(mesh::MainBoard* board, DisplayDriver* display = NULL) :
AbstractUITask(board), _display(display), _sensors(NULL), _board_ui(nullptr) {
UITask(mesh::MainBoard* board, DisplayDriver* display = NULL) : AbstractUITask(board), _display(display), _sensors(NULL) {
next_batt_chck = _next_refresh = 0;
ui_started_at = 0;
curr = NULL;
+6 -45
View File
@@ -30,18 +30,13 @@ static const uint8_t meshcore_logo [] PROGMEM = {
};
void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version, const char* role_lbl) {
#ifdef MESHPOCKET_V2_ROOM_SERVER
_prevBtnState = HIGH;
_started_at = 0; // The Room Server's splash starts at power-on.
#else
_started_at = millis();
#endif
_auto_off = millis() + AUTO_OFF_MILLIS;
_started_at = millis();
_node_prefs = node_prefs;
_display->turnOn();
boardScreen.begin(*_board, *_display);
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) && !defined(MESHPOCKET_V2_ROOM_SERVER)
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS)
user_btn.begin();
#endif
@@ -61,9 +56,6 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
}
long UITask::renderCurrScreen() {
uint32_t interval;
if (!_powering_off_at && boardScreen.renderIfSelected(interval)) return interval;
_display->startFrame();
char tmp[80];
if (millis() < _started_at + BOOT_SCREEN_MILLIS) { // boot screen
// meshcore logo
@@ -120,53 +112,22 @@ long UITask::renderCurrScreen() {
}
void UITask::loop() {
const uint8_t boardEvents = boardScreen.pollEvents();
bool handlingInput = false;
const bool canChangePage = !_powering_off_at && millis() - _started_at >= BOOT_SCREEN_MILLIS;
if (boardScreen.handleInput(boardEvents, canChangePage)) {
handlingInput = true;
_auto_off = millis() + AUTO_OFF_MILLIS;
_next_refresh = 0;
}
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS)
#ifdef MESHPOCKET_V2_ROOM_SERVER
int ev = BUTTON_EVENT_NONE;
if (millis() >= _next_read) {
const int btnState = digitalRead(PIN_USER_BTN);
if (btnState == USER_BTN_PRESSED && btnState != _prevBtnState) ev = BUTTON_EVENT_CLICK;
_prevBtnState = btnState;
_next_read = millis() + 200;
}
#else
int ev = user_btn.check();
#endif
handlingInput = handlingInput || ev != BUTTON_EVENT_NONE;
if (ev == BUTTON_EVENT_CLICK) {
if (_display->isOn()) {
if (canChangePage && boardScreen.togglePage()) {
_next_refresh = 0;
}
// TODO: any action ?
} else {
_display->turnOn();
}
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
_display->turnOn();
Serial.println("Powering Off");
_powering_off_at = millis() + POWEROFF_DELAY;
if (boardScreen.available()) {
_next_refresh = 0;
_auto_off = millis() + AUTO_OFF_MILLIS;
}
_display->turnOn();
Serial.println("Powering Off");
_powering_off_at = millis() + POWEROFF_DELAY;
}
#endif
const bool canTakePowerEvent = !_powering_off_at && millis() - _started_at >= BOOT_SCREEN_MILLIS;
if (boardScreen.handleFocusRequest(boardEvents, canTakePowerEvent, handlingInput)) {
_auto_off = millis() + AUTO_OFF_MILLIS;
_next_refresh = 0;
}
BaseUITask::loop();
if (_powering_off_at > 0) { // power off timer armed
+2 -6
View File
@@ -1,15 +1,11 @@
#pragma once
#include <helpers/ui/BaseUITask.h>
#include <helpers/ui/BoardUiScreen.h>
#include <helpers/CommonCLI.h>
class UITask : public BaseUITask {
BoardUiScreen boardScreen;
#ifdef MESHPOCKET_V2_ROOM_SERVER
unsigned long _next_read = 0;
unsigned long _next_read;
int _prevBtnState;
#endif
NodePrefs* _node_prefs;
char _version_info[32];
const char* _role_label;
@@ -20,7 +16,7 @@ protected:
long renderCurrScreen() override;
public:
UITask(mesh::MainBoard* board, DisplayDriver* display) : BaseUITask(board, display) {}
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;