feat(ui): page radio and system status

This commit is contained in:
mikecarper committed 2026-09-21 15:35:46 -07:00
1 parent 653578c818
commit b089b745fa
28 files changed
+2075 -73

No files matched your search

+16
View File
@@ -134,6 +134,22 @@ public:
virtual float getNoiseFloorDbm() const {
return static_cast<float>(getNoiseFloor());
}
// Profile zero is the primary radio. Radios that scan a second profile can
// expose its independent floor without changing the legacy stats API.
virtual float getNoiseFloorDbm(uint8_t profile) const {
(void)profile;
return getNoiseFloorDbm();
}
// A zero result means there is no active sampled calibration window (or
// that this transport does not expose one). The estimate itself may remain
// visible while a later refresh is being collected.
virtual float getNoiseFloorCalibrationSecondsRemaining() const { return 0.0f; }
virtual float getNoiseFloorCalibrationSecondsRemaining(uint8_t profile) const {
(void)profile;
return getNoiseFloorCalibrationSecondsRemaining();
}
virtual bool isCalibratingNoiseFloor() const { return false; }
virtual void triggerNoiseFloorCalibrate(int threshold) { }
+8 -1
View File
@@ -793,8 +793,15 @@ void CommonCLI::loadPrefs(FILESYSTEM* fs) {
_com_prefs_needs_upgrade = false;
#endif
} else {
// File doesn't exist - set default bridge settings for fresh installs
// File doesn't exist - set defaults for a fresh install. Dual R1/R2
// scanning keeps the node awake, so only that configuration starts with
// device power saving off. A saved preference is never rewritten here.
is_fresh_install = true;
mesh::Radio* profile_radio = _callbacks->getProfileRadio();
const bool dual_radio_active = profile_radio != NULL
&& profile_radio->profiles() != NULL
&& profile_radio->profiles()->enabled();
_prefs->powersaving_enabled = DEFAULT_POWERSAVING_ENABLED && !dual_radio_active ? 1 : 0;
_prefs->bridge_pkt_src = 1; // Default to RX (logRx) for new installs
}
#ifdef WITH_MQTT_BRIDGE
+2 -2
View File
@@ -20,7 +20,7 @@
#define DEFAULT_CAD_ENABLED 0
#endif
#ifndef DEFAULT_POWERSAVING_ENABLED
#define DEFAULT_POWERSAVING_ENABLED 0
#define DEFAULT_POWERSAVING_ENABLED 1
#endif
#if defined(ESP32_PLATFORM) || defined(USER_GPIO_CONTROL)
@@ -156,7 +156,7 @@ public:
uint8_t bridge_channel = 0; // 1-13 (ESP-NOW only)
char bridge_secret[16] = {}; // for XOR encryption of bridge packets (ESP-NOW only)
// Power setting
uint8_t powersaving_enabled = 0; // boolean
uint8_t powersaving_enabled = DEFAULT_POWERSAVING_ENABLED ? 1 : 0; // boolean
uint8_t reboot_interval = 0; // hours, 0-255 (default 0=disable)
// Gps settings
uint8_t gps_enabled = 0;
@@ -22,6 +22,13 @@ private:
public:
uint16_t count() const { return _count; }
uint16_t samplesRemaining() const { return SAMPLE_COUNT - _count; }
// This is the best-case remaining time: rejected RSSI reads and received
// packets deliberately pause the collection window rather than fabricate
// samples. It is useful for a compact UI progress indication.
float secondsRemaining() const {
return samplesRemaining() * (SAMPLE_INTERVAL_MS / 1000.0f);
}
bool complete() const { return _count == SAMPLE_COUNT; }
bool ready(uint32_t now) const {
return !complete() && (_count == 0 || uint32_t(now - _last_sample_at) >= SAMPLE_INTERVAL_MS);
+127 -12
View File
@@ -13,7 +13,11 @@
#define NF_CALIB_INTERVAL_MS 2000UL // match the original 2-second refresh cadence
#define NF_CALIB_TIMEOUT_MS NoiseFloorEstimator::WINDOW_TIMEOUT_MS
#define NF_CONTINUOUS_TIMEOUT_MS NoiseFloorEstimator::WINDOW_TIMEOUT_MS
#define NF_CALIB_SETTLE_MS 20UL // frontend/AGC settle after RX entry
#define NF_CALIB_SETTLE_MS RadioLibWrapper::NoiseFloorSettleMillis
// A profile normally visited for less than its RSSI settle time stays fast
// during ordinary scanning. Refresh its floor with one bounded slow-visit
// sample set every fifteen minutes instead.
#define NF_FAST_PROFILE_REFRESH_INTERVAL_MS (15UL * 60UL * 1000UL)
static volatile uint8_t state = STATE_IDLE;
@@ -64,7 +68,9 @@ void RadioLibWrapper::begin() {
_noise_floor = 0;
_noise_floor_centi_dbm = 0;
_noise_floor_secondary_centi_dbm = 0;
_noise_floor_valid = false;
_noise_floor_secondary_valid = false;
_threshold = 0;
_cad_enabled = false;
_rx_mode_checked_at = millis();
@@ -75,6 +81,7 @@ void RadioLibWrapper::begin() {
// start average out some samples
_floor_estimator.reset(true);
_secondary_floor_estimator.reset(true);
_nf_calib_active = false;
_nf_last_calib = 0;
_nf_sample_from = 0;
@@ -324,6 +331,11 @@ mesh::RadioParamApplyResult RadioLibWrapper::tuneProfile(uint8_t profile) {
if (!restored || (resume && !isInRecvMode())) _profile_refresh_required = true;
}
_profile_visit_us = micros();
// A profile retune re-enters RX on a different tuple. Do not read its
// instantaneous RSSI until the chip family's settle interval has elapsed.
if (applied && _nf_refresh_requested) {
_nf_sample_from = millis() + NF_CALIB_SETTLE_MS;
}
const uint32_t elapsed = _profile_visit_us - started;
if (elapsed > _profiles.longest_switch_us) _profiles.longest_switch_us = elapsed;
return applied ? mesh::RadioParamApplyResult::APPLIED : mesh::RadioParamApplyResult::FAILED;
@@ -361,7 +373,15 @@ void RadioLibWrapper::serviceProfileScan() {
_rx_ps_enabled = false;
_profile_rxps_suspended = true;
_nf_calib_active = false;
_noise_floor_valid = false; // a single-channel floor cannot describe both channels
// Each profile owns a floor. Start fresh, independent baselines so RSSI
// values from two frequencies are never blended into one estimate.
_noise_floor_valid = false;
_noise_floor_secondary_valid = false;
_nf_refresh_requested = true;
_nf_last_calib = 0;
_nf_calib_deadline = 0;
_floor_estimator.reset(true);
_secondary_floor_estimator.reset(true);
_profile_refresh_required = true; // refresh side detectors even if the tuple is unchanged
setProfileStandbyWarm(true);
endReconfigure(resume);
@@ -370,11 +390,32 @@ void RadioLibWrapper::serviceProfileScan() {
const bool restart_scan = _profiles.enabled()
&& (_profile_scan_generation[0] != _profiles.generation[0]
|| _profile_scan_generation[1] != _profiles.generation[1]);
if (restart_scan) {
// A profile changed while scanning. Discard both partial baselines before
// the first visit on the replacement tuples.
_noise_floor_valid = false;
_noise_floor_secondary_valid = false;
_nf_refresh_requested = true;
_nf_last_calib = 0;
_nf_calib_deadline = 0;
_floor_estimator.reset(true);
_secondary_floor_estimator.reset(true);
}
if (!_profiles.enabled()) target = 0;
else if (restart_scan) target = _profiles.slowerProfile();
else if ((uint32_t)(micros() - _profile_visit_us) >= _profiles.listenUs(
_active_profile, profilePreamble(_profiles.slowerProfile()))) {
target ^= 1;
else {
uint32_t visit_us = _profiles.listenUs(
_active_profile, profilePreamble(_profiles.slowerProfile()));
// A normal visit can be shorter than the RSSI settle interval on some
// chips. Hold only a visit that is actually due to contribute its next
// 50ms-spaced sample; very fast profiles otherwise retain their ordinary
// scan cadence throughout calibration.
const NoiseFloorEstimator& estimator = profileFloorEstimator(_active_profile);
if (_nf_refresh_requested && estimator.ready(static_cast<uint32_t>(millis()))
&& visit_us < NF_CALIB_SETTLE_MS * 1000UL) {
visit_us = NF_CALIB_SETTLE_MS * 1000UL;
}
if ((uint32_t)(micros() - _profile_visit_us) >= visit_us) target ^= 1;
}
const auto result = tuneProfile(target);
if (restart_scan && result == mesh::RadioParamApplyResult::APPLIED) {
@@ -466,9 +507,22 @@ void RadioLibWrapper::idle() {
void RadioLibWrapper::triggerNoiseFloorCalibrate(int threshold) {
_threshold = threshold;
// Calibration is independent of interference detection. Callers such as the
// Dispatcher and KISS modem use a zero threshold but still expect a fresh
// floor measurement on every scheduled request.
// The Dispatcher calls this every two seconds. Repeatedly recalibrating a
// dual-profile scanner would repeatedly lengthen its visits. Once both
// baselines are valid, retain them until a real RF-path change—except for a
// fast profile: it receives one new bounded 7 ms-visit sample set every
// fifteen minutes. Profiles already visiting for at least 7 ms need no
// artificial slowdown after their normal baseline.
if (_profiles.enabled() && _noise_floor_valid && _noise_floor_secondary_valid) {
const uint16_t preamble = profilePreamble(_profiles.slowerProfile());
const bool fast_profile = _profiles.listenUs(0, preamble) < NF_CALIB_SETTLE_MS * 1000UL
|| _profiles.listenUs(1, preamble) < NF_CALIB_SETTLE_MS * 1000UL;
if (fast_profile && _nf_last_calib != 0
&& (uint32_t)(millis() - _nf_last_calib) >= NF_FAST_PROFILE_REFRESH_INTERVAL_MS) {
requestNoiseFloorRefresh();
}
return;
}
requestNoiseFloorRefresh();
}
@@ -476,9 +530,11 @@ void RadioLibWrapper::recalibrateNoiseFloor() {
// A gain or tuning change starts a new baseline. Keep the published value
// available while discarding the old samples and rise-hold history.
_noise_floor_valid = false;
_noise_floor_secondary_valid = false;
_nf_refresh_requested = true;
_nf_last_calib = 0;
_floor_estimator.reset(true);
_secondary_floor_estimator.reset(true);
const unsigned long now = millis();
_nf_sample_from = now + NF_CALIB_SETTLE_MS;
@@ -497,6 +553,7 @@ void RadioLibWrapper::requestNoiseFloorRefresh() {
if (_nf_refresh_requested) return;
_nf_refresh_requested = true;
_floor_estimator.reset();
_secondary_floor_estimator.reset();
_nf_calib_deadline = 0; // starts when continuous RX is actually available
}
@@ -517,8 +574,10 @@ void RadioLibWrapper::resetAGC() {
// for LBT while the next spaced block is collected. Gain/tuning changes use
// recalibrateNoiseFloor() directly to seed a fresh baseline.
const bool previous_valid = _noise_floor_valid;
const bool previous_secondary_valid = _noise_floor_secondary_valid;
recalibrateNoiseFloor();
_noise_floor_valid = previous_valid;
_noise_floor_secondary_valid = previous_secondary_valid;
}
bool RadioLibWrapper::recoverRadio(bool hard) {
@@ -815,13 +874,69 @@ bool RadioLibWrapper::serviceCarrierWave() {
void RadioLibWrapper::loop() {
if (serviceCarrierWave()) return;
serviceProfileScan();
// Calibration batches need one stable channel. Do not publish a noise floor
// assembled from different frequencies, or let a batch pin the scan on one.
if (_profiles.enabled()) {
checkReceiveMode(static_cast<uint32_t>(millis()));
const unsigned long now = millis();
checkReceiveMode(static_cast<uint32_t>(now));
const bool restart_scan = _profile_scan_generation[0] != _profiles.generation[0]
|| _profile_scan_generation[1] != _profiles.generation[1];
if (!_profile_rxps_suspended || restart_scan) {
// Entering scan mode or changing a profile retunes before sampling. A
// sample from the previous physical tuple would be misleading.
serviceProfileScan();
return;
}
if (_nf_refresh_requested && _nf_calib_deadline == 0 && state == STATE_RX) {
_nf_calib_deadline = now + NF_CONTINUOUS_TIMEOUT_MS;
}
if (_nf_refresh_requested && _floor_estimator.complete()
&& _secondary_floor_estimator.complete()) {
if (_floor_estimator.publish(_noise_floor_centi_dbm, _noise_floor_valid)) {
_noise_floor_valid = true;
_noise_floor = (_noise_floor_centi_dbm - 50) / 100;
}
if (_secondary_floor_estimator.publish(_noise_floor_secondary_centi_dbm,
_noise_floor_secondary_valid)) {
_noise_floor_secondary_valid = true;
}
_nf_refresh_requested = false;
_nf_last_calib = now;
_nf_calib_deadline = 0;
MESH_DEBUG_PRINTLN("RadioLibWrapper: profile noise floors = %d, %d",
(int)_noise_floor,
(int)((_noise_floor_secondary_centi_dbm - 50) / 100));
} else if (_nf_refresh_requested && _nf_calib_deadline != 0
&& (long)(now - _nf_calib_deadline) >= 0) {
// Busy profile visits must not pin dual-profile scanning indefinitely.
_nf_refresh_requested = false;
_nf_last_calib = now;
_nf_calib_deadline = 0;
_floor_estimator.reset();
_secondary_floor_estimator.reset();
} else {
NoiseFloorEstimator& estimator = profileFloorEstimator(_active_profile);
if (_nf_refresh_requested && state == STATE_RX
&& !estimator.complete() && !_rx_ps_armed
&& estimator.ready(static_cast<uint32_t>(now))
&& !(_nf_sample_from != 0 && (long)(now - _nf_sample_from) < 0)
&& !isChipBusy() && !isPacketPendingOrReceiving()) {
// Preserve samples across visits, but never let one profile's RSSI
// contaminate the other profile's independent noise-floor estimate.
_nf_sample_from = now + NoiseFloorEstimator::SAMPLE_INTERVAL_MS;
if (readReceiveMode() == 0) {
estimator.reset(true);
} else if (!isPacketPendingOrReceiving()) {
estimator.add(getCurrentRSSI(), static_cast<uint32_t>(now));
}
}
}
// Sample before deciding whether to hop. serviceProfileScan() extends a
// short visit only when the active profile still needs a safe sample.
serviceProfileScan();
return;
}
serviceProfileScan();
if (_rx_ps_enabled && !_rx_ps_continuous_fallback) {
rxPsWatchdogCheck();
}
+56 -1
View File
@@ -33,12 +33,15 @@ protected:
uint32_t n_recv, n_sent, n_recv_errors;
int16_t _noise_floor, _threshold;
int32_t _noise_floor_centi_dbm;
int32_t _noise_floor_secondary_centi_dbm = 0;
float _last_rssi, _last_snr;
bool _cad_enabled;
uint32_t _cad_scan_timeout_override_ms;
bool _noise_floor_valid;
bool _noise_floor_secondary_valid = false;
bool _nf_refresh_requested;
NoiseFloorEstimator _floor_estimator;
NoiseFloorEstimator _secondary_floor_estimator;
uint32_t _rx_mode_checked_at = 0;
uint8_t _rx_mode_failures = 0;
unsigned long last_recv_millis;
@@ -101,6 +104,43 @@ protected:
unsigned long _nf_last_calib; // millis of last completed/attempted window
unsigned long _nf_calib_deadline; // abort window if the batch can't complete
unsigned long _nf_sample_from; // no samples before this (RX entry settle)
// The T096 SX1262 bench test found RSSI valid and stable by 7 ms after RX
// entry, including the 500 kHz/SF5 worst-case profile. Retain the
// conservative 20 ms path for the other radio families.
#if defined(USE_SX1262) || defined(USE_SX1268) || defined(USE_LLCC68)
static constexpr uint32_t NoiseFloorSettleMillis = 7UL;
#else
static constexpr uint32_t NoiseFloorSettleMillis = 20UL;
#endif
NoiseFloorEstimator& profileFloorEstimator(uint8_t profile) {
return profile == 1 ? _secondary_floor_estimator : _floor_estimator;
}
const NoiseFloorEstimator& profileFloorEstimator(uint8_t profile) const {
return profile == 1 ? _secondary_floor_estimator : _floor_estimator;
}
float profileNoiseFloorSecondsRemaining(uint8_t profile) const {
if (!isCalibratingNoiseFloor()) return 0.0f;
const NoiseFloorEstimator& estimator = profileFloorEstimator(profile);
if (!_profiles.enabled()) return estimator.secondsRemaining();
// Each profile receives one sample per complete scan cycle. The floor
// that belongs to a short visit may wait only as long as the chip family
// needs for RSSI settling; the UI must follow this true cadence.
const uint32_t preamble = profilePreamble(_profiles.slowerProfile());
uint32_t primary_visit = _profiles.listenUs(0, preamble);
uint32_t secondary_visit = _profiles.listenUs(1, preamble);
const uint32_t minimum_visit = NoiseFloorSettleMillis * 1000UL;
if (primary_visit < minimum_visit) primary_visit = minimum_visit;
if (secondary_visit < minimum_visit) secondary_visit = minimum_visit;
uint32_t switch_us = _profiles.longest_switch_us;
if (switch_us < mesh::RadioProfiles::SwitchBudgetUs) {
switch_us = mesh::RadioProfiles::SwitchBudgetUs;
}
const uint64_t cycle_us = uint64_t(primary_visit) + secondary_visit
+ 2ULL * switch_us + mesh::RadioProfiles::LoopBudgetUs;
return estimator.samplesRemaining() * (cycle_us / 1000000.0f);
}
static constexpr bool hasDirectRadioResetPin() {
#if defined(P_LORA_RESET)
@@ -270,6 +310,21 @@ public:
float getNoiseFloorDbm() const override {
return _noise_floor_centi_dbm / 100.0f;
}
float getNoiseFloorDbm(uint8_t profile) const override {
if (profile == 1 && _profiles.enabled()) {
return _noise_floor_secondary_centi_dbm / 100.0f;
}
return getNoiseFloorDbm();
}
float getNoiseFloorCalibrationSecondsRemaining() const override {
const float primary = profileNoiseFloorSecondsRemaining(0);
if (!_profiles.enabled()) return primary;
const float secondary = profileNoiseFloorSecondsRemaining(1);
return primary > secondary ? primary : secondary;
}
float getNoiseFloorCalibrationSecondsRemaining(uint8_t profile) const override {
return profileNoiseFloorSecondsRemaining(profile);
}
void triggerNoiseFloorCalibrate(int threshold) override;
void recalibrateNoiseFloor() override;
void setCADEnabled(bool enable) override { _cad_enabled = enable; }
@@ -300,7 +355,7 @@ public:
bool isWatchdogObserving() const { return _wd_observe_until != 0; }
// true while a noise-floor batch needs prompt loop service; the app's
// hasPendingWork() keeps the MCU awake for the bounded spaced-sample window.
bool isCalibratingNoiseFloor() const {
bool isCalibratingNoiseFloor() const override {
return _nf_calib_active
|| (_nf_refresh_requested
&& (!_rx_ps_enabled || _rx_ps_continuous_fallback));
+10
View File
@@ -168,6 +168,16 @@ public:
BoundedTextRows(DisplayDriver& d, const DisplayRegion& r, int spacing = 2)
: display(d), region(r), next_y(r.y), gap(spacing) {}
int nextY() const { return next_y; }
bool reserve() {
const int height = display.textLineHeight();
if (height <= 0 || !displayRegionContainsLine(region, next_y, height))
return false;
next_y += height + gap;
return true;
}
bool draw(const char* text, bool centered = true) {
const int height = display.textLineHeight();
if (height <= 0 || !displayRegionContainsLine(region, next_y, height))
+16 -2
View File
@@ -241,7 +241,9 @@ struct Context {
float freq;
uint8_t sf;
float bw;
const char* radio_label; // "" for the sole/default profile, otherwise R1/R2/T1/T2
bool link_up;
bool dual_radio;
};
struct RowText {
@@ -316,7 +318,11 @@ inline void composeRow(Row row, const Context& ctx, const RadioActivitySnapshot&
formatAge(scratch, sizeof(scratch), s.last_packet_age_ms, s.has_last_packet);
snprintf(out->left, sizeof(out->left), "RX %s", scratch);
out->left_color = s.has_last_packet ? TEXT : MUTED;
snprintf(out->right, sizeof(out->right), ctx.link_up ? "WiFi OK" : "WiFi --");
if (ctx.dual_radio) {
snprintf(out->right, sizeof(out->right), ctx.link_up ? "WiFi OK R2 ON" : "WiFi -- R2 ON");
} else {
snprintf(out->right, sizeof(out->right), ctx.link_up ? "WiFi OK" : "WiFi --");
}
out->right_color = ctx.link_up ? GOOD : WARN;
break;
@@ -485,7 +491,15 @@ inline void drawHeader(DisplayDriver& d, const Layout& l, const Context& ctx) {
inline void drawRadioStrip(DisplayDriver& d, const Layout& l, const Context& ctx) {
char tmp[32];
formatRadioStrip(tmp, sizeof(tmp), ctx.freq, ctx.sf, ctx.bw);
char params[32];
formatRadioStrip(params, sizeof(params), ctx.freq, ctx.sf, ctx.bw);
if (ctx.radio_label && ctx.radio_label[0]) {
// Tags are R1/R2/T1/T2. Bounds keep this header-only layout safe even if
// a future caller supplies a longer diagnostic label.
snprintf(tmp, sizeof(tmp), "%.3s %.27s", ctx.radio_label, params);
} else {
snprintf(tmp, sizeof(tmp), "%s", params);
}
char fitted[32];
fitToChars(fitted, sizeof(fitted), tmp, l.max_chars);
d.setTextSize(1);
+93
View File
@@ -0,0 +1,93 @@
#pragma once
#include <stdint.h>
namespace mesh { namespace ui {
// Keep each configured radio profile visible long enough to read, while still
// fitting both into the normal short display wake interval.
constexpr uint32_t RADIO_PROFILE_DISPLAY_PAGE_MILLIS = 7000;
// The ordinary repeater home page needs two RF pages when radio2 is active.
// Compact panels use the following page(s) for the settings that do not fit
// beside F/B/S/C. The caller supplies the number of status pages required by
// its measured font height and display height.
inline uint8_t radioProfileDisplayPageCount(bool dual_radio_enabled,
uint8_t status_page_count) {
return (dual_radio_enabled ? 2 : 1) + status_page_count;
}
inline uint8_t radioProfileDisplayPageIndex(bool dual_radio_enabled,
uint8_t status_page_count,
uint32_t elapsed_millis) {
const uint8_t page_count = radioProfileDisplayPageCount(
dual_radio_enabled, status_page_count);
return page_count == 0 ? 0
: (elapsed_millis / RADIO_PROFILE_DISPLAY_PAGE_MILLIS) % page_count;
}
// Repeater screens advance these pages with a physical button. Keeping the
// manual helpers alongside the timed compatibility helpers makes it explicit
// that a button press, rather than a timeout, owns the selected profile.
inline uint8_t radioProfileManualPageIndex(bool dual_radio_enabled,
uint8_t status_page_count,
uint8_t selected_page) {
const uint8_t page_count = radioProfileDisplayPageCount(
dual_radio_enabled, status_page_count);
return page_count == 0 ? 0 : selected_page % page_count;
}
inline bool showRadioProfileSystemStatusPage(bool dual_radio_enabled,
uint8_t status_page_count,
uint32_t elapsed_millis,
uint8_t* status_page_index = nullptr) {
const uint8_t radio_page_count = dual_radio_enabled ? 2 : 1;
const uint8_t page_index = radioProfileDisplayPageIndex(
dual_radio_enabled, status_page_count, elapsed_millis);
const bool is_status_page = status_page_count != 0
&& page_index >= radio_page_count;
if (status_page_index != nullptr) {
*status_page_index = is_status_page ? page_index - radio_page_count : 0;
}
return is_status_page;
}
inline bool showManualRadioProfileSystemStatusPage(bool dual_radio_enabled,
uint8_t status_page_count,
uint8_t selected_page,
uint8_t* status_page_index = nullptr) {
const uint8_t radio_page_count = dual_radio_enabled ? 2 : 1;
const uint8_t page_index = radioProfileManualPageIndex(
dual_radio_enabled, status_page_count, selected_page);
const bool is_status_page = status_page_count != 0
&& page_index >= radio_page_count;
if (status_page_index != nullptr) {
*status_page_index = is_status_page ? page_index - radio_page_count : 0;
}
return is_status_page;
}
inline bool showSecondaryRadioProfilePage(bool dual_radio_enabled,
uint8_t status_page_count,
uint32_t elapsed_millis) {
return dual_radio_enabled && radioProfileDisplayPageIndex(
dual_radio_enabled, status_page_count, elapsed_millis) == 1;
}
inline bool showManualSecondaryRadioProfilePage(bool dual_radio_enabled,
uint8_t selected_page) {
return dual_radio_enabled && selected_page == 1;
}
inline bool showSecondaryRadioProfilePage(bool dual_radio_enabled,
uint32_t elapsed_millis) {
return dual_radio_enabled
&& ((elapsed_millis / RADIO_PROFILE_DISPLAY_PAGE_MILLIS) & 1U) != 0;
}
inline const char* radioProfileDisplayTag(bool secondary, bool temporary) {
if (secondary) return temporary ? "T2" : "R2";
return temporary ? "T1" : "R1";
}
} } // namespace mesh::ui
+252
View File
@@ -0,0 +1,252 @@
#pragma once
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <RadioProfiles.h>
#include <helpers/ui/DisplayDriver.h>
#include <helpers/ui/RadioProfileDisplayPage.h>
namespace mesh { namespace ui {
// A compact, paged rendering of the radio/system state shared by the role
// UIs. Keeping the rows discrete lets a 72x40 screen page them safely while
// a 128x64 panel uses only two status pages.
struct RadioProfileSystemStatus {
const uint8_t* public_key = nullptr;
bool powersaving_enabled = false;
bool gps_enabled = false;
bool fem_enabled = false;
bool rx_boosted_gain = false;
bool rx_powersaving_enabled = false;
bool cad_enabled = false;
bool dual_radio_enabled = false;
bool secondary_temporary = false;
RadioProfileMode secondary_mode = RadioProfileMode::Rx;
RadioCrossMode cross = RadioCrossMode::Auto;
float noise_floor_1 = 0.0f;
float noise_floor_2 = 0.0f;
float noise_floor_1_seconds = 0.0f;
float noise_floor_2_seconds = 0.0f;
};
inline uint8_t radioProfileSystemStatusRowCount(bool dual_radio_enabled,
bool narrow = false) {
// ID, PS/GPS, FEM/RXB, RXPS/CAD, N1, plus R2 mode, cross, and N2.
// Narrow panels cannot fit a state pair on one line, so each switch gets
// its own row instead of clipping the right-hand state.
if (narrow) return dual_radio_enabled ? 11 : 8;
return dual_radio_enabled ? 8 : 5;
}
inline uint8_t radioProfileSystemStatusRowsPerPage(
DisplayDriver& display, int top = 0) {
const int line_height = display.textLineHeight();
if (line_height <= 0 || top >= display.height()) return 1;
const int row_height = line_height + 2;
const int rows = (display.height() - top + 2) / row_height;
return rows > 0 ? rows : 1;
}
inline uint8_t radioProfileSystemStatusPageCount(
DisplayDriver& display, bool dual_radio_enabled, int top = 0) {
const uint8_t rows = radioProfileSystemStatusRowsPerPage(display, top);
const uint8_t count = radioProfileSystemStatusRowCount(
dual_radio_enabled, display.width() < 104);
return (count + rows - 1) / rows;
}
inline int drawRadioProfileStatusState(DisplayDriver& display, int x, int y,
const char* label, bool enabled) {
const char* state = enabled ? "ON" : "OFF";
display.setColor(UIColor::primary_txt);
display.setCursor(x, y);
display.print(label);
x += display.getTextWidth(label);
display.setColor(enabled ? UIColor::primary_txt : UIColor::warning_txt);
display.setCursor(x, y);
display.print(state);
return x + display.getTextWidth(state);
}
inline void drawRadioProfileStatusPair(DisplayDriver& display, int y,
const char* first_label,
bool first_enabled,
const char* second_label,
bool second_enabled) {
const int x = drawRadioProfileStatusState(display, 0, y, first_label,
first_enabled);
drawRadioProfileStatusState(display, x + display.getTextWidth(" "), y,
second_label, second_enabled);
display.setColor(UIColor::primary_txt);
}
inline void formatRadioProfileNoiseFloor(char* buffer, size_t size,
const char* label, float dbm,
float seconds_remaining) {
if (dbm != 0.0f) {
snprintf(buffer, size, "%s:%.1f", label, dbm);
} else if (seconds_remaining > 0.0f) {
snprintf(buffer, size, "%s:%.1fs", label, seconds_remaining);
} else {
snprintf(buffer, size, "%s:WAIT", label);
}
}
inline void drawRadioProfileSystemStatusPage(
DisplayDriver& display, const RadioProfileSystemStatus& status,
uint8_t page_index, int top = 0) {
display.setTextSize(1);
const uint8_t rows_per_page = radioProfileSystemStatusRowsPerPage(display,
top);
const uint8_t first_row = page_index * rows_per_page;
// The widest paired row (RXPS/CAD) occupies 102 pixels in the standard
// six-pixel font, so 96-pixel panels must use the narrow layout too.
const bool narrow = display.width() < 104;
const uint8_t row_count = radioProfileSystemStatusRowCount(
status.dual_radio_enabled, narrow);
const int row_height = display.textLineHeight() + 2;
for (uint8_t row = first_row; row < row_count
&& row < first_row + rows_per_page; ++row) {
const int y = top + (row - first_row) * row_height;
if (narrow) {
if (row == 0) {
char identity[10] = "ID:------";
if (status.public_key != nullptr) {
snprintf(identity, sizeof(identity), "ID:%02X%02X%02X",
status.public_key[0], status.public_key[1],
status.public_key[2]);
}
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(identity);
} else if (row == 1) {
drawRadioProfileStatusState(display, 0, y, "PS:",
status.powersaving_enabled);
} else if (row == 2) {
drawRadioProfileStatusState(display, 0, y, "GPS:",
status.gps_enabled);
} else if (row == 3) {
drawRadioProfileStatusState(display, 0, y, "FEM:",
status.fem_enabled);
} else if (row == 4) {
drawRadioProfileStatusState(display, 0, y, "RXB:",
status.rx_boosted_gain);
} else if (row == 5) {
drawRadioProfileStatusState(display, 0, y, "RXPS:",
status.rx_powersaving_enabled);
} else if (row == 6) {
drawRadioProfileStatusState(display, 0, y, "CAD:",
status.cad_enabled);
} else if (status.dual_radio_enabled && row == 7) {
char mode[12];
snprintf(mode, sizeof(mode), "%s:%s",
radioProfileDisplayTag(true, status.secondary_temporary),
status.secondary_mode == RadioProfileMode::RxTx ? "RXTX"
: "RX");
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(mode);
} else if (status.dual_radio_enabled && row == 8) {
const char* cross = status.cross == RadioCrossMode::On ? "X:ON"
: status.cross == RadioCrossMode::Off ? "X:OFF" : "X:AUTO";
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(cross);
} else {
const bool second_noise = status.dual_radio_enabled && row == 10;
char noise[12];
formatRadioProfileNoiseFloor(noise, sizeof(noise),
second_noise ? "N2" : "N1",
second_noise ? status.noise_floor_2 : status.noise_floor_1,
second_noise ? status.noise_floor_2_seconds
: status.noise_floor_1_seconds);
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(noise);
}
continue;
}
switch (row) {
case 0: {
char identity[10] = "ID:------";
if (status.public_key != nullptr) {
snprintf(identity, sizeof(identity), "ID:%02X%02X%02X",
status.public_key[0], status.public_key[1],
status.public_key[2]);
}
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(identity);
break;
}
case 1:
drawRadioProfileStatusPair(display, y, "PS:",
status.powersaving_enabled, "GPS:",
status.gps_enabled);
break;
case 2:
drawRadioProfileStatusPair(display, y, "FEM:", status.fem_enabled,
"RXB:", status.rx_boosted_gain);
break;
case 3:
drawRadioProfileStatusPair(display, y, "RXPS:",
status.rx_powersaving_enabled, "CAD:",
status.cad_enabled);
break;
case 4:
if (status.dual_radio_enabled) {
char mode[12];
snprintf(mode, sizeof(mode), "%s:%s",
radioProfileDisplayTag(true, status.secondary_temporary),
status.secondary_mode == RadioProfileMode::RxTx ? "RXTX"
: "RX");
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(mode);
} else {
char noise[12];
formatRadioProfileNoiseFloor(noise, sizeof(noise), "N1",
status.noise_floor_1,
status.noise_floor_1_seconds);
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(noise);
}
break;
case 5: {
const char* cross = status.cross == RadioCrossMode::On ? "X:ON"
: status.cross == RadioCrossMode::Off ? "X:OFF" : "X:AUTO";
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(cross);
break;
}
case 6: {
char noise[12];
formatRadioProfileNoiseFloor(noise, sizeof(noise), "N1",
status.noise_floor_1,
status.noise_floor_1_seconds);
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(noise);
break;
}
case 7: {
char noise[12];
formatRadioProfileNoiseFloor(noise, sizeof(noise), "N2",
status.noise_floor_2,
status.noise_floor_2_seconds);
display.setColor(UIColor::primary_txt);
display.setCursor(0, y);
display.print(noise);
break;
}
}
}
display.setColor(UIColor::primary_txt);
}
} } // namespace mesh::ui