Add configurable battery and USB display behavior
Persist separate display modes and timeouts in seconds for battery and USB power, expose four controls in WebConfig and CLI, and apply one shared policy across display-equipped roles. Detect R8 external power from a USB host or calibrated battery voltage above 4.21 V, with cached sampling and hysteresis. Add policy, persistence, browser, and R8 power-detection regression coverage.
This commit is contained in:
1 parent
d83153e935
commit
a814a00ce7
39 files changed
+3187
-2488
No files matched your search
@@ -13,9 +13,6 @@
|
||||
|
||||
#include "NodePrefs.h"
|
||||
|
||||
#ifndef UI_USB_AUTO_OFF_MULTIPLIER
|
||||
#define UI_USB_AUTO_OFF_MULTIPLIER 5UL
|
||||
#endif
|
||||
|
||||
enum class UIEventType {
|
||||
none,
|
||||
@@ -50,26 +47,9 @@ protected:
|
||||
|| _shutdownGuard->prepareForUiShutdown();
|
||||
}
|
||||
|
||||
bool isDisplayAutoOffDue(unsigned long configured_deadline,
|
||||
unsigned long configured_timeout_millis) const {
|
||||
unsigned long deadline = configured_deadline;
|
||||
#if UI_USB_AUTO_OFF_MULTIPLIER > 1
|
||||
if (_board->isUsbHostConnected()) {
|
||||
// The configured deadline already includes the first timeout period.
|
||||
// Add the remaining periods while attached to a computer.
|
||||
deadline += configured_timeout_millis
|
||||
* (UI_USB_AUTO_OFF_MULTIPLIER - 1UL);
|
||||
}
|
||||
#endif
|
||||
return static_cast<int32_t>(millis() - deadline) > 0;
|
||||
}
|
||||
|
||||
bool shouldWakeDisplayForMessage() const {
|
||||
// Keep the existing BLE-only behavior, where the connected companion is
|
||||
// expected to surface the notification. A computer attached over USB is
|
||||
// the exception: show the message on the device even if BLE is connected.
|
||||
return !hasConnection() || _board->isUsbHostConnected();
|
||||
}
|
||||
|
||||
bool shouldWakeDisplayForMessage() const { return !hasConnection(); }
|
||||
|
||||
public:
|
||||
void setShutdownGuard(UIShutdownGuard* guard) { _shutdownGuard = guard; }
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <helpers/ui/DisplayPowerSettings.h>
|
||||
#include "MyMesh.h"
|
||||
|
||||
#include <Arduino.h> // needed for PlatformIO
|
||||
@@ -1723,6 +1724,14 @@ void MyMesh::begin(bool has_display, bool radio_available) {
|
||||
}
|
||||
#endif
|
||||
|
||||
mesh::ui::loadDisplayPowerSettings(_store->getPrimaryFS(),
|
||||
#ifdef BLE_PIN_CODE
|
||||
true
|
||||
#else
|
||||
false
|
||||
#endif
|
||||
);
|
||||
|
||||
// load persisted prefs
|
||||
const bool prefs_ready =
|
||||
_store->loadPrefs(_prefs, sensors.node_lat, sensors.node_lon);
|
||||
@@ -2546,6 +2555,8 @@ bool MyMesh::handleLocalControlCommand(const char* command, char* reply,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mesh::ui::handleDisplayPowerCommand(command, reply, reply_size)) return true;
|
||||
|
||||
if (strcmp(command, "get display.touch") == 0) {
|
||||
if (_ui == NULL || !_ui->supportsTouchDebug()) {
|
||||
snprintf(reply, reply_size, "Error: touchscreen diagnostics unsupported");
|
||||
|
||||
@@ -1591,7 +1591,7 @@ void halt() {
|
||||
|| static_cast<int32_t>(millis() - companion_setup_display_refresh) < 0) return;
|
||||
companion_setup_display_refresh = millis() + 1000;
|
||||
|
||||
companion_setup_display->turnOn();
|
||||
if (!companion_setup_display->isOn()) return;
|
||||
companion_setup_display->startFrame();
|
||||
companion_setup_display->setCompactText(false);
|
||||
companion_setup_display->setTextSize(1);
|
||||
@@ -2294,12 +2294,7 @@ void setup() {
|
||||
&& UI_WIFI_SETUP_HOME_PAGE != 1
|
||||
companion_setup_display = disp;
|
||||
#endif
|
||||
disp->startFrame();
|
||||
#ifdef ST7789
|
||||
disp->setTextSize(2);
|
||||
#endif
|
||||
disp->drawTextCentered(disp->width() / 2, 28, "Loading...");
|
||||
disp->endFrame();
|
||||
disp->turnOff(); // No boot content before the saved policy is loaded.
|
||||
}
|
||||
#if defined(ESP32) && defined(WIFI_SSID)
|
||||
companion_display_available = disp != NULL;
|
||||
@@ -2737,6 +2732,7 @@ void loop() {
|
||||
#if defined(TBEAM_1W) && defined(PIN_WIFI_BTN)
|
||||
ui_task.serviceWiFiToggleButton();
|
||||
#endif
|
||||
ui_task.loop(); // Continue button/touch handling while the portal is active.
|
||||
renderCompanionSetupDisplay();
|
||||
} else {
|
||||
ui_task.loop();
|
||||
|
||||
@@ -427,7 +427,6 @@ class HomeScreen : public UIScreen {
|
||||
uint64_t _uptime_millis;
|
||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||
|
||||
|
||||
int renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
|
||||
// Convert millivolts to percentage
|
||||
#ifndef BATT_MIN_MILLIVOLTS
|
||||
@@ -1662,7 +1661,6 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
if (_display != NULL) {
|
||||
_display->setRotationDegrees(node_prefs->display_rotation_degrees);
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
|
||||
#if defined(PIN_USER_BTN)
|
||||
user_btn.begin();
|
||||
@@ -1682,7 +1680,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
_node_prefs = node_prefs;
|
||||
|
||||
if (_display != NULL) {
|
||||
_display->turnOn();
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection());
|
||||
}
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
@@ -1726,18 +1724,16 @@ void UITask::showMessages() {
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
void UITask::showJohnReader() {
|
||||
if (!_display || isPairingScreenActive()) return;
|
||||
if (!_display->isOn()) _display->turnOn();
|
||||
if (!_display->isOn()) _display->wake(mesh::ui::DisplayWake::Button);
|
||||
if (!john_reader) john_reader = new (std::nothrow) JohnReaderScreen(this, _display);
|
||||
if (!john_reader) { showAlert("Reader: no memory", 1500); return; }
|
||||
static_cast<JohnReaderScreen*>(john_reader)->open();
|
||||
setCurrScreen(john_reader);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
|
||||
void UITask::closeJohnReader() {
|
||||
// Home retains the selected radio page while the reader is open.
|
||||
setCurrScreen(home);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1778,7 +1774,6 @@ switch(t){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void UITask::msgRead(int msgcount) {
|
||||
_msgcount = msgcount;
|
||||
if (msgcount == 0) {
|
||||
@@ -1826,13 +1821,10 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
|
||||
: 0;
|
||||
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn() && shouldWakeDisplayForMessage()) {
|
||||
_display->turnOn();
|
||||
}
|
||||
if (_display->isOn()) {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
||||
_next_refresh = 100; // trigger refresh
|
||||
if (shouldWakeDisplayForMessage()) {
|
||||
_display->wake(mesh::ui::DisplayWake::Message);
|
||||
}
|
||||
if (_display->isOn()) _next_refresh = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1900,10 +1892,8 @@ void UITask::showPairingPin() {
|
||||
}
|
||||
static_cast<HomeScreen*>(home)->showFirstPage();
|
||||
setCurrScreen(home);
|
||||
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn()) _display->turnOn();
|
||||
_auto_off = now + AUTO_OFF_MILLIS;
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection(), true);
|
||||
_next_refresh = 0;
|
||||
}
|
||||
}
|
||||
@@ -1914,14 +1904,12 @@ void UITask::finishPairingScreen(bool timed_out) {
|
||||
if (_deferred_msg_preview && _msgcount > 0) {
|
||||
_deferred_msg_preview = false;
|
||||
setCurrScreen(msg_preview);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
} else {
|
||||
_deferred_msg_preview = false;
|
||||
gotoHomeScreen();
|
||||
if (timed_out && _display != NULL) {
|
||||
_display->turnOff();
|
||||
_display->dismiss();
|
||||
} else {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_next_refresh = 0;
|
||||
}
|
||||
}
|
||||
@@ -1939,6 +1927,15 @@ void UITask::servicePairingState() {
|
||||
finishPairingScreen(timed_out);
|
||||
}
|
||||
}
|
||||
if (_display != NULL && _display->servicePower(
|
||||
_board->isExternalPowered() || _board->isUsbHostConnected(),
|
||||
hasConnection(), isPairingScreenActive())) {
|
||||
_next_refresh = 0;
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (!_display->isOn() && isJohnReaderActive())
|
||||
static_cast<JohnReaderScreen*>(john_reader)->flush();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2032,7 +2029,7 @@ void UITask::loop() {
|
||||
c = handleLongPress(KEY_ENTER);
|
||||
else
|
||||
#endif
|
||||
display.turnOff();
|
||||
display.dismiss();
|
||||
} else if (ev == BUTTON_EVENT_DOUBLE_CLICK) {
|
||||
c = handleDoubleClick(KEY_SELECT);
|
||||
} else if (ev == BUTTON_EVENT_TRIPLE_CLICK || ev == BUTTON_EVENT_QUADRUPLE_CLICK) {
|
||||
@@ -2149,12 +2146,11 @@ void UITask::loop() {
|
||||
#endif
|
||||
#if defined(BACKLIGHT_BTN)
|
||||
if (millis() > next_backlight_btn_check) {
|
||||
bool touch_state = digitalRead(PIN_BUTTON2);
|
||||
#if defined(DISP_BACKLIGHT)
|
||||
digitalWrite(DISP_BACKLIGHT, !touch_state);
|
||||
#elif defined(EXP_PIN_BACKLIGHT)
|
||||
expander.digitalWrite(EXP_PIN_BACKLIGHT, !touch_state);
|
||||
#endif
|
||||
static bool was_pressed = false;
|
||||
const bool pressed = digitalRead(PIN_BUTTON2) == LOW;
|
||||
if (pressed && !was_pressed && _display != NULL)
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
was_pressed = pressed;
|
||||
next_backlight_btn_check = millis() + 300;
|
||||
}
|
||||
#endif
|
||||
@@ -2167,8 +2163,8 @@ void UITask::loop() {
|
||||
}
|
||||
|
||||
if (c != 0 && curr) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
curr->handleInput(c);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_next_refresh = 100; // trigger refresh
|
||||
}
|
||||
|
||||
@@ -2225,24 +2221,9 @@ void UITask::loop() {
|
||||
_display->endFrame();
|
||||
}
|
||||
#if AUTO_OFF_MILLIS > 0
|
||||
#ifdef KEEP_DISPLAY_ON_USB
|
||||
// Opt-in: refresh the auto-off deadline while externally powered, so the
|
||||
// timer counts from the moment external power is removed. Off by default
|
||||
// because OLED panels burn in quickly; only enable for LCD targets or
|
||||
// where the display is replaceable.
|
||||
if (board.isExternalPowered()) {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
#endif
|
||||
#if MOMENTARY_BUTTON_WAKE_HOLD_MS > 0 && defined(PIN_USER_BTN)
|
||||
if (user_btn.isWakeHoldActive()) _auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
if (user_btn.isWakeHoldActive()) _display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
if (!isPairingScreenActive() && isDisplayAutoOffDue(_auto_off, AUTO_OFF_MILLIS)) {
|
||||
#if COMPANION_FEATURE_JOHN
|
||||
if (isJohnReaderActive()) static_cast<JohnReaderScreen*>(john_reader)->flush();
|
||||
#endif
|
||||
_display->turnOff();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -2305,11 +2286,11 @@ void UITask::getTouchControls(mesh::ui::TouchSplitSelector& transport_touch_sele
|
||||
|
||||
char UITask::checkDisplayOn(char c) {
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn(); // turn display on and consume event
|
||||
const bool was_on = _display->isOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
if (!was_on) {
|
||||
c = 0;
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_next_refresh = 0; // trigger refresh
|
||||
}
|
||||
return c;
|
||||
|
||||
@@ -35,7 +35,7 @@ class UITask : public AbstractUITask {
|
||||
#ifdef PIN_VIBRATION
|
||||
GenericVibration vibration;
|
||||
#endif
|
||||
unsigned long _next_refresh, _auto_off;
|
||||
unsigned long _next_refresh;
|
||||
unsigned long _msg_preview_until;
|
||||
unsigned long _pairing_screen_until;
|
||||
bool _deferred_msg_preview;
|
||||
|
||||
@@ -53,11 +53,11 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
if (_display != NULL) {
|
||||
_display->setRotationDegrees(node_prefs->display_rotation_degrees);
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
|
||||
clearMsgPreview();
|
||||
_node_prefs = node_prefs;
|
||||
if (_display != NULL) {
|
||||
_display->turnOn();
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection());
|
||||
}
|
||||
|
||||
// strip off dash and commit hash by changing dash to null terminator
|
||||
@@ -182,13 +182,10 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
|
||||
StrHelper::strncpy(_msg, text, sizeof(_msg));
|
||||
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn() && shouldWakeDisplayForMessage()) {
|
||||
_display->turnOn();
|
||||
}
|
||||
if (_display->isOn()) {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
||||
_need_refresh = true;
|
||||
if (shouldWakeDisplayForMessage()) {
|
||||
_display->wake(mesh::ui::DisplayWake::Message);
|
||||
}
|
||||
if (_display->isOn()) _need_refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,7 +482,7 @@ void UITask::showPairingPin() {
|
||||
_need_refresh = true;
|
||||
_next_refresh = 0;
|
||||
if (_display != NULL && !_display->isOn()) {
|
||||
_display->turnOn();
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -496,9 +493,7 @@ void UITask::finishPairingScreen(bool timed_out) {
|
||||
if (_display == NULL) return;
|
||||
|
||||
if (timed_out) {
|
||||
_display->turnOff();
|
||||
} else {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_display->dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -514,6 +509,12 @@ void UITask::servicePairingState() {
|
||||
finishPairingScreen(timed_out);
|
||||
}
|
||||
}
|
||||
if (_display != NULL && _display->servicePower(
|
||||
_board->isExternalPowered() || _board->isUsbHostConnected(),
|
||||
hasConnection(), isPairingScreenActive())) {
|
||||
_next_refresh = 0;
|
||||
_need_refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
void UITask::loop() {
|
||||
@@ -548,18 +549,6 @@ void UITask::loop() {
|
||||
|
||||
_next_refresh = millis() + 1000; // refresh every second
|
||||
}
|
||||
#ifdef KEEP_DISPLAY_ON_USB
|
||||
// Opt-in: refresh the auto-off deadline while externally powered, so the
|
||||
// timer counts from the moment external power is removed. Off by default
|
||||
// because OLED panels burn in quickly; only enable for LCD targets or
|
||||
// where the display is replaceable.
|
||||
if (board.isExternalPowered()) {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
#endif
|
||||
if (!isPairingScreenActive() && isDisplayAutoOffDue(_auto_off, AUTO_OFF_MILLIS)) {
|
||||
_display->turnOff();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -569,10 +558,7 @@ void UITask::handleButtonAnyPress() {
|
||||
// do not refresh the display here, as it may block the button handler
|
||||
if (_display != NULL) {
|
||||
_displayWasOn = _display->isOn(); // Track display state before any action
|
||||
if (!_displayWasOn) {
|
||||
_display->turnOn();
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class UITask : public AbstractUITask {
|
||||
#ifdef HAS_DRV2605
|
||||
DRV2605Vibration vibration;
|
||||
#endif
|
||||
unsigned long _next_refresh, _auto_off;
|
||||
unsigned long _next_refresh;
|
||||
CompanionNodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
char _origin[62];
|
||||
|
||||
@@ -171,7 +171,6 @@ public:
|
||||
// display.setCursor(0, 0);
|
||||
// display.print(filtered_name);
|
||||
|
||||
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setTextSize(2);
|
||||
sprintf(tmp, "MSG: %d", _task->getMsgCount());
|
||||
@@ -441,7 +440,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#if UI_SMALL_MESSAGE_FONT == 1
|
||||
class TinyMessageScreen : public UIScreen {
|
||||
UITask* _task;
|
||||
@@ -480,7 +478,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
if (_display != NULL) {
|
||||
_display->setRotationDegrees(node_prefs->display_rotation_degrees);
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
|
||||
_cached_batt_mv = getBattMilliVolts();
|
||||
|
||||
#if defined(PIN_USER_BTN)
|
||||
@@ -493,11 +491,10 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
_node_prefs = node_prefs;
|
||||
|
||||
if (_display != NULL) {
|
||||
_display->turnOn();
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection());
|
||||
}
|
||||
_statusBar.begin(_display->width());
|
||||
|
||||
|
||||
#ifdef PIN_BUZZER
|
||||
buzzer.begin();
|
||||
buzzer.quiet(_node_prefs->buzzer_quiet);
|
||||
@@ -553,7 +550,6 @@ switch(t){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void UITask::msgRead(int msgcount) {
|
||||
_msgcount = msgcount;
|
||||
if (msgcount == 0) {
|
||||
@@ -580,13 +576,10 @@ void UITask::newMsg(uint8_t path_len, const char* from_name, const char* text,
|
||||
#endif
|
||||
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn() && shouldWakeDisplayForMessage()) {
|
||||
_display->turnOn();
|
||||
}
|
||||
if (_display->isOn()) {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend the auto-off timer
|
||||
_next_refresh = 100; // trigger refresh
|
||||
if (shouldWakeDisplayForMessage()) {
|
||||
_display->wake(mesh::ui::DisplayWake::Message);
|
||||
}
|
||||
if (_display->isOn()) _next_refresh = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -630,9 +623,8 @@ void UITask::showPairingPin() {
|
||||
_pairing_screen_until = now + BLE_PAIRING_DISPLAY_MILLIS;
|
||||
static_cast<HomeScreen*>(home)->showFirstPage();
|
||||
setCurrScreen(home);
|
||||
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn()) _display->turnOn();
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection(), true);
|
||||
_next_refresh = 0;
|
||||
}
|
||||
}
|
||||
@@ -649,9 +641,7 @@ void UITask::finishPairingScreen(bool timed_out) {
|
||||
if (_display == NULL) return;
|
||||
|
||||
if (timed_out) {
|
||||
_display->turnOff();
|
||||
} else {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_display->dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -667,6 +657,9 @@ void UITask::servicePairingState() {
|
||||
finishPairingScreen(timed_out);
|
||||
}
|
||||
}
|
||||
if (_display != NULL && _display->servicePower(
|
||||
_board->isExternalPowered() || _board->isUsbHostConnected(),
|
||||
hasConnection(), isPairingScreenActive())) _next_refresh = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -760,12 +753,11 @@ void UITask::loop() {
|
||||
#endif
|
||||
#if defined(BACKLIGHT_BTN)
|
||||
if (millis() > next_backlight_btn_check) {
|
||||
bool touch_state = digitalRead(PIN_BUTTON2);
|
||||
#if defined(DISP_BACKLIGHT)
|
||||
digitalWrite(DISP_BACKLIGHT, !touch_state);
|
||||
#elif defined(EXP_PIN_BACKLIGHT)
|
||||
expander.digitalWrite(EXP_PIN_BACKLIGHT, !touch_state);
|
||||
#endif
|
||||
static bool was_pressed = false;
|
||||
const bool pressed = digitalRead(PIN_BUTTON2) == LOW;
|
||||
if (pressed && !was_pressed && _display != NULL)
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
was_pressed = pressed;
|
||||
next_backlight_btn_check = millis() + 300;
|
||||
}
|
||||
#endif
|
||||
@@ -786,8 +778,8 @@ void UITask::loop() {
|
||||
}
|
||||
|
||||
if (c != 0 && curr) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
curr->handleInput(c);
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_next_refresh = 100; // trigger refresh
|
||||
}
|
||||
|
||||
@@ -836,18 +828,9 @@ void UITask::loop() {
|
||||
_display->endFrame();
|
||||
}
|
||||
#if AUTO_OFF_MILLIS > 0
|
||||
#ifdef KEEP_DISPLAY_ON_USB
|
||||
// Opt-in: refresh the auto-off deadline while externally powered, so the
|
||||
// timer counts from the moment external power is removed. Off by default
|
||||
// because OLED panels burn in quickly; only enable for LCD targets or
|
||||
// where the display is replaceable.
|
||||
if (board.isExternalPowered()) {
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
}
|
||||
#if MOMENTARY_BUTTON_WAKE_HOLD_MS > 0 && defined(PIN_USER_BTN)
|
||||
if (user_btn.isWakeHoldActive()) _display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
if (!isPairingScreenActive() && isDisplayAutoOffDue(_auto_off, AUTO_OFF_MILLIS)) {
|
||||
_display->turnOff();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -884,11 +867,11 @@ void UITask::loop() {
|
||||
|
||||
char UITask::checkDisplayOn(char c) {
|
||||
if (_display != NULL) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn(); // turn display on and consume event
|
||||
const bool was_on = _display->isOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
if (!was_on) {
|
||||
c = 0;
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_next_refresh = 0; // trigger refresh
|
||||
}
|
||||
return c;
|
||||
|
||||
@@ -35,7 +35,7 @@ class UITask : public AbstractUITask {
|
||||
#ifdef PIN_VIBRATION
|
||||
GenericVibration vibration;
|
||||
#endif
|
||||
unsigned long _next_refresh, _auto_off;
|
||||
unsigned long _next_refresh;
|
||||
CompanionNodePrefs* _node_prefs;
|
||||
char _alert[80];
|
||||
unsigned long _alert_expiry;
|
||||
|
||||
@@ -19,9 +19,6 @@
|
||||
#include <helpers/esp32/WebConfigServer.h> // defines WITH_WEBCONFIG on ESP32
|
||||
#endif
|
||||
|
||||
#ifndef AUTO_OFF_MILLIS
|
||||
#define AUTO_OFF_MILLIS 20000 // 20 seconds; 0 keeps the screen on
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
#define TOUCH_POLL_MILLIS 50
|
||||
@@ -55,15 +52,6 @@ void UITask::applyDisplayFlip() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// `display.timeout` when the observer prefs are available, otherwise the
|
||||
// compiled-in default. Read on every use so a `set display.timeout` takes
|
||||
// effect immediately.
|
||||
unsigned long UITask::displayTimeoutMillis() const {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (_observer_prefs) return (unsigned long)_observer_prefs->display_timeout_secs * 1000UL;
|
||||
#endif
|
||||
return AUTO_OFF_MILLIS;
|
||||
}
|
||||
#define BOOT_SCREEN_MILLIS 4000 // 4 seconds
|
||||
|
||||
#define POWEROFF_DELAY 3000
|
||||
@@ -87,14 +75,12 @@ static const uint8_t meshcore_logo [] PROGMEM = {
|
||||
|
||||
void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) {
|
||||
_prevBtnState = HIGH;
|
||||
_timeout_seen = displayTimeoutMillis();
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
_started_at = millis();
|
||||
_node_prefs = node_prefs;
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
ObserverDashboard::applyDarkPalette(); // retunes UIColor for this target only
|
||||
#endif
|
||||
_display->turnOn();
|
||||
_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected());
|
||||
applyDisplayFlip();
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
_touch.begin();
|
||||
@@ -360,11 +346,7 @@ void UITask::updateActivityRows() {
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
void UITask::toggleDisplay(const char* source) {
|
||||
if (_display->isOn()) {
|
||||
_display->turnOff();
|
||||
} else {
|
||||
_display->turnOn();
|
||||
}
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#ifdef DISPLAY_TOUCH_DEBUG
|
||||
mesh::usbConsolePort().printf("Display: %s -> %s\n", source, _display->isOn() ? "on" : "off");
|
||||
#else
|
||||
@@ -377,11 +359,19 @@ void UITask::toggleDisplay(const char* source) {
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
_next_refresh = 0; // redraw at once rather than showing the stale frame
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
}
|
||||
#endif
|
||||
|
||||
void UITask::loop() {
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) {
|
||||
_next_refresh = 0;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS)
|
||||
int ev = user_btn.check();
|
||||
// Multiclick stays enabled on the R8 observer so triple-click can toggle
|
||||
@@ -394,7 +384,7 @@ void UITask::loop() {
|
||||
if (_display->isOn()) {
|
||||
// TODO: any action ?
|
||||
} else {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
@@ -402,10 +392,10 @@ void UITask::loop() {
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
_auto_off = millis() + displayTimeoutMillis(); // extend auto-off timer
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
mesh::usbConsolePort().printf("Powering Off\r\n");
|
||||
_powering_off_at = millis() + POWEROFF_DELAY;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
@@ -420,29 +410,11 @@ void UITask::loop() {
|
||||
// Preserve the fork's persistent WebUI toggle. R8 observer repeaters keep
|
||||
// multiclick enabled specifically for this action.
|
||||
WebConfigServer::requestToggleFromButton();
|
||||
_display->turnOn();
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_WEBCONFIG
|
||||
// While the setup portal is up there's no user button to wake the screen
|
||||
// reliably - keep it on so the join instructions stay visible.
|
||||
if (WebConfigServer::getSetupInfo(NULL, 0, NULL, 0)) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
{
|
||||
unsigned long now = millis();
|
||||
@@ -453,25 +425,6 @@ void UITask::loop() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Observe timeout changes even while the panel is blanked. In particular,
|
||||
// `set display.timeout 0` means the display must stay on, so wake it now
|
||||
// rather than waiting for a button/touch event that may never arrive.
|
||||
unsigned long timeout = displayTimeoutMillis();
|
||||
if (timeout != _timeout_seen) {
|
||||
_timeout_seen = timeout;
|
||||
_auto_off = millis() + timeout;
|
||||
if (timeout == 0 && !_display->isOn()) {
|
||||
_display->turnOn();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
_next_refresh = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (_display->isOn()) {
|
||||
// Apply a live orientation change before drawing, including the first frame
|
||||
// after a preference was changed while the panel was blanked.
|
||||
@@ -500,21 +453,6 @@ void UITask::loop() {
|
||||
|
||||
_next_refresh = millis() + 1000; // check for visible changes every second
|
||||
}
|
||||
// `_auto_off` is only armed on activity, so a timeout changed at runtime has
|
||||
// to restart the countdown here - otherwise 0 -> 60 blanks instantly off a
|
||||
// boot-time deadline, and 60 -> 3600 still blanks at the old 60 s mark.
|
||||
#if MOMENTARY_BUTTON_WAKE_HOLD_MS > 0 && defined(PIN_USER_BTN)
|
||||
if (user_btn.isWakeHoldActive()) _auto_off = millis() + timeout;
|
||||
#endif
|
||||
if (_powering_off_at == 0 && timeout > 0 && millisReached(millis(), _auto_off)) {
|
||||
_display->turnOff();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (_powering_off_at > 0) { // power off timer armed
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
class UITask {
|
||||
mesh::MainBoard* _board;
|
||||
DisplayDriver* _display;
|
||||
unsigned long _next_read, _next_refresh, _auto_off;
|
||||
unsigned long _next_read, _next_refresh;
|
||||
int _prevBtnState;
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
@@ -54,11 +54,9 @@ class UITask {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
MQTTPrefs* _observer_prefs = NULL;
|
||||
#endif
|
||||
unsigned long _timeout_seen = 0; // to notice a live `display.timeout` change
|
||||
uint8_t _flip_seen = 0xFF; // 0xFF forces the first apply
|
||||
void applyDisplayFlip();
|
||||
|
||||
unsigned long displayTimeoutMillis() const;
|
||||
|
||||
void renderCurrScreen();
|
||||
public:
|
||||
@@ -66,8 +64,7 @@ public:
|
||||
void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version);
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
// Supplies `display.timeout`, which is read live so a config change applies
|
||||
// without a reboot. Call before begin().
|
||||
// Supplies display.flip. Call before begin().
|
||||
void setObserverPrefs(MQTTPrefs* prefs) { _observer_prefs = prefs; }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -96,10 +96,7 @@ void setup() {
|
||||
#ifdef DISPLAY_CLASS
|
||||
display_ready = display.begin();
|
||||
if (display_ready) {
|
||||
display.startFrame();
|
||||
display.setCursor(0, 0);
|
||||
display.print("Please wait...");
|
||||
display.endFrame();
|
||||
display.turnOff(); // Stay dark until the saved display policy is loaded.
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,9 +18,6 @@
|
||||
#include <helpers/esp32/WebConfigServer.h> // defines WITH_WEBCONFIG on ESP32
|
||||
#endif
|
||||
|
||||
#ifndef AUTO_OFF_MILLIS
|
||||
#define AUTO_OFF_MILLIS 20000 // 20 seconds; 0 keeps the screen on
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
#define TOUCH_POLL_MILLIS 50
|
||||
@@ -54,15 +51,6 @@ void UITask::applyDisplayFlip() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// `display.timeout` when the observer prefs are available, otherwise the
|
||||
// compiled-in default. Read on every use so a `set display.timeout` takes
|
||||
// effect immediately.
|
||||
unsigned long UITask::displayTimeoutMillis() const {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
if (_observer_prefs) return (unsigned long)_observer_prefs->display_timeout_secs * 1000UL;
|
||||
#endif
|
||||
return AUTO_OFF_MILLIS;
|
||||
}
|
||||
#define BOOT_SCREEN_MILLIS 4000 // 4 seconds
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
@@ -88,14 +76,12 @@ static const uint8_t meshcore_logo [] PROGMEM = {
|
||||
|
||||
void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) {
|
||||
_prevBtnState = HIGH;
|
||||
_timeout_seen = displayTimeoutMillis();
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
_started_at = millis();
|
||||
_node_prefs = node_prefs;
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
ObserverDashboard::applyDarkPalette(); // retunes UIColor for this target only
|
||||
#endif
|
||||
_display->turnOn();
|
||||
_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected());
|
||||
applyDisplayFlip();
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
_touch.begin();
|
||||
@@ -342,11 +328,7 @@ void UITask::updateActivityRows() {
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
void UITask::toggleDisplay(const char* source) {
|
||||
if (_display->isOn()) {
|
||||
_display->turnOff();
|
||||
} else {
|
||||
_display->turnOn();
|
||||
}
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#ifdef DISPLAY_TOUCH_DEBUG
|
||||
mesh::usbConsolePort().printf("Display: %s -> %s\n", source, _display->isOn() ? "on" : "off");
|
||||
#else
|
||||
@@ -359,17 +341,25 @@ void UITask::toggleDisplay(const char* source) {
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
_next_refresh = 0; // redraw at once rather than showing the stale frame
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
}
|
||||
#endif
|
||||
|
||||
void UITask::loop() {
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) {
|
||||
_next_refresh = 0;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
#if defined(PIN_USER_BTN) && defined(DISPLAY_TOUCH_TOGGLE)
|
||||
int ev = user_btn.check();
|
||||
if (ev == BUTTON_EVENT_CLICK) {
|
||||
toggleDisplay("button");
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
mesh::usbConsolePort().printf("Powering Off\r\n");
|
||||
_powering_off_at = millis() + POWEROFF_DELAY;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
@@ -390,7 +380,7 @@ void UITask::loop() {
|
||||
int ev = user_btn.check();
|
||||
if (ev != BUTTON_EVENT_NONE) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
@@ -399,7 +389,7 @@ void UITask::loop() {
|
||||
#endif
|
||||
_next_refresh = 0;
|
||||
}
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
}
|
||||
#elif defined(PIN_USER_BTN)
|
||||
if (millisReached(millis(), _next_read)) {
|
||||
@@ -412,7 +402,7 @@ void UITask::loop() {
|
||||
if (_display->isOn()) {
|
||||
// TODO: any action ?
|
||||
} else {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
@@ -420,7 +410,7 @@ void UITask::loop() {
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
_auto_off = millis() + displayTimeoutMillis(); // extend auto-off timer
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
}
|
||||
_prevBtnState = btnState;
|
||||
@@ -429,23 +419,6 @@ void UITask::loop() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WITH_WEBCONFIG
|
||||
// While the setup portal is up there's no user button to wake the screen
|
||||
// reliably - keep it on so the join instructions stay visible.
|
||||
if (WebConfigServer::getSetupInfo(NULL, 0, NULL, 0)) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
_auto_off = millis() + displayTimeoutMillis();
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
{
|
||||
unsigned long now = millis();
|
||||
@@ -456,25 +429,6 @@ void UITask::loop() {
|
||||
}
|
||||
#endif
|
||||
|
||||
// Observe timeout changes even while the panel is blanked. In particular,
|
||||
// `set display.timeout 0` means the display must stay on, so wake it now
|
||||
// rather than waiting for a button/touch event that may never arrive.
|
||||
unsigned long timeout = displayTimeoutMillis();
|
||||
if (timeout != _timeout_seen) {
|
||||
_timeout_seen = timeout;
|
||||
_auto_off = millis() + timeout;
|
||||
if (timeout == 0 && !_display->isOn()) {
|
||||
_display->turnOn();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
_next_refresh = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (_display->isOn()) {
|
||||
// Apply a live orientation change before drawing, including the first frame
|
||||
// after a preference was changed while the panel was blanked.
|
||||
@@ -503,25 +457,6 @@ void UITask::loop() {
|
||||
|
||||
_next_refresh = millis() + 1000; // check for visible changes every second
|
||||
}
|
||||
// `_auto_off` is only armed on activity, so a timeout changed at runtime has
|
||||
// to restart the countdown here - otherwise 0 -> 60 blanks instantly off a
|
||||
// boot-time deadline, and 60 -> 3600 still blanks at the old 60 s mark.
|
||||
#if MOMENTARY_BUTTON_WAKE_HOLD_MS > 0 && defined(PIN_USER_BTN)
|
||||
if (user_btn.isWakeHoldActive()) _auto_off = millis() + timeout;
|
||||
#endif
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
if (_powering_off_at == 0 && timeout > 0 && millisReached(millis(), _auto_off)) {
|
||||
#else
|
||||
if (timeout > 0 && millisReached(millis(), _auto_off)) {
|
||||
#endif
|
||||
_display->turnOff();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
|
||||
@@ -21,7 +21,7 @@ class UITask {
|
||||
mesh::MainBoard* _board;
|
||||
#endif
|
||||
DisplayDriver* _display;
|
||||
unsigned long _next_read, _next_refresh, _auto_off;
|
||||
unsigned long _next_read, _next_refresh;
|
||||
int _prevBtnState;
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
@@ -58,11 +58,9 @@ class UITask {
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
MQTTPrefs* _observer_prefs = NULL;
|
||||
#endif
|
||||
unsigned long _timeout_seen = 0; // to notice a live `display.timeout` change
|
||||
uint8_t _flip_seen = 0xFF; // 0xFF forces the first apply
|
||||
void applyDisplayFlip();
|
||||
|
||||
unsigned long displayTimeoutMillis() const;
|
||||
|
||||
void renderCurrScreen();
|
||||
public:
|
||||
@@ -76,8 +74,7 @@ public:
|
||||
void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version);
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
// Supplies `display.timeout`, which is read live so a config change applies
|
||||
// without a reboot. Call before begin().
|
||||
// Supplies display.flip. Call before begin().
|
||||
void setObserverPrefs(MQTTPrefs* prefs) { _observer_prefs = prefs; }
|
||||
#endif
|
||||
|
||||
|
||||
@@ -62,10 +62,7 @@ void setup() {
|
||||
#ifdef DISPLAY_CLASS
|
||||
display_ready = display.begin();
|
||||
if (display_ready) {
|
||||
display.startFrame();
|
||||
display.setCursor(0, 0);
|
||||
display.print("Please wait...");
|
||||
display.endFrame();
|
||||
display.turnOff(); // Stay dark until the saved display policy is loaded.
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#define USER_BTN_PRESSED LOW
|
||||
#endif
|
||||
|
||||
#define AUTO_OFF_MILLIS 20000 // 20 seconds
|
||||
#define BOOT_SCREEN_MILLIS 4000 // 4 seconds
|
||||
|
||||
// 'meshcore', 128x13px
|
||||
@@ -29,9 +28,8 @@ static const uint8_t meshcore_logo [] PROGMEM = {
|
||||
|
||||
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();
|
||||
_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected());
|
||||
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) \
|
||||
&& defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
&& MOMENTARY_BUTTON_WAKE_FROM_SLEEP
|
||||
@@ -98,16 +96,17 @@ void UITask::renderCurrScreen() {
|
||||
}
|
||||
|
||||
void UITask::loop() {
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) _next_refresh = 0;
|
||||
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) \
|
||||
&& defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
&& MOMENTARY_BUTTON_WAKE_FROM_SLEEP
|
||||
int ev = user_btn.check();
|
||||
if (ev != BUTTON_EVENT_NONE) {
|
||||
if (!_display->isOn()) {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
_next_refresh = 0;
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
}
|
||||
#elif defined(PIN_USER_BTN)
|
||||
if (millis() >= _next_read) {
|
||||
@@ -117,9 +116,9 @@ void UITask::loop() {
|
||||
if (_display->isOn()) {
|
||||
// TODO: any action ?
|
||||
} else {
|
||||
_display->turnOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
}
|
||||
_auto_off = millis() + AUTO_OFF_MILLIS; // extend auto-off timer
|
||||
_display->wake(mesh::ui::DisplayWake::Button); // extend auto-off timer
|
||||
}
|
||||
_prevBtnState = btnState;
|
||||
}
|
||||
@@ -136,10 +135,8 @@ void UITask::loop() {
|
||||
_next_refresh = millis() + 1000; // refresh every second
|
||||
}
|
||||
#if MOMENTARY_BUTTON_WAKE_HOLD_MS > 0 && defined(PIN_USER_BTN)
|
||||
if (user_btn.isWakeHoldActive()) _auto_off = millis() + AUTO_OFF_MILLIS;
|
||||
if (user_btn.isWakeHoldActive()) _display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
if (millis() > _auto_off) {
|
||||
_display->turnOff();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
class UITask {
|
||||
DisplayDriver* _display;
|
||||
unsigned long _next_read, _next_refresh, _auto_off;
|
||||
unsigned long _next_read, _next_refresh;
|
||||
int _prevBtnState;
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
|
||||
@@ -75,9 +75,8 @@ void setup() {
|
||||
|
||||
#ifdef DISPLAY_CLASS
|
||||
if (display.begin()) {
|
||||
display.startFrame();
|
||||
display.print("Please wait...");
|
||||
display.endFrame();
|
||||
display.turnOff();
|
||||
// Saved display policy is applied by UITask::begin().
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Reference in new issue
Block a user