Files
MeshCore/examples/simple_repeater/UITask.h
T
agessaman ca17c2980c feat(display): add runtime display.flip for panel orientation
`set display.flip 0|1` (also off/on) turns the panel 180 degrees from its
compiled DISPLAY_ROTATION, persisted in MQTTPrefs alongside display.timeout
and applied live without a reboot.

Adding 2 to the compiled rotation rather than setting an absolute value keeps
portrait portrait and landscape landscape, so the DisplayViewport geometry
never changes with it and the setting cannot produce a nonsensical mix.
DisplayDriver gains a defaulted no-op setFlipped(), so no other display
driver is affected.

The compiled rotation was verified identical across `pio run` and `build.sh`
on two machines (movi a11, 2 at the setRotation call site), yet the panel read
upside down for one tester and upright for another - which is what a board
mounted either way up looks like. No single compiled constant satisfies both,
so orientation becomes a setting rather than another rebuild.

Runtime-only, like display_timeout_secs: LegacyV1MQTTPrefs and the frozen
binary payload sizes are untouched, and the JSON group is an append that older
firmware skips.
2026-08-28 14:37:03 -07:00

80 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 {
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;
#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();
#endif
#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:
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);
#ifdef WITH_MQTT_BRIDGE
// Supplies `display.timeout`, which is read live so a config change applies
// without a reboot. Call before begin().
void setObserverPrefs(MQTTPrefs* prefs) { _observer_prefs = prefs; }
#endif
#ifdef DISPLAY_ACTIVITY_DASHBOARD
void setActivityWindow(RadioActivityWindow* activity) { _activity = activity; }
#endif
void loop();
};