Add state_terminate() that saves settings to flash

This commit is contained in:
Federico Amedeo Izzo 2021-02-21 16:44:31 +01:00
parent d4981ee288
commit 35bde9bccb
3 changed files with 19 additions and 0 deletions

View File

@ -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.

View File

@ -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)

View File

@ -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)