From d5efd3351a57d395d0744977400185ef93b7cecd Mon Sep 17 00:00:00 2001 From: Matthew Burton <19491784+matthew73210@users.noreply.github.com> Date: Sat, 4 Jul 2026 07:42:10 +0200 Subject: [PATCH] fixed apc text on screen --- zephcore/helpers/ui/ui_headless_stubs.c | 2 + zephcore/helpers/ui/ui_task.h | 6 ++ zephcore/src/main_repeater.cpp | 73 +++++++++++++++++++------ 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/zephcore/helpers/ui/ui_headless_stubs.c b/zephcore/helpers/ui/ui_headless_stubs.c index c11a495..8112e62 100644 --- a/zephcore/helpers/ui/ui_headless_stubs.c +++ b/zephcore/helpers/ui/ui_headless_stubs.c @@ -68,6 +68,8 @@ WEAK void ui_set_radio_stats(uint32_t packets_rx, uint32_t packets_tx, ARG_UNUSED(packets_rx); ARG_UNUSED(packets_tx); ARG_UNUSED(packets_err); } +WEAK void ui_refresh_display(void) { } + WEAK void ui_set_gps_data(bool has_fix, uint8_t sats, int32_t lat_mdeg, int32_t lon_mdeg, int32_t alt_mm) { diff --git a/zephcore/helpers/ui/ui_task.h b/zephcore/helpers/ui/ui_task.h index be98a0a..334cfca 100644 --- a/zephcore/helpers/ui/ui_task.h +++ b/zephcore/helpers/ui/ui_task.h @@ -99,6 +99,12 @@ void ui_set_radio_runtime(int8_t effective_tx_power, bool apc_enabled, void ui_set_radio_stats(uint32_t packets_rx, uint32_t packets_tx, uint32_t packets_err); +/** + * Request an immediate display redraw for the current UI state. + * No-op on headless builds. + */ +void ui_refresh_display(void); + /** * Update GPS data for display. */ diff --git a/zephcore/src/main_repeater.cpp b/zephcore/src/main_repeater.cpp index f7af7f7..266e36b 100644 --- a/zephcore/src/main_repeater.cpp +++ b/zephcore/src/main_repeater.cpp @@ -141,6 +141,7 @@ K_TIMER_DEFINE(housekeeping_timer, housekeeping_timer_fn, NULL); /* Forward declarations */ #ifdef ZEPHCORE_LORA static RepeaterMesh *repeater_mesh_ptr; +static void refresh_repeater_ui_radio_state(bool redraw); #endif /* Print string to USB serial */ @@ -233,6 +234,7 @@ static void process_cli_commands(void) while (repeater_mesh_ptr && k_msgq_get(&cli_cmd_queue, &c, K_NO_WAIT) == 0) { cli_reply_buf[0] = '\0'; repeater_mesh_ptr->handleCommand(0, c.buf, cli_reply_buf); + refresh_repeater_ui_radio_state(true); if (cli_reply_buf[0] != '\0') { cli_print("\r\n -> "); cli_print(cli_reply_buf); @@ -358,6 +360,55 @@ static mesh::SimpleMeshTables mesh_tables; /* RepeaterMesh requires: board, radio, ms_clock, rng, rtc, tables */ static RepeaterMesh repeater_mesh(zephyr_board, lora_radio, ms_clock, zephyr_rng, rtc_clock, mesh_tables); + +static void refresh_repeater_ui_radio_state(bool redraw) +{ + if (!repeater_mesh_ptr) { + return; + } + + ui_set_radio_params( + lora_radio.getActiveFrequencyHz(), + lora_radio.getActiveSpreadingFactor(), + lora_radio.getActiveBandwidthKHzX10(), + lora_radio.getActiveCodingRate(), + lora_radio.getConfiguredTxPower(), + lora_radio.getNoiseFloor()); + + bool apc_enabled = false; + int8_t apc_reduction = 0; + int16_t apc_margin_x10 = 0; + uint8_t apc_target = repeater_mesh_ptr->getNodePrefs()->apc_margin; + +#ifdef CONFIG_ZEPHCORE_APC + apc_enabled = repeater_mesh_ptr->isAPCEnabled(); + apc_reduction = repeater_mesh_ptr->getAPCReduction(); + apc_margin_x10 = (int16_t)(repeater_mesh_ptr->getAPCMargin() * 10.0f); + apc_target = repeater_mesh_ptr->getAPCTargetMargin(); +#endif + + ui_set_radio_runtime( + lora_radio.getEffectiveTxPower(), + apc_enabled, + apc_reduction, + apc_margin_x10, + apc_target, + lora_radio.getActiveSyncWord(), + lora_radio.getActivePreambleLength(), + lora_radio.isRxDutyCycleEnabled(), + lora_radio.isRadioReady(), + lora_radio.isInRecvMode(), + lora_radio.isTxActive()); + + ui_set_radio_stats( + lora_radio.getPacketsRecv(), + lora_radio.getPacketsSent(), + lora_radio.getPacketsRecvErrors()); + + if (redraw) { + ui_refresh_display(); + } +} #endif /* Repeater event loop */ @@ -425,17 +476,9 @@ static void repeater_event_loop(void) ui_set_clock(rtc_clock.getCurrentTime()); #ifdef ZEPHCORE_LORA - /* Refresh radio params (noise floor changes from calibration) */ - if (repeater_mesh_ptr) { - NodePrefs *p = repeater_mesh_ptr->getNodePrefs(); - ui_set_radio_params( - (uint32_t)(p->freq * 1000000.0f + 0.5f), - p->sf, - (uint16_t)(p->bw * 10.0f + 0.5f), - p->cr, - p->tx_power_dbm, - lora_radio.getNoiseFloor()); - } + /* Refresh live radio/APC state (noise floor, TX power + * reduction, RX/TX mode, packet counters). */ + refresh_repeater_ui_radio_state(true); /* Battery is now refreshed lazily from ui_pages_render() with * a 30 s freshness guard — no periodic ADC fire here. */ @@ -588,13 +631,7 @@ int main(void) /* Feed initial UI state from loaded prefs */ ui_set_node_name(prefs->node_name); - ui_set_radio_params( - (uint32_t)(prefs->freq * 1000000.0f + 0.5f), /* MHz → Hz */ - prefs->sf, - (uint16_t)(prefs->bw * 10.0f + 0.5f), /* kHz → 0.1 kHz */ - prefs->cr, - prefs->tx_power_dbm, - lora_radio.getNoiseFloor()); + refresh_repeater_ui_radio_state(false); ui_set_battery_provider(get_battery_mv); ui_set_battery(zephyr_board.getBattMilliVolts(), 0); ui_set_gps_available(gps_is_available());