From 35bde9bccb1ed1163db99eeaea8854605ce7e136 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sun, 21 Feb 2021 16:44:31 +0100 Subject: [PATCH] Add state_terminate() that saves settings to flash --- openrtx/include/state.h | 6 ++++++ openrtx/src/state.c | 6 ++++++ openrtx/src/ui/ui.c | 7 +++++++ 3 files changed, 19 insertions(+) diff --git a/openrtx/include/state.h b/openrtx/include/state.h index 141770bd..2b3b7806 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -121,6 +121,12 @@ extern state_t state; */ void state_init(); +/** + * This function terminates the Radio state, + * Saving persistent settings to flash. + */ +void state_terminate(); + /** * This function applies the selected timezone after reading the time from * the RTC. diff --git a/openrtx/src/state.c b/openrtx/src/state.c index a893e548..7d1e714a 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -90,6 +90,12 @@ void state_init() } } +void state_terminate() +{ + // Write settings to flash memory + nvm_writeSettings(&state.settings); +} + void state_applyTimezone() { if(state.time.hour + state.settings.utc_timezone >= 24) diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 29b63647..b8bc1d31 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -696,6 +696,13 @@ void ui_saveState() void ui_updateFSM(event_t event, bool *sync_rtx) { + // The volume knob has been set to OFF, shutdown the radio + if(state.v_bat <= 0) + { + state_terminate(); + platform_terminate(); + return; + } // Check if battery has enough charge to operate float charge = battery_getCharge(state.v_bat); if (!state.emergency && charge <= 0)