ui: repeater discover screen

This commit is contained in:
Florent
2026-08-21 18:24:46 -04:00
parent e749010bbc
commit 52f0362c09
3 changed files with 120 additions and 1 deletions
+52 -1
View File
@@ -24,6 +24,7 @@
#define LONG_PRESS_MILLIS 1200
// Used both for recent adverts and discovered nodes
#ifndef UI_RECENT_LIST_SIZE
#define UI_RECENT_LIST_SIZE 4
#endif
@@ -102,6 +103,7 @@ class HomeScreen : public UIScreen {
#if UI_SENSORS_PAGE == 1
SENSORS,
#endif
DISCOVERY,
SHUTDOWN,
Count // keep as last
};
@@ -113,7 +115,9 @@ class HomeScreen : public UIScreen {
uint8_t _page;
bool _shutdown_init;
AdvertPath recent[UI_RECENT_LIST_SIZE];
DiscoveredNode discovered[UI_RECENT_LIST_SIZE];
uint32_t discovery_req_time = 0;
bool discovery_disp_names = true; // by default desplay names if available (removes SNR_O)
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
// Convert millivolts to percentage
@@ -459,6 +463,39 @@ public:
if (sensors_scroll) sensors_scroll_offset = (sensors_scroll_offset+1)%sensors_nb;
else sensors_scroll_offset = 0;
#endif
} else if (_page == HomePage::DISCOVERY) {
int count = the_mesh.getDiscoveredNodes(discovered, UI_RECENT_LIST_SIZE);
display.setColor(UIColor::primary_txt);
int y = 20;
for (int i = 0; i < count; i++, y += 11) {
char name[32];
auto a = &discovered[i];
if ((a->name[0] == 0) || !discovery_disp_names) {
mesh::Utils::toHex(name, a->pubkey_prefix, 4);
} else {
strncpy(name, a->name, 32);
}
char filtered_name[sizeof(name)];
char snr_s[12];
if (strlen(name) <= 8) { // display snr_o
sprintf(snr_s, "%02.1f>%02.1f", a->snr_out, a->snr_in);
} else {
sprintf(snr_s, "%02.1f", a->snr_in);
}
int snr_width = display.getTextWidth(snr_s);
int max_name_width = display.width() - snr_width - 1;
display.translateUTF8ToBlocks(filtered_name, name, sizeof(filtered_name));
display.drawTextEllipsized(0, y, max_name_width, filtered_name);
display.setCursor(display.width() - snr_width - 1, y);
display.print(snr_s);
}
if (millis() < discovery_req_time + 5000) {
return 1000; // more frequent updates just after req
} else if (count < UI_RECENT_LIST_SIZE -1) { // show only 5 sec after last disc
y = 10 + 11 * UI_RECENT_LIST_SIZE;
display.drawTextCentered(display.width() / 2, y, "discover: " PRESS_LABEL);
}
} else if (_page == HomePage::SHUTDOWN) {
display.setColor(UIColor::corp_blue);
display.setTextSize(1);
@@ -484,6 +521,9 @@ public:
if (_page == HomePage::RECENT) {
_task->showAlert("Recent adverts", 800);
}
if (_page == HomePage::DISCOVERY) {
_task->showAlert("Repeater disc", 800);
}
return true;
}
if (c == KEY_ENTER && _page == HomePage::BLUETOOTH) {
@@ -516,6 +556,17 @@ public:
return true;
}
#endif
if (c == KEY_ENTER && _page == HomePage::DISCOVERY) {
if (millis() > discovery_req_time + 5000) { // rate limiter
the_mesh.requestRepeatersDiscovery();
discovery_req_time = millis();
}
return true;
}
if (c == KEY_SELECT && _page == HomePage::DISCOVERY) {
discovery_disp_names = !discovery_disp_names;
return true;
}
if (c == KEY_ENTER && _page == HomePage::SHUTDOWN) {
_shutdown_init = true; // need to wait for button to be released
return true;