Moved code for radio state update to a dedicated function
This commit is contained in:
parent
91c9408f32
commit
3f2df608c9
|
|
@ -77,7 +77,6 @@ m17_t;
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
bool radioStateUpdated;
|
|
||||||
curTime_t time;
|
curTime_t time;
|
||||||
uint16_t v_bat;
|
uint16_t v_bat;
|
||||||
uint8_t charge;
|
uint8_t charge;
|
||||||
|
|
@ -131,17 +130,21 @@ extern state_t state;
|
||||||
void state_init();
|
void state_init();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write default values to OpenRTX settings and VFO Channel configuration
|
* Write default values to OpenRTX settings and VFO Channel configuration.
|
||||||
* Writes out to flash and calls state_init again to reload it immediately
|
* Writes out to flash and calls state_init again to reload it immediately.
|
||||||
*/
|
*/
|
||||||
void defaultSettingsAndVfo();
|
void defaultSettingsAndVfo();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function terminates the Radio state,
|
* This function terminates the radio state saving persistent settings to flash.
|
||||||
* Saving persistent settings to flash.
|
|
||||||
*/
|
*/
|
||||||
void state_terminate();
|
void state_terminate();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update radio state fetching data from device drivers.
|
||||||
|
*/
|
||||||
|
void state_update();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The RTC and state.time are set to UTC time
|
* The RTC and state.time are set to UTC time
|
||||||
* Use this function to get local time from UTC time based on timezone setting
|
* Use this function to get local time from UTC time based on timezone setting
|
||||||
|
|
|
||||||
|
|
@ -65,10 +65,9 @@ void state_init()
|
||||||
/*
|
/*
|
||||||
* Initialise remaining fields
|
* Initialise remaining fields
|
||||||
*/
|
*/
|
||||||
state.radioStateUpdated = true;
|
#ifdef HAS_RTC
|
||||||
#ifdef HAS_RTC
|
|
||||||
state.time = rtc_getTime();
|
state.time = rtc_getTime();
|
||||||
#endif
|
#endif
|
||||||
state.v_bat = platform_getVbat();
|
state.v_bat = platform_getVbat();
|
||||||
state.charge = battery_getCharge(state.v_bat);
|
state.charge = battery_getCharge(state.v_bat);
|
||||||
state.rssi = rtx_getRssi();
|
state.rssi = rtx_getRssi();
|
||||||
|
|
@ -95,6 +94,25 @@ void state_terminate()
|
||||||
nvm_writeSettingsAndVfo(&state.settings, &state.channel);
|
nvm_writeSettingsAndVfo(&state.settings, &state.channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void state_update()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Low-pass filtering with a time constant of 10s when updated at 1Hz
|
||||||
|
* Original computation: state.v_bat = 0.02*vbat + 0.98*state.v_bat
|
||||||
|
* Peak error is 18mV when input voltage is 49mV.
|
||||||
|
*/
|
||||||
|
uint16_t vbat = platform_getVbat();
|
||||||
|
state.v_bat -= (state.v_bat * 2) / 100;
|
||||||
|
state.v_bat += (vbat * 2) / 100;
|
||||||
|
|
||||||
|
state.charge = battery_getCharge(state.v_bat);
|
||||||
|
state.rssi = rtx_getRssi();
|
||||||
|
|
||||||
|
#ifdef HAS_RTC
|
||||||
|
state.time = rtc_getTime();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
curTime_t state_getLocalTime(curTime_t utc_time)
|
curTime_t state_getLocalTime(curTime_t utc_time)
|
||||||
{
|
{
|
||||||
curTime_t local_time = utc_time;
|
curTime_t local_time = utc_time;
|
||||||
|
|
|
||||||
|
|
@ -225,23 +225,7 @@ void *dev_task(void *arg)
|
||||||
{
|
{
|
||||||
// Lock mutex and update internal state
|
// Lock mutex and update internal state
|
||||||
pthread_mutex_lock(&state_mutex);
|
pthread_mutex_lock(&state_mutex);
|
||||||
|
state_update();
|
||||||
#ifdef HAS_RTC
|
|
||||||
state.time = rtc_getTime();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Low-pass filtering with a time constant of 10s when updated at 1Hz
|
|
||||||
* Original computation: state.v_bat = 0.02*vbat + 0.98*state.v_bat
|
|
||||||
* Peak error is 18mV when input voltage is 49mV.
|
|
||||||
*/
|
|
||||||
uint16_t vbat = platform_getVbat();
|
|
||||||
state.v_bat -= (state.v_bat * 2) / 100;
|
|
||||||
state.v_bat += (vbat * 2) / 100;
|
|
||||||
|
|
||||||
state.charge = battery_getCharge(state.v_bat);
|
|
||||||
state.rssi = rtx_getRssi();
|
|
||||||
|
|
||||||
pthread_mutex_unlock(&state_mutex);
|
pthread_mutex_unlock(&state_mutex);
|
||||||
|
|
||||||
// Signal state update to UI thread
|
// Signal state update to UI thread
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue