feat(ui): page radio and system status
This commit is contained in:
1 parent
527bc98da2
commit
a95f7b3d16
28 files changed
+2075
-73
No files matched your search
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in new issue
Block a user