feat(ui): page radio and system status
This commit is contained in:
1 parent
653578c818
commit
b089b745fa
28 files changed
+2075
-73
No files matched your search
@@ -12,6 +12,9 @@
|
||||
#include <helpers/ui/SmallMessageText.h>
|
||||
#endif
|
||||
#include <helpers/ui/CompanionTransportSelectorLayout.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <helpers/ui/RadioProfileSystemStatus.h>
|
||||
#include <RadioProfiles.h>
|
||||
#include "../MyMesh.h"
|
||||
#include "../CompanionWiFi.h"
|
||||
#include "target.h"
|
||||
@@ -66,6 +69,38 @@ static uint64_t companionMessageElapsedMillis(uint64_t heard_millis) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static mesh::ui::RadioProfileSystemStatus radioProfileSystemStatus(
|
||||
const CompanionNodePrefs& prefs) {
|
||||
mesh::ui::RadioProfileSystemStatus status;
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const mesh::RadioProfiles* profiles = radio ? radio->profiles() : NULL;
|
||||
status.public_key = the_mesh.self_id.pub_key;
|
||||
status.powersaving_enabled = prefs.powersaving_enabled != 0;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
status.gps_enabled = prefs.gps_enabled != 0;
|
||||
#endif
|
||||
status.fem_enabled = board.canControlLoRaFemLna()
|
||||
&& board.isLoRaFemLnaEnabled();
|
||||
status.rx_boosted_gain = prefs.rx_boosted_gain != 0;
|
||||
status.rx_powersaving_enabled = prefs.rx_powersaving_enabled != 0;
|
||||
status.cad_enabled = prefs.cad_enabled != 0;
|
||||
status.dual_radio_enabled = profiles != NULL && profiles->enabled();
|
||||
if (status.dual_radio_enabled) {
|
||||
status.secondary_temporary = profiles->secondary_temporary;
|
||||
status.secondary_mode = profiles->secondary.mode;
|
||||
status.cross = profiles->cross;
|
||||
}
|
||||
status.noise_floor_1 = radio_driver.getNoiseFloorDbm(0);
|
||||
status.noise_floor_1_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(0);
|
||||
if (status.dual_radio_enabled) {
|
||||
status.noise_floor_2 = radio_driver.getNoiseFloorDbm(1);
|
||||
status.noise_floor_2_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
#ifndef UI_RECENT_LIST_SIZE
|
||||
#define UI_RECENT_LIST_SIZE 4
|
||||
#endif
|
||||
@@ -421,6 +456,8 @@ class HomeScreen : public UIScreen {
|
||||
#endif
|
||||
uint32_t _uptime_last_millis;
|
||||
uint64_t _uptime_millis;
|
||||
uint32_t _radio_profile_page_started_at = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||
#if !(defined(UI_NO_DISCOVER_SCREEN) && (UI_NO_DISCOVER_SCREEN + 0 != 0))
|
||||
DiscoveredNode discovered[UI_RECENT_LIST_SIZE];
|
||||
@@ -558,6 +595,35 @@ class HomeScreen : public UIScreen {
|
||||
}
|
||||
}
|
||||
|
||||
void resetRadioProfileDisplayPage() {
|
||||
_radio_profile_page_started_at = millis();
|
||||
_dual_radio_enabled_seen = the_mesh.isDualRadioActive();
|
||||
}
|
||||
|
||||
bool showingSecondaryRadioProfilePage(DisplayDriver& display,
|
||||
int status_top) {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint32_t now = millis();
|
||||
if (dual_radio_enabled != _dual_radio_enabled_seen) {
|
||||
_dual_radio_enabled_seen = dual_radio_enabled;
|
||||
_radio_profile_page_started_at = now;
|
||||
}
|
||||
display.setTextSize(1);
|
||||
const uint8_t status_pages = mesh::ui::radioProfileSystemStatusPageCount(
|
||||
display, dual_radio_enabled, status_top);
|
||||
return mesh::ui::showSecondaryRadioProfilePage(dual_radio_enabled,
|
||||
status_pages,
|
||||
now - _radio_profile_page_started_at);
|
||||
}
|
||||
|
||||
int radioProfileRefreshMillis() const {
|
||||
const uint32_t elapsed = millis() - _radio_profile_page_started_at;
|
||||
const uint32_t remaining = mesh::ui::RADIO_PROFILE_DISPLAY_PAGE_MILLIS
|
||||
- elapsed % mesh::ui::RADIO_PROFILE_DISPLAY_PAGE_MILLIS;
|
||||
return remaining < UI_RADIO_REFRESH_MILLIS ? (int)remaining
|
||||
: UI_RADIO_REFRESH_MILLIS;
|
||||
}
|
||||
|
||||
public:
|
||||
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, CompanionNodePrefs* node_prefs)
|
||||
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
|
||||
@@ -893,13 +959,50 @@ public:
|
||||
} else if (_page == HomePage::RADIO) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setTextSize(1);
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const mesh::RadioProfiles* profiles = radio ? radio->profiles() : NULL;
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
const uint8_t status_pages = mesh::ui::radioProfileSystemStatusPageCount(
|
||||
display, dual_radio, body_top);
|
||||
uint8_t status_page_index = 0;
|
||||
if (mesh::ui::showRadioProfileSystemStatusPage(dual_radio, status_pages,
|
||||
millis() - _radio_profile_page_started_at, &status_page_index)) {
|
||||
mesh::ui::drawRadioProfileSystemStatusPage(display,
|
||||
radioProfileSystemStatus(*_node_prefs), status_page_index, body_top);
|
||||
return radioProfileRefreshMillis();
|
||||
}
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage(display,
|
||||
body_top);
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
const char* profile_tag = "";
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
profile_tag = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
// freq / sf
|
||||
display.setCursor(0, body_top);
|
||||
sprintf(tmp, "FQ: %06.3f SF: %d", _node_prefs->freq, _node_prefs->sf);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s F:%06.3f S:%d", profile_tag, freq, sf);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "FQ: %06.3f SF: %d", freq, sf);
|
||||
}
|
||||
display.print(tmp);
|
||||
|
||||
display.setCursor(0, body_top + row_height);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s B:%03.2f C:%d", profile_tag, bw, cr);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
}
|
||||
display.print(tmp);
|
||||
|
||||
// tx power, noise floor
|
||||
@@ -907,11 +1010,23 @@ public:
|
||||
sprintf(tmp, "TX: %ddBm", _node_prefs->tx_power_dbm);
|
||||
display.print(tmp);
|
||||
display.setCursor(0, body_top + 3 * row_height);
|
||||
float noise_floor = radio_driver.getNoiseFloorDbm();
|
||||
// The RF rows above can be showing R1 or R2. Read the matching
|
||||
// estimator too; otherwise an R2-labelled page silently showed R1's
|
||||
// noise floor.
|
||||
const uint8_t noise_profile = dual_radio && secondary_page ? 1 : 0;
|
||||
const char* noise_label = dual_radio
|
||||
? (noise_profile == 0 ? "N1" : "N2") : "Noise floor";
|
||||
float noise_floor = radio_driver.getNoiseFloorDbm(noise_profile);
|
||||
if (noise_floor == 0.0f) {
|
||||
strcpy(tmp, "Noise floor: measuring");
|
||||
const float seconds = radio_driver
|
||||
.getNoiseFloorCalibrationSecondsRemaining(noise_profile);
|
||||
if (seconds > 0.0f) {
|
||||
snprintf(tmp, sizeof(tmp), "%s: %.1fs", noise_label, seconds);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%s: WAIT", noise_label);
|
||||
}
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "Noise floor: %.1f", noise_floor);
|
||||
snprintf(tmp, sizeof(tmp), "%s: %.1f", noise_label, noise_floor);
|
||||
}
|
||||
display.print(tmp);
|
||||
#ifdef COMPANION_EXCLUSIVE_WIFI_BLE
|
||||
@@ -1152,7 +1267,7 @@ public:
|
||||
}
|
||||
#endif
|
||||
}
|
||||
if (_page == HomePage::RADIO) return UI_RADIO_REFRESH_MILLIS;
|
||||
if (_page == HomePage::RADIO) return radioProfileRefreshMillis();
|
||||
#if UI_MESSAGES_HOME_PAGE == 1
|
||||
if (_page == HomePage::MESSAGES) return 1000;
|
||||
#endif
|
||||
@@ -1167,6 +1282,7 @@ public:
|
||||
const uint8_t key = static_cast<uint8_t>(c);
|
||||
if (key == KEY_LEFT || key == KEY_PREV) {
|
||||
_page = (_page + HomePage::Count - 1) % HomePage::Count;
|
||||
if (_page == HomePage::RADIO) resetRadioProfileDisplayPage();
|
||||
return true;
|
||||
}
|
||||
#if COMPANION_FEATURE_READER
|
||||
@@ -1177,6 +1293,7 @@ public:
|
||||
#endif
|
||||
if (key == KEY_NEXT || key == KEY_RIGHT) {
|
||||
_page = (_page + 1) % HomePage::Count;
|
||||
if (_page == HomePage::RADIO) resetRadioProfileDisplayPage();
|
||||
if (_page == HomePage::RECENT) {
|
||||
_task->showAlert("Recent adverts", 800);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
#include <Arduino.h>
|
||||
#include <helpers/TxtDataHelpers.h>
|
||||
#include <helpers/ui/BluetoothPairingUiPolicy.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <helpers/ui/RadioProfileSystemStatus.h>
|
||||
#include <RadioProfiles.h>
|
||||
#include "../MyMesh.h"
|
||||
|
||||
#define AUTO_OFF_MILLIS 15000 // 15 seconds
|
||||
@@ -30,6 +33,49 @@
|
||||
#define USER_BTN_PRESSED LOW
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
mesh::ui::RadioProfileSystemStatus radioProfileSystemStatus(
|
||||
const CompanionNodePrefs& prefs, const mesh::MainBoard& board) {
|
||||
mesh::ui::RadioProfileSystemStatus status;
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const mesh::RadioProfiles* profiles = radio ? radio->profiles() : NULL;
|
||||
status.public_key = the_mesh.self_id.pub_key;
|
||||
status.powersaving_enabled = prefs.powersaving_enabled != 0;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
status.gps_enabled = prefs.gps_enabled != 0;
|
||||
#endif
|
||||
status.fem_enabled = board.canControlLoRaFemLna()
|
||||
&& board.isLoRaFemLnaEnabled();
|
||||
status.rx_boosted_gain = prefs.rx_boosted_gain != 0;
|
||||
status.rx_powersaving_enabled = prefs.rx_powersaving_enabled != 0;
|
||||
status.cad_enabled = prefs.cad_enabled != 0;
|
||||
status.dual_radio_enabled = profiles != NULL && profiles->enabled();
|
||||
if (status.dual_radio_enabled) {
|
||||
status.secondary_temporary = profiles->secondary_temporary;
|
||||
status.secondary_mode = profiles->secondary.mode;
|
||||
status.cross = profiles->cross;
|
||||
}
|
||||
status.noise_floor_1 = radio_driver.getNoiseFloorDbm(0);
|
||||
status.noise_floor_1_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(0);
|
||||
if (status.dual_radio_enabled) {
|
||||
status.noise_floor_2 = radio_driver.getNoiseFloorDbm(1);
|
||||
status.noise_floor_2_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t radioProfileStatusPageCount(DisplayDriver& display,
|
||||
bool dual_radio_enabled) {
|
||||
display.setTextSize(1);
|
||||
return mesh::ui::radioProfileSystemStatusPageCount(display,
|
||||
dual_radio_enabled);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// 'meshcore', 128x13px
|
||||
static const uint8_t meshcore_logo [] PROGMEM = {
|
||||
0x3c, 0x01, 0xe3, 0xff, 0xc7, 0xff, 0x8f, 0x03, 0x87, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe, 0x1f, 0xfe,
|
||||
@@ -56,6 +102,7 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
|
||||
clearMsgPreview();
|
||||
_node_prefs = node_prefs;
|
||||
resetRadioProfileDisplayPage();
|
||||
if (_display != NULL) {
|
||||
_display->servicePower(_board->isExternalPowered() || _board->isUsbHostConnected(), hasConnection());
|
||||
}
|
||||
@@ -112,6 +159,39 @@ void UITask::begin(DisplayDriver* display, SensorManager* sensors, CompanionNode
|
||||
ui_started_at = millis();
|
||||
}
|
||||
|
||||
void UITask::resetRadioProfileDisplayPage() {
|
||||
_radio_profile_page_started_at = millis();
|
||||
_dual_radio_enabled_seen = the_mesh.isDualRadioActive();
|
||||
_radio_profile_display_page_seen = 0;
|
||||
}
|
||||
|
||||
bool UITask::showingSecondaryRadioProfilePage() {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint32_t now = millis();
|
||||
if (dual_radio_enabled != _dual_radio_enabled_seen) {
|
||||
_dual_radio_enabled_seen = dual_radio_enabled;
|
||||
_radio_profile_page_started_at = now;
|
||||
}
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(*_display,
|
||||
dual_radio_enabled);
|
||||
return mesh::ui::showSecondaryRadioProfilePage(dual_radio_enabled,
|
||||
status_pages,
|
||||
now - _radio_profile_page_started_at);
|
||||
}
|
||||
|
||||
void UITask::serviceRadioProfileDisplayPage() {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(*_display,
|
||||
dual_radio_enabled);
|
||||
const uint8_t page = mesh::ui::radioProfileDisplayPageIndex(
|
||||
dual_radio_enabled, status_pages,
|
||||
millis() - _radio_profile_page_started_at);
|
||||
if (page != _radio_profile_display_page_seen) {
|
||||
_radio_profile_display_page_seen = page;
|
||||
_need_refresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool UITask::shouldPlayMessageTone() const {
|
||||
#ifdef BLE_PIN_CODE
|
||||
return !hasBluetoothConnection();
|
||||
@@ -272,6 +352,18 @@ void UITask::renderCurrScreen() {
|
||||
_display->setCursor((_display->width() - textWidth) / 2, 22);
|
||||
_display->print(_version_info);
|
||||
} else { // home screen
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(
|
||||
*_display, dual_radio_enabled);
|
||||
uint8_t status_page_index = 0;
|
||||
if (mesh::ui::showRadioProfileSystemStatusPage(dual_radio_enabled,
|
||||
status_pages, millis() - _radio_profile_page_started_at,
|
||||
&status_page_index)) {
|
||||
mesh::ui::drawRadioProfileSystemStatusPage(*_display,
|
||||
radioProfileSystemStatus(*_node_prefs, *_board), status_page_index);
|
||||
_need_refresh = false;
|
||||
return;
|
||||
}
|
||||
// node name
|
||||
_display->setCursor(0, 0);
|
||||
_display->setTextSize(1);
|
||||
@@ -281,15 +373,42 @@ void UITask::renderCurrScreen() {
|
||||
// battery voltage
|
||||
renderBatteryIndicator(_board->getBattMilliVolts());
|
||||
|
||||
// freq / sf
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const mesh::RadioProfiles* profiles = radio ? radio->profiles() : NULL;
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
const char* profile_tag = "";
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
profile_tag = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
|
||||
// Compact R1/R2 rows preserve every RF field on 128px displays.
|
||||
_display->setCursor(0, 20);
|
||||
_display->setColor(UIColor::secondary_txt);
|
||||
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s F:%06.3f S:%d", profile_tag, freq, sf);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", freq, sf);
|
||||
}
|
||||
_display->print(tmp);
|
||||
|
||||
// bw / cr
|
||||
_display->setCursor(0, 30);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s B:%03.2f C:%d", profile_tag, bw, cr);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
}
|
||||
_display->print(tmp);
|
||||
|
||||
// BT pin
|
||||
@@ -538,6 +657,10 @@ void UITask::loop() {
|
||||
#endif
|
||||
|
||||
if (_display != NULL && _display->isOn()) {
|
||||
if (!isPairingScreenActive() && !_alert[0] && !(_origin[0] && _msg[0])
|
||||
&& (millis() - ui_started_at) >= BOOT_SCREEN_MILLIS) {
|
||||
serviceRadioProfileDisplayPage();
|
||||
}
|
||||
static bool _firstBoot = true;
|
||||
if(_firstBoot && (millis() - ui_started_at) >= BOOT_SCREEN_MILLIS) {
|
||||
_need_refresh = true;
|
||||
@@ -560,6 +683,7 @@ void UITask::handleButtonAnyPress() {
|
||||
if (_display != NULL) {
|
||||
_displayWasOn = _display->isOn(); // Track display state before any action
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
if (!_displayWasOn) resetRadioProfileDisplayPage();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ class UITask : public AbstractUITask {
|
||||
bool _displayWasOn = false; // Track display state before button press
|
||||
unsigned long _pairing_screen_until;
|
||||
unsigned long ui_started_at;
|
||||
uint32_t _radio_profile_page_started_at = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
uint8_t _radio_profile_display_page_seen = 0;
|
||||
|
||||
// Button handlers
|
||||
#ifdef PIN_USER_BTN
|
||||
@@ -64,6 +67,9 @@ class UITask : public AbstractUITask {
|
||||
void handleButtonLongPress();
|
||||
bool shouldPlayMessageTone() const;
|
||||
bool isPairingScreenActive() const;
|
||||
void resetRadioProfileDisplayPage();
|
||||
bool showingSecondaryRadioProfilePage();
|
||||
void serviceRadioProfileDisplayPage();
|
||||
void showPairingPin();
|
||||
void finishPairingScreen(bool timed_out);
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
#endif
|
||||
#include <helpers/TxtDataHelpers.h>
|
||||
#include <helpers/ui/BluetoothPairingUiPolicy.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <helpers/ui/RadioProfileSystemStatus.h>
|
||||
#include "../MyMesh.h"
|
||||
#include <RadioProfiles.h>
|
||||
#include "target.h"
|
||||
#include "u8g2_icons.h"
|
||||
|
||||
@@ -28,6 +31,42 @@
|
||||
|
||||
#define LONG_PRESS_MILLIS 1200
|
||||
|
||||
namespace {
|
||||
|
||||
mesh::ui::RadioProfileSystemStatus radioProfileSystemStatus(
|
||||
const CompanionNodePrefs& prefs) {
|
||||
mesh::ui::RadioProfileSystemStatus status;
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const mesh::RadioProfiles* profiles = radio ? radio->profiles() : NULL;
|
||||
status.public_key = the_mesh.self_id.pub_key;
|
||||
status.powersaving_enabled = prefs.powersaving_enabled != 0;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
status.gps_enabled = prefs.gps_enabled != 0;
|
||||
#endif
|
||||
status.fem_enabled = board.canControlLoRaFemLna()
|
||||
&& board.isLoRaFemLnaEnabled();
|
||||
status.rx_boosted_gain = prefs.rx_boosted_gain != 0;
|
||||
status.rx_powersaving_enabled = prefs.rx_powersaving_enabled != 0;
|
||||
status.cad_enabled = prefs.cad_enabled != 0;
|
||||
status.dual_radio_enabled = profiles != NULL && profiles->enabled();
|
||||
if (status.dual_radio_enabled) {
|
||||
status.secondary_temporary = profiles->secondary_temporary;
|
||||
status.secondary_mode = profiles->secondary.mode;
|
||||
status.cross = profiles->cross;
|
||||
}
|
||||
status.noise_floor_1 = radio_driver.getNoiseFloorDbm(0);
|
||||
status.noise_floor_1_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(0);
|
||||
if (status.dual_radio_enabled) {
|
||||
status.noise_floor_2 = radio_driver.getNoiseFloorDbm(1);
|
||||
status.noise_floor_2_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifndef UI_RECENT_LIST_SIZE
|
||||
#define UI_RECENT_LIST_SIZE 4
|
||||
#endif
|
||||
@@ -124,6 +163,8 @@ class HomeScreen : public UIScreen {
|
||||
bool sensors_scroll = false;
|
||||
int sensors_scroll_offset = 0;
|
||||
int next_sensors_refresh = 0;
|
||||
uint32_t _radio_profile_page_started_at = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
|
||||
void refresh_sensors() {
|
||||
if (millis() > next_sensors_refresh) {
|
||||
@@ -146,10 +187,39 @@ class HomeScreen : public UIScreen {
|
||||
}
|
||||
}
|
||||
|
||||
void resetRadioProfileDisplayPage() {
|
||||
_radio_profile_page_started_at = millis();
|
||||
_dual_radio_enabled_seen = the_mesh.isDualRadioActive();
|
||||
}
|
||||
|
||||
bool showingSecondaryRadioProfilePage(DisplayDriver& display) {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint32_t now = millis();
|
||||
if (dual_radio_enabled != _dual_radio_enabled_seen) {
|
||||
_dual_radio_enabled_seen = dual_radio_enabled;
|
||||
_radio_profile_page_started_at = now;
|
||||
}
|
||||
display.setTextSize(1);
|
||||
const uint8_t status_pages = mesh::ui::radioProfileSystemStatusPageCount(
|
||||
display, dual_radio_enabled, 8);
|
||||
return mesh::ui::showSecondaryRadioProfilePage(dual_radio_enabled,
|
||||
status_pages,
|
||||
now - _radio_profile_page_started_at);
|
||||
}
|
||||
|
||||
int radioProfileRefreshMillis() const {
|
||||
const uint32_t elapsed = millis() - _radio_profile_page_started_at;
|
||||
const uint32_t remaining = mesh::ui::RADIO_PROFILE_DISPLAY_PAGE_MILLIS
|
||||
- elapsed % mesh::ui::RADIO_PROFILE_DISPLAY_PAGE_MILLIS;
|
||||
return remaining < 5000 ? static_cast<int>(remaining) : 5000;
|
||||
}
|
||||
|
||||
public:
|
||||
HomeScreen(UITask* task, mesh::RTCClock* rtc, SensorManager* sensors, CompanionNodePrefs* node_prefs)
|
||||
: _task(task), _rtc(rtc), _sensors(sensors), _node_prefs(node_prefs), _page(0),
|
||||
_shutdown_init(false), sensors_lpp(200) { }
|
||||
_shutdown_init(false), sensors_lpp(200) {
|
||||
resetRadioProfileDisplayPage();
|
||||
}
|
||||
|
||||
void showFirstPage() { _page = HomePage::FIRST; }
|
||||
|
||||
@@ -230,23 +300,72 @@ public:
|
||||
} else if (_page == HomePage::RADIO) {
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setTextSize(1);
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
const mesh::RadioProfiles* profiles = radio ? radio->profiles() : NULL;
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
const uint8_t status_pages = mesh::ui::radioProfileSystemStatusPageCount(
|
||||
display, dual_radio, 8);
|
||||
uint8_t status_page_index = 0;
|
||||
if (mesh::ui::showRadioProfileSystemStatusPage(dual_radio, status_pages,
|
||||
millis() - _radio_profile_page_started_at, &status_page_index)) {
|
||||
mesh::ui::drawRadioProfileSystemStatusPage(display,
|
||||
radioProfileSystemStatus(*_node_prefs), status_page_index, 8);
|
||||
return radioProfileRefreshMillis();
|
||||
}
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage(display);
|
||||
const uint8_t profile = dual_radio && secondary_page ? 1 : 0;
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
const char* profile_tag = "";
|
||||
if (dual_radio) {
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
profile_tag = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary
|
||||
: profiles->primary_temporary);
|
||||
}
|
||||
// frequency and spreading factor
|
||||
display.setCursor(0, 8);
|
||||
sprintf(tmp, "FQ %06.3f", _node_prefs->freq);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s F:%06.3f", profile_tag, freq);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "FQ %06.3f", freq);
|
||||
}
|
||||
display.print(tmp);
|
||||
sprintf(tmp, "SF%d", _node_prefs->sf);
|
||||
snprintf(tmp, sizeof(tmp), "S:%d", sf);
|
||||
display.drawTextRightAlign(display.width(), 8, tmp);
|
||||
// bandwidth and coding rate
|
||||
display.setCursor(0, 17);
|
||||
sprintf(tmp, "BW %03.2f", _node_prefs->bw);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s B:%03.2f", profile_tag, bw);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "BW %03.2f", bw);
|
||||
}
|
||||
display.print(tmp);
|
||||
sprintf(tmp, "CR%d", _node_prefs->cr);
|
||||
snprintf(tmp, sizeof(tmp), "C:%d", cr);
|
||||
display.drawTextRightAlign(display.width(), 17, tmp);
|
||||
// tx power and noise floor
|
||||
display.setCursor(0, 26);
|
||||
sprintf(tmp, "NF %ddB", radio_driver.getNoiseFloor());
|
||||
const char* noise_label = dual_radio ? (profile == 0 ? "N1" : "N2") : "NF";
|
||||
const float noise_floor = radio_driver.getNoiseFloorDbm(profile);
|
||||
if (noise_floor == 0.0f) {
|
||||
const float seconds = radio_driver
|
||||
.getNoiseFloorCalibrationSecondsRemaining(profile);
|
||||
if (seconds > 0.0f) {
|
||||
snprintf(tmp, sizeof(tmp), "%s:%.1fs", noise_label, seconds);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%s:WAIT", noise_label);
|
||||
}
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "%s:%.1f", noise_label, noise_floor);
|
||||
}
|
||||
display.print(tmp);
|
||||
sprintf(tmp, "TX%d", _node_prefs->tx_power_dbm);
|
||||
snprintf(tmp, sizeof(tmp), "TX:%d", _node_prefs->tx_power_dbm);
|
||||
display.drawTextRightAlign(display.width(), 26, tmp);
|
||||
|
||||
} else if (_page == HomePage::BLUETOOTH) {
|
||||
@@ -387,16 +506,20 @@ public:
|
||||
// display.drawTextCentered(display.width() / 2, 40 - 11, "hibernate:" PRESS_LABEL);
|
||||
}
|
||||
}
|
||||
return 5000; // next render after 5000 ms
|
||||
// Keep the compact radio page on the R1/R2 boundary; other tiny pages
|
||||
// retain their existing low-refresh cadence.
|
||||
return _page == HomePage::RADIO ? radioProfileRefreshMillis() : 5000;
|
||||
}
|
||||
|
||||
bool handleInput(char c) override {
|
||||
if (c == KEY_LEFT || c == KEY_PREV) {
|
||||
_page = (_page + HomePage::Count - 1) % HomePage::Count;
|
||||
if (_page == HomePage::RADIO) resetRadioProfileDisplayPage();
|
||||
return true;
|
||||
}
|
||||
if (c == KEY_NEXT || c == KEY_RIGHT) {
|
||||
_page = (_page + 1) % HomePage::Count;
|
||||
if (_page == HomePage::RADIO) resetRadioProfileDisplayPage();
|
||||
if (_page == HomePage::RECENT) {
|
||||
_task->showAlert("Recent adverts", 800);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,261 @@
|
||||
#include <helpers/CommonCLI.h>
|
||||
#include <helpers/ui/WiFiSetupQrDisplay.h>
|
||||
#include <helpers/ui/CompanionHomeLayout.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <RadioProfiles.h>
|
||||
#include <Utils.h>
|
||||
#include "MyMesh.h"
|
||||
|
||||
extern MyMesh the_mesh;
|
||||
|
||||
namespace {
|
||||
|
||||
const mesh::RadioProfiles* configuredRadioProfiles() {
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
return radio ? radio->profiles() : NULL;
|
||||
}
|
||||
|
||||
const char* secondaryRadioProfileTag() {
|
||||
const auto* profiles = configuredRadioProfiles();
|
||||
return mesh::ui::radioProfileDisplayTag(true,
|
||||
profiles != NULL && profiles->secondary_temporary);
|
||||
}
|
||||
|
||||
// The complete system-status view needs four rows on a single-radio node and
|
||||
// two more when radio2 is configured. Grouping related switches keeps a
|
||||
// normal 128x64 OLED to one status page (rather than silently dropping the
|
||||
// lower rows), while the measured page count below naturally splits this on
|
||||
// a genuinely short display.
|
||||
constexpr uint8_t RADIO_SYSTEM_STATUS_ROWS = 8;
|
||||
constexpr uint8_t RADIO_SYSTEM_STATUS_ROWS_WITHOUT_RADIO2 = 5;
|
||||
|
||||
uint8_t radioSystemStatusRowsPerPage(DisplayDriver& display) {
|
||||
const int line_height = display.textLineHeight();
|
||||
if (line_height <= 0) return 1;
|
||||
const int row_height = line_height + 2;
|
||||
const int rows = (display.height() + 2) / row_height;
|
||||
return rows > 0 ? rows : 1;
|
||||
}
|
||||
|
||||
uint8_t radioSystemStatusPageCount(DisplayDriver& display,
|
||||
bool dual_radio_enabled) {
|
||||
const uint8_t row_count = dual_radio_enabled ? RADIO_SYSTEM_STATUS_ROWS
|
||||
: RADIO_SYSTEM_STATUS_ROWS_WITHOUT_RADIO2;
|
||||
const uint8_t rows_per_page = radioSystemStatusRowsPerPage(display);
|
||||
return (row_count + rows_per_page - 1) / rows_per_page;
|
||||
}
|
||||
|
||||
int drawRadioStatusState(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);
|
||||
}
|
||||
|
||||
void drawRadioStatusPair(DisplayDriver& display, int y,
|
||||
const char* first_label, bool first_enabled,
|
||||
const char* second_label, bool second_enabled) {
|
||||
int x = drawRadioStatusState(display, 0, y, first_label, first_enabled);
|
||||
drawRadioStatusState(display, x + display.getTextWidth(" "), y,
|
||||
second_label, second_enabled);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
}
|
||||
|
||||
void formatRadioNoiseFloor(char* noise_floor, size_t size, const char* label,
|
||||
uint8_t profile = 0) {
|
||||
const float dbm = radio_driver.getNoiseFloorDbm(profile);
|
||||
if (dbm == 0.0f) {
|
||||
const float seconds = radio_driver.getNoiseFloorCalibrationSecondsRemaining(profile);
|
||||
if (seconds > 0.0f) {
|
||||
snprintf(noise_floor, size, "%s:%.1fs", label, seconds);
|
||||
} else {
|
||||
snprintf(noise_floor, size, "%s:WAIT", label);
|
||||
}
|
||||
} else {
|
||||
snprintf(noise_floor, size, "%s:%.1f", label, dbm);
|
||||
}
|
||||
}
|
||||
|
||||
void drawRadioNoiseFloor(DisplayDriver& display, int y, const char* label,
|
||||
uint8_t profile = 0) {
|
||||
char noise_floor[12];
|
||||
formatRadioNoiseFloor(noise_floor, sizeof(noise_floor), label, profile);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setCursor(0, y);
|
||||
display.print(noise_floor);
|
||||
}
|
||||
|
||||
void drawRadioSystemStatusPage(DisplayDriver& display, const NodePrefs& prefs,
|
||||
uint8_t status_page_index) {
|
||||
display.setTextSize(1);
|
||||
const auto* profiles = configuredRadioProfiles();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
const uint8_t rows_per_page = radioSystemStatusRowsPerPage(display);
|
||||
const uint8_t first_row = status_page_index * rows_per_page;
|
||||
const uint8_t row_count = dual_radio ? RADIO_SYSTEM_STATUS_ROWS
|
||||
: RADIO_SYSTEM_STATUS_ROWS_WITHOUT_RADIO2;
|
||||
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 = (row - first_row) * row_height;
|
||||
switch (row) {
|
||||
case 0: {
|
||||
char identity_prefix[7];
|
||||
mesh::Utils::toHex(identity_prefix, the_mesh.getSelfId().pub_key, 3);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setCursor(0, y);
|
||||
display.print("ID:");
|
||||
display.print(identity_prefix);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
drawRadioStatusPair(display, y, "PS:", prefs.powersaving_enabled != 0,
|
||||
"GPS:", prefs.gps_enabled != 0);
|
||||
#else
|
||||
drawRadioStatusPair(display, y, "PS:", prefs.powersaving_enabled != 0,
|
||||
"GPS:", false);
|
||||
#endif
|
||||
break;
|
||||
case 2:
|
||||
drawRadioStatusPair(display, y, "FEM:",
|
||||
board.canControlLoRaFemLna() && board.isLoRaFemLnaEnabled(),
|
||||
"RXB:", prefs.rx_boosted_gain != 0);
|
||||
break;
|
||||
case 3:
|
||||
drawRadioStatusPair(display, y, "RXPS:", prefs.rx_powersaving_enabled != 0,
|
||||
"CAD:", prefs.cad_enabled != 0);
|
||||
break;
|
||||
case 4: {
|
||||
char mode[10];
|
||||
snprintf(mode, sizeof(mode), "%s:%s", secondaryRadioProfileTag(),
|
||||
profiles->secondary.mode == mesh::RadioProfileMode::RxTx ? "RXTX" : "RX");
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setCursor(0, y);
|
||||
display.print(mode);
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
const char* cross = profiles->cross == mesh::RadioCrossMode::On ? "X:ON"
|
||||
: profiles->cross == mesh::RadioCrossMode::Off ? "X:OFF" : "X:AUTO";
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setCursor(0, y);
|
||||
display.print(cross);
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
drawRadioNoiseFloor(display, y, "N1", 0);
|
||||
break;
|
||||
case 7:
|
||||
drawRadioNoiseFloor(display, y, "N2", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
display.setColor(UIColor::primary_txt);
|
||||
}
|
||||
|
||||
#if defined(HELTEC_T096)
|
||||
|
||||
// The native T096 canvas is 160x80. Compact F/B/S/C rows use the first 108
|
||||
// pixels; this leaves a 50px status column plus a 2px right margin. The
|
||||
// widest normal 6x8 label, "RXPS:OFF", is 48px, so it has a 2px buffer.
|
||||
constexpr int T096_STATUS_PANEL_WIDTH = 50;
|
||||
constexpr int T096_STATUS_RIGHT_MARGIN = 2;
|
||||
constexpr int T096_STATUS_TOP = 10;
|
||||
constexpr int T096_STATUS_LINE_HEIGHT = 10;
|
||||
|
||||
void drawT096State(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);
|
||||
display.setColor(enabled ? UIColor::primary_txt : UIColor::warning_txt);
|
||||
display.setCursor(x + display.getTextWidth(label), y);
|
||||
display.print(state);
|
||||
}
|
||||
|
||||
void drawT096StatusRow(DisplayDriver& display, int y,
|
||||
const char* name, bool enabled) {
|
||||
char label[8]; // "RXPS:" plus its terminator
|
||||
snprintf(label, sizeof(label), "%s:", name);
|
||||
const char* state = enabled ? "ON" : "OFF";
|
||||
const int x = display.width() - T096_STATUS_RIGHT_MARGIN
|
||||
- display.getTextWidth(label) - display.getTextWidth(state);
|
||||
drawT096State(display, x, y, label, enabled);
|
||||
}
|
||||
|
||||
void drawT096NoiseFloorRow(DisplayDriver& display, int y, uint8_t profile) {
|
||||
char noise_floor[12];
|
||||
const bool dual_radio = the_mesh.isDualRadioActive();
|
||||
const char* label = dual_radio ? (profile == 1 ? "N2" : "N1") : "N";
|
||||
// "N1:-120.0" needs 54px in the normal 6px font. On this final line the
|
||||
// left side contains only the short cross-mode marker, so it may safely use
|
||||
// four pixels of the otherwise empty gutter while retaining decimal dBm.
|
||||
formatRadioNoiseFloor(noise_floor, sizeof(noise_floor), label, profile);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setCursor(display.width() - T096_STATUS_RIGHT_MARGIN
|
||||
- display.getTextWidth(noise_floor), y);
|
||||
display.print(noise_floor);
|
||||
}
|
||||
|
||||
void drawT096StatusPanel(DisplayDriver& display, const NodePrefs& prefs,
|
||||
uint8_t profile) {
|
||||
// This is the ST7735 driver's standard 6x8 font, rather than Squeezed6.
|
||||
display.setTextSize(1);
|
||||
int y = T096_STATUS_TOP;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
drawT096StatusRow(display, y, "GPS", prefs.gps_enabled != 0);
|
||||
#else
|
||||
drawT096StatusRow(display, y, "GPS", false);
|
||||
#endif
|
||||
y += T096_STATUS_LINE_HEIGHT;
|
||||
drawT096StatusRow(display, y, "FEM", board.canControlLoRaFemLna()
|
||||
&& board.isLoRaFemLnaEnabled());
|
||||
y += T096_STATUS_LINE_HEIGHT;
|
||||
drawT096StatusRow(display, y, "RXB", prefs.rx_boosted_gain != 0);
|
||||
y += T096_STATUS_LINE_HEIGHT;
|
||||
drawT096StatusRow(display, y, "RXPS", prefs.rx_powersaving_enabled != 0);
|
||||
|
||||
// A configured secondary profile keeps both profiles live; show it only
|
||||
// when it exists, so the panel does not imply a second radio on every T096.
|
||||
if (the_mesh.isDualRadioActive()) {
|
||||
y += T096_STATUS_LINE_HEIGHT;
|
||||
drawT096StatusRow(display, y, secondaryRadioProfileTag(), true);
|
||||
}
|
||||
y += T096_STATUS_LINE_HEIGHT;
|
||||
drawT096StatusRow(display, y, "CAD", prefs.cad_enabled != 0);
|
||||
y += T096_STATUS_LINE_HEIGHT;
|
||||
drawT096NoiseFloorRow(display, y, profile);
|
||||
display.setColor(UIColor::primary_txt);
|
||||
}
|
||||
|
||||
void drawT096Radio2Details(DisplayDriver& display, int mode_y, int cross_y) {
|
||||
const auto* profiles = configuredRadioProfiles();
|
||||
if (profiles == NULL || !profiles->enabled()) return;
|
||||
|
||||
char mode[10];
|
||||
snprintf(mode, sizeof(mode), "%s:%s", secondaryRadioProfileTag(),
|
||||
profiles->secondary.mode == mesh::RadioProfileMode::RxTx ? "RXTX" : "RX");
|
||||
const char* cross = profiles->cross == mesh::RadioCrossMode::On ? "X:ON"
|
||||
: profiles->cross == mesh::RadioCrossMode::Off ? "X:OFF" : "X:AUTO";
|
||||
display.setColor(UIColor::primary_txt);
|
||||
display.setCursor(0, mode_y);
|
||||
display.print(mode);
|
||||
display.setCursor(0, cross_y);
|
||||
display.print(cross);
|
||||
}
|
||||
|
||||
#endif // HELTEC_T096
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
#include <helpers/ui/DisplayFrameSignature.h>
|
||||
@@ -77,6 +332,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
|
||||
_prevBtnState = HIGH;
|
||||
_started_at = millis();
|
||||
_node_prefs = node_prefs;
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
ObserverDashboard::applyDarkPalette(); // retunes UIColor for this target only
|
||||
#endif
|
||||
@@ -106,6 +362,56 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
|
||||
free(version);
|
||||
}
|
||||
|
||||
void UITask::resetRadioProfileDisplayPage() {
|
||||
_radio_profile_display_page = 0;
|
||||
_dual_radio_enabled_seen = the_mesh.isDualRadioActive();
|
||||
}
|
||||
|
||||
uint8_t UITask::currentRadioProfileDisplayPage() {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
if (dual_radio_enabled != _dual_radio_enabled_seen) {
|
||||
_dual_radio_enabled_seen = dual_radio_enabled;
|
||||
_radio_profile_display_page = 0;
|
||||
}
|
||||
return mesh::ui::radioProfileManualPageIndex(dual_radio_enabled,
|
||||
radioProfileSystemStatusPageCount(), _radio_profile_display_page);
|
||||
}
|
||||
|
||||
void UITask::advanceRadioProfileDisplayPage() {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint8_t page_count = mesh::ui::radioProfileDisplayPageCount(
|
||||
dual_radio_enabled, radioProfileSystemStatusPageCount());
|
||||
_radio_profile_display_page = (currentRadioProfileDisplayPage() + 1) % page_count;
|
||||
_next_refresh = 0;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool UITask::showingSecondaryRadioProfilePage() {
|
||||
return mesh::ui::showManualSecondaryRadioProfilePage(the_mesh.isDualRadioActive(),
|
||||
currentRadioProfileDisplayPage());
|
||||
}
|
||||
|
||||
uint8_t UITask::radioProfileSystemStatusPageCount() const {
|
||||
#if defined(HELTEC_T096)
|
||||
// The T096's dedicated 50px status column already shows every switch.
|
||||
return 0;
|
||||
#else
|
||||
_display->setTextSize(1);
|
||||
return radioSystemStatusPageCount(*_display, the_mesh.isDualRadioActive());
|
||||
#endif
|
||||
}
|
||||
|
||||
bool UITask::showingRadioProfileSystemStatusPage(uint8_t* status_page_index) {
|
||||
return mesh::ui::showManualRadioProfileSystemStatusPage(the_mesh.isDualRadioActive(),
|
||||
radioProfileSystemStatusPageCount(), currentRadioProfileDisplayPage(),
|
||||
status_page_index);
|
||||
}
|
||||
|
||||
void UITask::renderCurrScreen() {
|
||||
char tmp[80];
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
@@ -192,23 +498,85 @@ void UITask::renderCurrScreen() {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
uint8_t status_page_index = 0;
|
||||
if (showingRadioProfileSystemStatusPage(&status_page_index)) {
|
||||
drawRadioSystemStatusPage(*_display, *_node_prefs, status_page_index);
|
||||
return;
|
||||
}
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
renderDashboard();
|
||||
return;
|
||||
#endif
|
||||
// Reserve a full measured font-height for each row on OLED/TFT/e-paper.
|
||||
mesh::ui::BoundedTextRows rows(*_display,
|
||||
{0, 0, _display->width(), _display->height()});
|
||||
#if defined(HELTEC_T096)
|
||||
// Never let normal full-size rows overwrite the dedicated normal-font
|
||||
// column at the right of the native 160x80 T096 screen.
|
||||
const int content_width = _display->width() - T096_STATUS_PANEL_WIDTH
|
||||
- T096_STATUS_RIGHT_MARGIN;
|
||||
#else
|
||||
const int content_width = _display->width();
|
||||
#endif
|
||||
_display->setTextSize(1);
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
#if defined(HELTEC_T096)
|
||||
// The name gets the entire top row. The status strip begins below it, so
|
||||
// no part of the name is covered or forced into a second line.
|
||||
_display->drawTextEllipsized(0, 0, _display->width(), _node_prefs->node_name);
|
||||
const int rows_top = T096_STATUS_TOP;
|
||||
mesh::ui::BoundedTextRows rows(*_display,
|
||||
{0, rows_top, content_width, _display->height() - rows_top});
|
||||
#else
|
||||
mesh::ui::BoundedTextRows rows(*_display,
|
||||
{0, 0, content_width, _display->height()});
|
||||
rows.draw(_node_prefs->node_name, false);
|
||||
#endif
|
||||
|
||||
// freq / sf
|
||||
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
const char* profile_tag = "";
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
profile_tag = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
|
||||
// T096's normal 6x8 right column needs compact radio labels. Other
|
||||
// displays retain the longer labels for their roomier layouts.
|
||||
#if defined(HELTEC_T096)
|
||||
snprintf(tmp, sizeof(tmp), "%s%sF:%06.3f S:%d", profile_tag,
|
||||
dual_radio ? " " : "", freq, sf);
|
||||
#else
|
||||
if (dual_radio) {
|
||||
// R1/R2/T1/T2 needs three extra cells. Compact fields retain every RF
|
||||
// value on a 128px OLED even at the widest legal frequency/SF pair.
|
||||
snprintf(tmp, sizeof(tmp), "%s F:%06.3f S:%d", profile_tag, freq, sf);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", freq, sf);
|
||||
}
|
||||
#endif
|
||||
rows.draw(tmp, false);
|
||||
|
||||
// bw / cr
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
// bandwidth / coding rate
|
||||
#if defined(HELTEC_T096)
|
||||
snprintf(tmp, sizeof(tmp), "%s%sB:%03.2f C:%d", profile_tag,
|
||||
dual_radio ? " " : "", bw, cr);
|
||||
#else
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s B:%03.2f C:%d", profile_tag, bw, cr);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
}
|
||||
#endif
|
||||
rows.draw(tmp, false);
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
@@ -226,8 +594,38 @@ void UITask::renderCurrScreen() {
|
||||
}
|
||||
|
||||
// Keep power-saving state visible even when the MQTT IP replaces battery.
|
||||
snprintf(tmp, sizeof(tmp), "PowerSaving: %s", _node_prefs->powersaving_enabled ? "ON" : "off");
|
||||
#if defined(HELTEC_T096)
|
||||
// This is the fourth left-column row (after F, B, and battery/IP). Keep
|
||||
// its label green, with just the saved ON/OFF value carrying the state
|
||||
// color used by the status strip.
|
||||
const int power_saving_y = rows.nextY();
|
||||
if (rows.reserve()) {
|
||||
drawT096State(*_display, 0, power_saving_y, "PS: ",
|
||||
_node_prefs->powersaving_enabled != 0);
|
||||
}
|
||||
const int identity_y = rows.nextY();
|
||||
if (rows.reserve()) {
|
||||
char identity_prefix[7];
|
||||
mesh::Utils::toHex(identity_prefix, the_mesh.getSelfId().pub_key, 3);
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
_display->setCursor(0, identity_y);
|
||||
_display->print("ID:");
|
||||
_display->print(identity_prefix);
|
||||
}
|
||||
drawT096Radio2Details(*_display, rows.nextY(),
|
||||
rows.nextY() + _display->textLineHeight() + 2);
|
||||
#else
|
||||
snprintf(tmp, sizeof(tmp), "PS: %s", _node_prefs->powersaving_enabled ? "ON" : "OFF");
|
||||
rows.draw(tmp, false);
|
||||
#endif
|
||||
#if defined(HELTEC_T096)
|
||||
drawT096StatusPanel(*_display, *_node_prefs, secondary_page ? 1 : 0);
|
||||
#else
|
||||
// The shared radio-profile layer reports this on every repeater board.
|
||||
// BoundedTextRows simply omits this extra row on a screen too short to
|
||||
// hold it, rather than overwriting an existing status line.
|
||||
if (the_mesh.isDualRadioActive()) rows.draw("DualRadio: ON", false);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,9 +658,61 @@ uint32_t UITask::getFrameSignature() {
|
||||
|
||||
signature = DisplayFrameSignature::append(signature, "home");
|
||||
signature = DisplayFrameSignature::append(signature, _node_prefs->node_name);
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
uint8_t status_page_index = 0;
|
||||
if (showingRadioProfileSystemStatusPage(&status_page_index)) {
|
||||
signature = DisplayFrameSignature::append(signature, "radio-system-status");
|
||||
snprintf(tmp, sizeof(tmp), "status-page-%u", status_page_index);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->powersaving_enabled ? "powersaving-on" : "powersaving-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->gps_enabled ? "gps-on" : "gps-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _board->canControlLoRaFemLna() && _board->isLoRaFemLnaEnabled()
|
||||
? "fem-on" : "fem-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->rx_boosted_gain ? "rxb-on" : "rxb-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->rx_powersaving_enabled ? "rxps-on" : "rxps-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->cad_enabled ? "cad-on" : "cad-off");
|
||||
const mesh::RadioProfiles* status_profiles = configuredRadioProfiles();
|
||||
if (status_profiles != NULL && status_profiles->enabled()) {
|
||||
formatRadioNoiseFloor(tmp, sizeof(tmp), "N1", 0);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
formatRadioNoiseFloor(tmp, sizeof(tmp), "N2", 1);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
signature = DisplayFrameSignature::append(signature,
|
||||
status_profiles->secondary.mode == mesh::RadioProfileMode::RxTx
|
||||
? "radio2-rxtx" : "radio2-rx");
|
||||
signature = DisplayFrameSignature::append(signature,
|
||||
status_profiles->cross == mesh::RadioCrossMode::On ? "cross-on"
|
||||
: status_profiles->cross == mesh::RadioCrossMode::Off
|
||||
? "cross-off" : "cross-auto");
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
signature = DisplayFrameSignature::append(signature,
|
||||
mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary));
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", freq, sf);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
|
||||
#if defined(WITH_MQTT_BRIDGE) && !defined(DISPLAY_ACTIVITY_DASHBOARD)
|
||||
@@ -287,6 +737,24 @@ uint32_t UITask::getFrameSignature() {
|
||||
#endif
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->powersaving_enabled ? "powersaving-on" : "powersaving-off");
|
||||
#if defined(HELTEC_T096)
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->gps_enabled ? "gps-on" : "gps-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _board->canControlLoRaFemLna() && _board->isLoRaFemLnaEnabled()
|
||||
? "fem-on" : "fem-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->rx_boosted_gain ? "rxb-on" : "rxb-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->rx_powersaving_enabled ? "rxps-on" : "rxps-off");
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, _node_prefs->cad_enabled ? "cad-on" : "cad-off");
|
||||
formatRadioNoiseFloor(tmp, sizeof(tmp), dual_radio
|
||||
? (secondary_page ? "N2" : "N1") : "N", secondary_page ? 1 : 0);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
#endif
|
||||
signature = DisplayFrameSignature::append(
|
||||
signature, the_mesh.isDualRadioActive() ? "radio2-on" : "radio2-off");
|
||||
#endif
|
||||
|
||||
return signature;
|
||||
@@ -303,6 +771,18 @@ bool UITask::buildDashboardContext(ObserverDashboard::Context* ctx) {
|
||||
ctx->freq = _node_prefs->freq;
|
||||
ctx->sf = _node_prefs->sf;
|
||||
ctx->bw = _node_prefs->bw;
|
||||
ctx->radio_label = "";
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
if (profiles != NULL && profiles->enabled()) {
|
||||
const uint8_t profile = showingSecondaryRadioProfilePage() ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
ctx->freq = params.freq;
|
||||
ctx->sf = params.sf;
|
||||
ctx->bw = params.bw;
|
||||
ctx->radio_label = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
ctx->dual_radio = the_mesh.isDualRadioActive();
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
ctx->link_up = (WiFi.status() == WL_CONNECTED);
|
||||
#else
|
||||
@@ -347,6 +827,7 @@ void UITask::updateActivityRows() {
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
void UITask::toggleDisplay(const char* source) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_TOUCH_DEBUG
|
||||
mesh::usbConsolePort().printf("Display: %s -> %s\n", source, _display->isOn() ? "on" : "off");
|
||||
#else
|
||||
@@ -364,6 +845,7 @@ void UITask::toggleDisplay(const char* source) {
|
||||
|
||||
void UITask::loop() {
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) {
|
||||
if (_display->isOn()) resetRadioProfileDisplayPage();
|
||||
_next_refresh = 0;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
@@ -378,13 +860,15 @@ void UITask::loop() {
|
||||
// WebConfig. Collapse a completed double-click into one display action
|
||||
// instead of silently consuming both presses.
|
||||
if (ev == BUTTON_EVENT_CLICK || ev == BUTTON_EVENT_DOUBLE_CLICK) {
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
toggleDisplay("button"); // same action as tapping the panel
|
||||
#else
|
||||
if (_display->isOn()) {
|
||||
// TODO: any action ?
|
||||
// A page change is still user activity. Capture the old state first so
|
||||
// the first press wakes to R1, while every subsequent press both extends
|
||||
// the 15-second timer and advances to the next available detail page.
|
||||
const bool display_was_on = _display->isOn();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
if (display_was_on) {
|
||||
advanceRadioProfileDisplayPage();
|
||||
} else {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
@@ -392,10 +876,9 @@ void UITask::loop() {
|
||||
_rows_valid = false;
|
||||
#endif
|
||||
}
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
#endif
|
||||
} else if (ev == BUTTON_EVENT_LONG_PRESS) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
mesh::usbConsolePort().printf("Powering Off\r\n");
|
||||
_powering_off_at = millis() + POWEROFF_DELAY;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
@@ -411,6 +894,7 @@ void UITask::loop() {
|
||||
// multiclick enabled specifically for this action.
|
||||
WebConfigServer::requestToggleFromButton();
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@@ -451,7 +935,16 @@ void UITask::loop() {
|
||||
}
|
||||
#endif
|
||||
|
||||
_next_refresh = millis() + 1000; // check for visible changes every second
|
||||
unsigned long refresh_interval = 1000; // check normal status changes every second
|
||||
#if defined(HELTEC_T096)
|
||||
// The T096's TFT can show each tenth while the short, 3.2-second noise
|
||||
// floor collection window is active. Keep every other screen at the
|
||||
// normal cadence, particularly displays with slow/expensive refreshes.
|
||||
if (radio_driver.getNoiseFloorCalibrationSecondsRemaining() > 0.0f) {
|
||||
refresh_interval = 100;
|
||||
}
|
||||
#endif
|
||||
_next_refresh = millis() + refresh_interval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,15 @@ class UITask {
|
||||
char _version_info[32];
|
||||
unsigned long _powering_off_at = 0;
|
||||
unsigned long _started_at = 0;
|
||||
uint8_t _radio_profile_display_page = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
|
||||
void resetRadioProfileDisplayPage();
|
||||
void advanceRadioProfileDisplayPage();
|
||||
uint8_t currentRadioProfileDisplayPage();
|
||||
bool showingSecondaryRadioProfilePage();
|
||||
bool showingRadioProfileSystemStatusPage(uint8_t* status_page_index = nullptr);
|
||||
uint8_t radioProfileSystemStatusPageCount() const;
|
||||
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
uint32_t _last_frame_signature = 0;
|
||||
|
||||
@@ -4,6 +4,59 @@
|
||||
#include <helpers/UsbLogging.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
#include <helpers/ui/WiFiSetupQrDisplay.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <helpers/ui/RadioProfileSystemStatus.h>
|
||||
#include <RadioProfiles.h>
|
||||
#include "MyMesh.h"
|
||||
|
||||
extern MyMesh the_mesh;
|
||||
|
||||
namespace {
|
||||
|
||||
const mesh::RadioProfiles* configuredRadioProfiles() {
|
||||
const auto* radio = the_mesh.getProfileRadio();
|
||||
return radio ? radio->profiles() : NULL;
|
||||
}
|
||||
|
||||
mesh::ui::RadioProfileSystemStatus radioProfileSystemStatus(
|
||||
const NodePrefs& prefs) {
|
||||
mesh::ui::RadioProfileSystemStatus status;
|
||||
const auto* profiles = configuredRadioProfiles();
|
||||
status.public_key = the_mesh.getSelfId().pub_key;
|
||||
status.powersaving_enabled = prefs.powersaving_enabled != 0;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
status.gps_enabled = prefs.gps_enabled != 0;
|
||||
#endif
|
||||
status.fem_enabled = board.canControlLoRaFemLna()
|
||||
&& board.isLoRaFemLnaEnabled();
|
||||
status.rx_boosted_gain = prefs.rx_boosted_gain != 0;
|
||||
status.rx_powersaving_enabled = prefs.rx_powersaving_enabled != 0;
|
||||
status.cad_enabled = prefs.cad_enabled != 0;
|
||||
status.dual_radio_enabled = profiles != NULL && profiles->enabled();
|
||||
if (status.dual_radio_enabled) {
|
||||
status.secondary_temporary = profiles->secondary_temporary;
|
||||
status.secondary_mode = profiles->secondary.mode;
|
||||
status.cross = profiles->cross;
|
||||
}
|
||||
status.noise_floor_1 = radio_driver.getNoiseFloorDbm(0);
|
||||
status.noise_floor_1_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(0);
|
||||
if (status.dual_radio_enabled) {
|
||||
status.noise_floor_2 = radio_driver.getNoiseFloorDbm(1);
|
||||
status.noise_floor_2_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t radioProfileStatusPageCount(DisplayDriver& display,
|
||||
bool dual_radio_enabled) {
|
||||
display.setTextSize(1);
|
||||
return mesh::ui::radioProfileSystemStatusPageCount(display,
|
||||
dual_radio_enabled);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
#include <helpers/ui/DisplayFrameSignature.h>
|
||||
@@ -78,6 +131,7 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
|
||||
_prevBtnState = HIGH;
|
||||
_started_at = millis();
|
||||
_node_prefs = node_prefs;
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
ObserverDashboard::applyDarkPalette(); // retunes UIColor for this target only
|
||||
#endif
|
||||
@@ -109,6 +163,25 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
|
||||
free(version);
|
||||
}
|
||||
|
||||
void UITask::resetRadioProfileDisplayPage() {
|
||||
_radio_profile_page_started_at = millis();
|
||||
_dual_radio_enabled_seen = the_mesh.isDualRadioActive();
|
||||
}
|
||||
|
||||
bool UITask::showingSecondaryRadioProfilePage() {
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint32_t now = millis();
|
||||
if (dual_radio_enabled != _dual_radio_enabled_seen) {
|
||||
_dual_radio_enabled_seen = dual_radio_enabled;
|
||||
_radio_profile_page_started_at = now;
|
||||
}
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(*_display,
|
||||
dual_radio_enabled);
|
||||
return mesh::ui::showSecondaryRadioProfilePage(dual_radio_enabled,
|
||||
status_pages,
|
||||
now - _radio_profile_page_started_at);
|
||||
}
|
||||
|
||||
void UITask::renderCurrScreen() {
|
||||
char tmp[80];
|
||||
#ifdef DISPLAY_ACTIVITY_DASHBOARD
|
||||
@@ -196,20 +269,57 @@ void UITask::renderCurrScreen() {
|
||||
renderDashboard();
|
||||
return;
|
||||
#endif
|
||||
const bool dual_radio_enabled = the_mesh.isDualRadioActive();
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(
|
||||
*_display, dual_radio_enabled);
|
||||
uint8_t status_page_index = 0;
|
||||
if (mesh::ui::showRadioProfileSystemStatusPage(dual_radio_enabled,
|
||||
status_pages, millis() - _radio_profile_page_started_at,
|
||||
&status_page_index)) {
|
||||
mesh::ui::drawRadioProfileSystemStatusPage(*_display,
|
||||
radioProfileSystemStatus(*_node_prefs), status_page_index);
|
||||
return;
|
||||
}
|
||||
// node name
|
||||
_display->setCursor(0, 0);
|
||||
_display->setTextSize(1);
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
_display->print(_node_prefs->node_name);
|
||||
|
||||
// freq / sf
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
const char* profile_tag = "";
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
profile_tag = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
|
||||
// Compact R1/R2 rows preserve every RF field on 128px displays.
|
||||
_display->setCursor(0, 20);
|
||||
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s F:%06.3f S:%d", profile_tag, freq, sf);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", freq, sf);
|
||||
}
|
||||
_display->print(tmp);
|
||||
|
||||
// bw / cr
|
||||
_display->setCursor(0, 30);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s B:%03.2f C:%d", profile_tag, bw, cr);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
}
|
||||
_display->print(tmp);
|
||||
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
@@ -256,9 +366,36 @@ uint32_t UITask::getFrameSignature() {
|
||||
|
||||
signature = DisplayFrameSignature::append(signature, "home");
|
||||
signature = DisplayFrameSignature::append(signature, _node_prefs->node_name);
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(*_display,
|
||||
dual_radio);
|
||||
uint8_t status_page_index = 0;
|
||||
if (mesh::ui::showRadioProfileSystemStatusPage(dual_radio, status_pages,
|
||||
millis() - _radio_profile_page_started_at, &status_page_index)) {
|
||||
snprintf(tmp, sizeof(tmp), "radio-status:%u:%lu", status_page_index,
|
||||
(unsigned long)(millis() / 1000UL));
|
||||
return DisplayFrameSignature::append(signature, tmp);
|
||||
}
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage();
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
signature = DisplayFrameSignature::append(signature,
|
||||
mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary));
|
||||
}
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", freq, sf);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
signature = DisplayFrameSignature::append(signature, tmp);
|
||||
|
||||
#if defined(WITH_MQTT_BRIDGE) && !defined(DISPLAY_ACTIVITY_DASHBOARD)
|
||||
@@ -285,6 +422,18 @@ bool UITask::buildDashboardContext(ObserverDashboard::Context* ctx) {
|
||||
ctx->freq = _node_prefs->freq;
|
||||
ctx->sf = _node_prefs->sf;
|
||||
ctx->bw = _node_prefs->bw;
|
||||
ctx->radio_label = "";
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
if (profiles != NULL && profiles->enabled()) {
|
||||
const uint8_t profile = showingSecondaryRadioProfilePage() ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
ctx->freq = params.freq;
|
||||
ctx->sf = params.sf;
|
||||
ctx->bw = params.bw;
|
||||
ctx->radio_label = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
ctx->dual_radio = the_mesh.isDualRadioActive();
|
||||
#ifdef WITH_MQTT_BRIDGE
|
||||
ctx->link_up = (WiFi.status() == WL_CONNECTED);
|
||||
#else
|
||||
@@ -329,6 +478,7 @@ void UITask::updateActivityRows() {
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
void UITask::toggleDisplay(const char* source) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_TOUCH_DEBUG
|
||||
mesh::usbConsolePort().printf("Display: %s -> %s\n", source, _display->isOn() ? "on" : "off");
|
||||
#else
|
||||
@@ -346,6 +496,7 @@ void UITask::toggleDisplay(const char* source) {
|
||||
|
||||
void UITask::loop() {
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) {
|
||||
resetRadioProfileDisplayPage();
|
||||
_next_refresh = 0;
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
@@ -381,6 +532,7 @@ void UITask::loop() {
|
||||
if (ev != BUTTON_EVENT_NONE) {
|
||||
if (!_display->isOn()) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
@@ -403,6 +555,7 @@ void UITask::loop() {
|
||||
// TODO: any action ?
|
||||
} else {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
#ifdef DISPLAY_REDRAW_ON_CHANGE
|
||||
_frame_valid = false;
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,8 @@ class UITask {
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
unsigned long _started_at = 0;
|
||||
uint32_t _radio_profile_page_started_at = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
#ifdef DISPLAY_TOUCH_TOGGLE
|
||||
unsigned long _powering_off_at = 0;
|
||||
#endif
|
||||
@@ -61,6 +63,8 @@ class UITask {
|
||||
uint8_t _flip_seen = 0xFF; // 0xFF forces the first apply
|
||||
void applyDisplayFlip();
|
||||
|
||||
void resetRadioProfileDisplayPage();
|
||||
bool showingSecondaryRadioProfilePage();
|
||||
|
||||
void renderCurrScreen();
|
||||
public:
|
||||
|
||||
@@ -243,3 +243,7 @@ private:
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
// The display implementation is kept independent of the sketch-local MyMesh
|
||||
// subclass, while still needing its configured radio profiles.
|
||||
SensorMesh& activeSensorMesh();
|
||||
@@ -2,6 +2,57 @@
|
||||
#include "target.h"
|
||||
#include <Arduino.h>
|
||||
#include <helpers/CommonCLI.h>
|
||||
#include <helpers/ui/RadioProfileDisplayPage.h>
|
||||
#include <helpers/ui/RadioProfileSystemStatus.h>
|
||||
#include <RadioProfiles.h>
|
||||
#include "SensorMesh.h"
|
||||
|
||||
namespace {
|
||||
|
||||
const mesh::RadioProfiles* configuredRadioProfiles() {
|
||||
const auto* radio = activeSensorMesh().getProfileRadio();
|
||||
return radio ? radio->profiles() : NULL;
|
||||
}
|
||||
|
||||
mesh::ui::RadioProfileSystemStatus radioProfileSystemStatus(
|
||||
const NodePrefs& prefs) {
|
||||
mesh::ui::RadioProfileSystemStatus status;
|
||||
const auto* profiles = configuredRadioProfiles();
|
||||
status.public_key = activeSensorMesh().getSelfId().pub_key;
|
||||
status.powersaving_enabled = prefs.powersaving_enabled != 0;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
status.gps_enabled = prefs.gps_enabled != 0;
|
||||
#endif
|
||||
status.fem_enabled = board.canControlLoRaFemLna()
|
||||
&& board.isLoRaFemLnaEnabled();
|
||||
status.rx_boosted_gain = prefs.rx_boosted_gain != 0;
|
||||
status.rx_powersaving_enabled = prefs.rx_powersaving_enabled != 0;
|
||||
status.cad_enabled = prefs.cad_enabled != 0;
|
||||
status.dual_radio_enabled = profiles != NULL && profiles->enabled();
|
||||
if (status.dual_radio_enabled) {
|
||||
status.secondary_temporary = profiles->secondary_temporary;
|
||||
status.secondary_mode = profiles->secondary.mode;
|
||||
status.cross = profiles->cross;
|
||||
}
|
||||
status.noise_floor_1 = radio_driver.getNoiseFloorDbm(0);
|
||||
status.noise_floor_1_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(0);
|
||||
if (status.dual_radio_enabled) {
|
||||
status.noise_floor_2 = radio_driver.getNoiseFloorDbm(1);
|
||||
status.noise_floor_2_seconds =
|
||||
radio_driver.getNoiseFloorCalibrationSecondsRemaining(1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t radioProfileStatusPageCount(DisplayDriver& display,
|
||||
bool dual_radio_enabled) {
|
||||
display.setTextSize(1);
|
||||
return mesh::ui::radioProfileSystemStatusPageCount(display,
|
||||
dual_radio_enabled);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
#ifndef USER_BTN_PRESSED
|
||||
#define USER_BTN_PRESSED LOW
|
||||
@@ -29,6 +80,7 @@ static const uint8_t meshcore_logo [] PROGMEM = {
|
||||
void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version) {
|
||||
_prevBtnState = HIGH;
|
||||
_node_prefs = node_prefs;
|
||||
resetRadioProfileDisplayPage();
|
||||
_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected());
|
||||
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) \
|
||||
&& defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
@@ -49,6 +101,25 @@ void UITask::begin(NodePrefs* node_prefs, const char* build_date, const char* fi
|
||||
free(version);
|
||||
}
|
||||
|
||||
void UITask::resetRadioProfileDisplayPage() {
|
||||
_radio_profile_page_started_at = millis();
|
||||
_dual_radio_enabled_seen = activeSensorMesh().isDualRadioActive();
|
||||
}
|
||||
|
||||
bool UITask::showingSecondaryRadioProfilePage() {
|
||||
const bool dual_radio_enabled = activeSensorMesh().isDualRadioActive();
|
||||
const uint32_t now = millis();
|
||||
if (dual_radio_enabled != _dual_radio_enabled_seen) {
|
||||
_dual_radio_enabled_seen = dual_radio_enabled;
|
||||
_radio_profile_page_started_at = now;
|
||||
}
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(*_display,
|
||||
dual_radio_enabled);
|
||||
return mesh::ui::showSecondaryRadioProfilePage(dual_radio_enabled,
|
||||
status_pages,
|
||||
now - _radio_profile_page_started_at);
|
||||
}
|
||||
|
||||
void UITask::renderCurrScreen() {
|
||||
char tmp[80];
|
||||
if (millis() < BOOT_SCREEN_MILLIS) { // boot screen
|
||||
@@ -77,26 +148,66 @@ void UITask::renderCurrScreen() {
|
||||
_display->setCursor((_display->width() - typeWidth) / 2, 48);
|
||||
_display->print(node_type);
|
||||
} else { // home screen
|
||||
const bool dual_radio_enabled = activeSensorMesh().isDualRadioActive();
|
||||
const uint8_t status_pages = radioProfileStatusPageCount(
|
||||
*_display, dual_radio_enabled);
|
||||
uint8_t status_page_index = 0;
|
||||
if (mesh::ui::showRadioProfileSystemStatusPage(dual_radio_enabled,
|
||||
status_pages, millis() - _radio_profile_page_started_at,
|
||||
&status_page_index)) {
|
||||
mesh::ui::drawRadioProfileSystemStatusPage(*_display,
|
||||
radioProfileSystemStatus(*_node_prefs), status_page_index);
|
||||
return;
|
||||
}
|
||||
// node name
|
||||
_display->setCursor(0, 0);
|
||||
_display->setTextSize(1);
|
||||
_display->setColor(UIColor::primary_txt);
|
||||
_display->print(_node_prefs->node_name);
|
||||
|
||||
// freq / sf
|
||||
const mesh::RadioProfiles* profiles = configuredRadioProfiles();
|
||||
const bool secondary_page = showingSecondaryRadioProfilePage();
|
||||
const bool dual_radio = profiles != NULL && profiles->enabled();
|
||||
float freq = _node_prefs->freq;
|
||||
float bw = _node_prefs->bw;
|
||||
uint8_t sf = _node_prefs->sf;
|
||||
uint8_t cr = _node_prefs->cr;
|
||||
const char* profile_tag = "";
|
||||
if (dual_radio) {
|
||||
const uint8_t profile = secondary_page ? 1 : 0;
|
||||
const auto& params = profiles->params(profile);
|
||||
freq = params.freq;
|
||||
bw = params.bw;
|
||||
sf = params.sf;
|
||||
cr = params.cr;
|
||||
profile_tag = mesh::ui::radioProfileDisplayTag(profile,
|
||||
profile == 1 ? profiles->secondary_temporary : profiles->primary_temporary);
|
||||
}
|
||||
|
||||
// Compact R1/R2 rows preserve every RF field on 128px displays.
|
||||
_display->setCursor(0, 20);
|
||||
sprintf(tmp, "FREQ: %06.3f SF%d", _node_prefs->freq, _node_prefs->sf);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s F:%06.3f S:%d", profile_tag, freq, sf);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "FREQ: %06.3f SF%d", freq, sf);
|
||||
}
|
||||
_display->print(tmp);
|
||||
|
||||
// bw / cr
|
||||
_display->setCursor(0, 30);
|
||||
sprintf(tmp, "BW: %03.2f CR: %d", _node_prefs->bw, _node_prefs->cr);
|
||||
if (dual_radio) {
|
||||
snprintf(tmp, sizeof(tmp), "%s B:%03.2f C:%d", profile_tag, bw, cr);
|
||||
} else {
|
||||
snprintf(tmp, sizeof(tmp), "BW: %03.2f CR: %d", bw, cr);
|
||||
}
|
||||
_display->print(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void UITask::loop() {
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) _next_refresh = 0;
|
||||
if (_display->servicePower(board.isExternalPowered() || board.isUsbHostConnected())) {
|
||||
resetRadioProfileDisplayPage();
|
||||
_next_refresh = 0;
|
||||
}
|
||||
#if defined(PIN_USER_BTN) && defined(DISPLAY_CLASS) \
|
||||
&& defined(MOMENTARY_BUTTON_WAKE_FROM_SLEEP) \
|
||||
&& MOMENTARY_BUTTON_WAKE_FROM_SLEEP
|
||||
@@ -104,6 +215,7 @@ void UITask::loop() {
|
||||
if (ev != BUTTON_EVENT_NONE) {
|
||||
if (!_display->isOn()) {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
_next_refresh = 0;
|
||||
}
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
@@ -117,6 +229,7 @@ void UITask::loop() {
|
||||
// TODO: any action ?
|
||||
} else {
|
||||
_display->wake(mesh::ui::DisplayWake::Button);
|
||||
resetRadioProfileDisplayPage();
|
||||
}
|
||||
_display->wake(mesh::ui::DisplayWake::Button); // extend auto-off timer
|
||||
}
|
||||
|
||||
@@ -9,11 +9,15 @@ class UITask {
|
||||
int _prevBtnState;
|
||||
NodePrefs* _node_prefs;
|
||||
char _version_info[32];
|
||||
uint32_t _radio_profile_page_started_at = 0;
|
||||
bool _dual_radio_enabled_seen = false;
|
||||
|
||||
void resetRadioProfileDisplayPage();
|
||||
bool showingSecondaryRadioProfilePage();
|
||||
void renderCurrScreen();
|
||||
public:
|
||||
UITask(DisplayDriver& display) : _display(&display) { _next_read = _next_refresh = 0; }
|
||||
void begin(NodePrefs* node_prefs, const char* build_date, const char* firmware_version);
|
||||
|
||||
void loop();
|
||||
};
|
||||
};
|
||||
@@ -52,6 +52,10 @@ SimpleMeshTables tables;
|
||||
|
||||
MyMesh the_mesh(board, radio_driver, *new ArduinoMillis(), fast_rng, rtc_clock, tables);
|
||||
|
||||
SensorMesh& activeSensorMesh() {
|
||||
return the_mesh;
|
||||
}
|
||||
|
||||
void halt() {
|
||||
while (1) ;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user