Files
HaloKeymind/examples/simple_room_server/UITask.h
T
mikecarper a814a00ce7 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.
2026-09-10 21:03:15 -07:00

87 lines
2.2 KiB
C++

#pragma once
#include <helpers/ui/DisplayDriver.h>
#include <helpers/CommonCLI.h>
#ifdef DISPLAY_ACTIVITY_DASHBOARD
#ifndef DISPLAY_REDRAW_ON_CHANGE
#error "DISPLAY_ACTIVITY_DASHBOARD needs DISPLAY_REDRAW_ON_CHANGE: without it every frame clears the whole screen"
#endif
#include <helpers/RadioActivityWindow.h>
#include <helpers/ui/ObserverDashboard.h>
#endif
#ifdef DISPLAY_TOUCH_TOGGLE
#include <helpers/ui/CHSC6XTouch.h>
#endif
class UITask {
#ifdef DISPLAY_TOUCH_TOGGLE
mesh::MainBoard* _board;
#endif
DisplayDriver* _display;
unsigned long _next_read, _next_refresh;
int _prevBtnState;
NodePrefs* _node_prefs;
char _version_info[32];
unsigned long _started_at = 0;
#ifdef DISPLAY_TOUCH_TOGGLE
unsigned long _powering_off_at = 0;
#endif
#ifdef DISPLAY_REDRAW_ON_CHANGE
uint32_t _last_frame_signature = 0;
bool _frame_valid = false;
uint32_t getFrameSignature();
#endif
#ifdef DISPLAY_ACTIVITY_DASHBOARD
RadioActivityWindow* _activity = NULL;
unsigned long _next_activity = 0;
uint32_t _row_signatures[ObserverDashboard::ROW_COUNT] = {0};
bool _rows_valid = false; // true only while the dashboard is the drawn screen
bool buildDashboardContext(ObserverDashboard::Context* ctx);
void renderDashboard();
void updateActivityRows();
#endif
#ifdef DISPLAY_TOUCH_TOGGLE
CHSC6XTouch _touch;
unsigned long _next_touch = 0;
void toggleDisplay(const char* source);
#endif
#ifdef WITH_MQTT_BRIDGE
MQTTPrefs* _observer_prefs = NULL;
#endif
uint8_t _flip_seen = 0xFF; // 0xFF forces the first apply
void applyDisplayFlip();
void renderCurrScreen();
public:
#ifdef DISPLAY_TOUCH_TOGGLE
UITask(mesh::MainBoard& board, DisplayDriver& display) : _board(&board), _display(&display) {
_next_read = _next_refresh = 0;
}
#else
UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; }
#endif
void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version);
#ifdef WITH_MQTT_BRIDGE
// Supplies display.flip. Call before begin().
void setObserverPrefs(MQTTPrefs* prefs) { _observer_prefs = prefs; }
#endif
#ifdef DISPLAY_ACTIVITY_DASHBOARD
void setActivityWindow(RadioActivityWindow* activity) { _activity = activity; }
#endif
void loop();
};