feat: add MeshPocket V2 support

This commit is contained in:
Quency-D committed 2026-11-10 18:34:03 +08:00
1 parent 9f10793f7a
commit ae8cc34e10
25 files changed
+1210 -37

No files matched your search

+74 -11
View File
@@ -107,6 +107,7 @@ class HomeScreen : public UIScreen {
#ifndef UI_NO_HIBERNATE
SHUTDOWN,
#endif
BOARD_PAGE,
Count // keep as last
};
@@ -114,8 +115,10 @@ class HomeScreen : public UIScreen {
mesh::RTCClock* _rtc;
SensorManager* _sensors;
NodePrefs* _node_prefs;
mesh::BoardUiExtension* _board_ui;
uint8_t _page;
bool _shutdown_init;
bool boardPageFullRefresh;
AdvertPath recent[UI_RECENT_LIST_SIZE];
#if UI_DISCOVER_SCREEN
DiscoveredNode discovered[DISCOVERED_NODES_TABLE_SIZE]; // not circular, latest discovered nodes are not kept
@@ -157,7 +160,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.isExternalPowered();
bool charging = board.hasChargerStatus() ? board.isChargerActive() : 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).
@@ -204,9 +207,10 @@ class HomeScreen : public UIScreen {
}
public:
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) { }
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) { }
#if UI_DISCOVER_SCREEN
bool sendDiscoverRequest() {
@@ -248,7 +252,28 @@ 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];
@@ -270,8 +295,9 @@ public:
display.setColor(UIColor::title_bkg);
}
int y = 14;
int x = display.width() / 2 - 5 * (HomePage::Count-1);
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) {
const uint8_t count = pageCount();
int x = display.width() / 2 - 5 * (count-1);
for (uint8_t i = 0; i < count; i++, x += 10) {
if (i == _page) {
display.fillRect(x-1, y-1, 4, 4);
} else {
@@ -561,11 +587,14 @@ public:
bool handleInput(char c) override {
if (c == KEY_LEFT || c == KEY_PREV) {
_page = (_page + HomePage::Count - 1) % HomePage::Count;
const uint8_t count = pageCount();
_page = (_page + count - 1) % count;
invalidateBoardPage();
return true;
}
if (c == KEY_NEXT || c == KEY_RIGHT) {
_page = (_page + 1) % HomePage::Count;
_page = (_page + 1) % pageCount();
invalidateBoardPage();
if (_page == HomePage::RECENT) {
_task->showAlert("Recent adverts", 800);
}
@@ -724,6 +753,7 @@ public:
void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* node_prefs) {
_display = display;
_sensors = sensors;
_board_ui = _board->getUiExtension();
#if defined(PIN_USER_BTN)
user_btn.begin();
@@ -757,7 +787,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, NodePrefs* no
_alert_expiry = 0;
splash = new SplashScreen(this);
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs);
home = new HomeScreen(this, &rtc_clock, sensors, node_prefs, _board_ui);
msg_preview = new MsgPreviewScreen(this, &rtc_clock);
setCurrScreen(splash);
}
@@ -885,6 +915,7 @@ void UITask::userLedHandler() {
}
void UITask::setCurrScreen(UIScreen* c) {
if (curr && curr == home && c != home) static_cast<HomeScreen*>(home)->invalidateBoardPage();
curr = c;
_next_refresh = 100;
}
@@ -926,8 +957,16 @@ 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) {
@@ -985,6 +1024,21 @@ 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();
@@ -1043,6 +1097,7 @@ 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
@@ -1060,9 +1115,15 @@ void UITask::loop() {
if (_display != NULL && _display->isOn()) {
if (millis() >= _next_refresh && curr) {
_display->startFrame();
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;
int delay_millis = curr->render(*_display);
if (millis() < _alert_expiry) { // render alert popup
if (alertVisible) { // render alert popup
_display->setTextSize(1);
int y = _display->height() / 3;
int p = _display->height() / 32;
@@ -1088,6 +1149,7 @@ 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)) {
@@ -1129,6 +1191,7 @@ 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;
}
+6 -1
View File
@@ -1,6 +1,7 @@
#pragma once
#include <MeshCore.h>
#include <helpers/ui/BoardUiExtension.h>
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/UIScreen.h>
#include <helpers/SensorManager.h>
@@ -77,6 +78,8 @@ class UITask : public AbstractUITask {
UIScreen* home;
UIScreen* msg_preview;
UIScreen* curr;
mesh::BoardUiExtension* _board_ui;
bool boardPageHadAlert = false;
void userLedHandler();
@@ -87,10 +90,12 @@ class UITask : public AbstractUITask {
char handleTripleClick(char c);
void setCurrScreen(UIScreen* c);
void handleBoardUiFocus(uint8_t events, bool handlingInput);
public:
UITask(mesh::MainBoard* board, MultiSerialInterface* serial) : AbstractUITask(board, serial), _display(NULL), _sensors(NULL) {
UITask(mesh::MainBoard* board, MultiSerialInterface* serial) :
AbstractUITask(board, serial), _display(NULL), _sensors(NULL), _board_ui(nullptr) {
next_batt_chck = _next_refresh = 0;
ui_started_at = 0;
curr = NULL;
+31 -6
View File
@@ -35,6 +35,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
_started_at = millis();
_node_prefs = node_prefs;
_display->turnOn();
boardScreen.begin(*_board, *_display);
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS)
user_btn.begin();
@@ -53,7 +54,10 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
free(version);
}
void UITask::renderCurrScreen() {
unsigned 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
@@ -107,14 +111,26 @@ void UITask::renderCurrScreen() {
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
_display->print(tmp);
}
return 1000;
}
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)
int ev = user_btn.check();
handlingInput = handlingInput || ev != BUTTON_EVENT_NONE;
if (ev == BUTTON_EVENT_CLICK) {
if (_display->isOn()) {
// TODO: any action ?
if (canChangePage && boardScreen.togglePage()) {
_next_refresh = 0;
}
} else {
_display->turnOn();
}
@@ -122,17 +138,26 @@ void UITask::loop() {
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
_display->turnOn();
Serial.println("Powering Off");
_powering_off_at = millis() + POWEROFF_DELAY;
_powering_off_at = millis() + POWEROFF_DELAY;
if (boardScreen.available()) {
_next_refresh = 0;
_auto_off = millis() + AUTO_OFF_MILLIS;
}
}
#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;
}
if (_display->isOn()) {
if (millis() >= _next_refresh) {
_display->startFrame();
renderCurrScreen();
unsigned long interval = renderCurrScreen();
_display->endFrame();
_next_refresh = millis() + 1000; // refresh every second
_next_refresh = millis() + interval;
}
if (millis() > _auto_off) {
_display->turnOff();
+4 -2
View File
@@ -1,9 +1,11 @@
#pragma once
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/BoardUiScreen.h>
#include <helpers/CommonCLI.h>
class UITask {
BoardUiScreen boardScreen;
mesh::MainBoard* _board;
DisplayDriver* _display;
unsigned long _next_read, _next_refresh, _auto_off;
@@ -13,10 +15,10 @@ class UITask {
unsigned long _powering_off_at = 0;
unsigned long _started_at = 0;
void renderCurrScreen();
unsigned long 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();
};
};
+25 -5
View File
@@ -31,6 +31,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
_auto_off = millis() + AUTO_OFF_MILLIS;
_node_prefs = node_prefs;
_display->turnOn();
boardScreen.begin(*_board, *_display);
// strip off dash and commit hash by changing dash to null terminator
// e.g: v1.2.3-abcdef -> v1.2.3
@@ -45,7 +46,10 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
free(version);
}
void UITask::renderCurrScreen() {
unsigned long UITask::renderCurrScreen() {
uint32_t interval;
if (boardScreen.renderIfSelected(interval)) return interval;
_display->startFrame();
char tmp[80];
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen
// meshcore logo
@@ -89,16 +93,28 @@ void UITask::renderCurrScreen() {
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
_display->print(tmp);
}
return 1000;
}
void UITask::loop() {
const uint8_t boardEvents = boardScreen.pollEvents();
bool handlingInput = false;
const bool canChangePage = millis() >= BOOT_SCREEN_MILLIS;
if (boardScreen.handleInput(boardEvents, canChangePage)) {
handlingInput = true;
_auto_off = millis() + AUTO_OFF_MILLIS;
_next_refresh = 0;
}
#ifdef PIN_USER_BTN
if (millis() >= _next_read) {
int btnState = digitalRead(PIN_USER_BTN);
if (btnState != _prevBtnState) {
if (btnState == USER_BTN_PRESSED) { // pressed?
handlingInput = true;
if (_display->isOn()) {
// TODO: any action ?
if (canChangePage && boardScreen.togglePage()) {
_next_refresh = 0;
}
} else {
_display->turnOn();
}
@@ -110,13 +126,17 @@ void UITask::loop() {
}
#endif
if (boardScreen.handleFocusRequest(boardEvents, canChangePage, handlingInput)) {
_auto_off = millis() + AUTO_OFF_MILLIS;
_next_refresh = 0;
}
if (_display->isOn()) {
if (millis() >= _next_refresh) {
_display->startFrame();
renderCurrScreen();
unsigned long interval = renderCurrScreen();
_display->endFrame();
_next_refresh = millis() + 1000; // refresh every second
_next_refresh = millis() + interval;
}
if (millis() > _auto_off) {
_display->turnOff();
+6 -3
View File
@@ -1,19 +1,22 @@
#pragma once
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/BoardUiScreen.h>
#include <helpers/CommonCLI.h>
class UITask {
BoardUiScreen boardScreen;
mesh::MainBoard* _board;
DisplayDriver* _display;
unsigned long _next_read, _next_refresh, _auto_off;
int _prevBtnState;
NodePrefs* _node_prefs;
char _version_info[32];
void renderCurrScreen();
unsigned long renderCurrScreen();
public:
UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; }
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();
};
};
+1 -1
View File
@@ -10,7 +10,7 @@
#ifdef DISPLAY_CLASS
#include "UITask.h"
static UITask ui_task(display);
static UITask ui_task(board, display);
#endif
StdRNG fast_rng;