Added 'packed' attribute to settings data structure. Some refactoring of settings and state code.

replace/1ccc5b19fe76c12ee179fc4b5afb698e5a5c0fdd
Silvano Seva 2021-02-21 19:25:09 +01:00
rodzic 35bde9bccb
commit d0e8d15389
3 zmienionych plików z 25 dodań i 22 usunięć

Wyświetl plik

@ -30,8 +30,17 @@ typedef struct
bool gps_enabled;
bool gps_set_time;
}
settings_t;
__attribute__((packed)) settings_t;
extern const settings_t default_settings;
static const settings_t default_settings =
{
"OPNRTX", // Settings valid string
255, // Brightness
60, // Contrast
0, // UTC Timezone
false, // GPS enabled
true // GPS set time
};
#endif /* SETTINGS_H */

Wyświetl plik

@ -75,10 +75,10 @@ typedef struct
uint8_t ui_screen;
uint8_t tuner_mode;
//time_t rx_status_tv;
//bool rx_status;
//time_t tx_status_tv;
//bool tx_status;
@ -113,7 +113,7 @@ enum RtxStatus
RTX_TX
};
extern state_t state;
state_t state;
/**
* This function initializes the Radio state, acquiring the information

Wyświetl plik

@ -26,22 +26,10 @@
#include <interfaces/platform.h>
#include <interfaces/nvmem.h>
state_t state;
const settings_t default_settings =
{
"OPNRTX", // Settings valid string
255, // Brightness
60, // Contrast
0, // UTC Timezone
false, // GPS enabled
true // GPS set time
};
void state_init()
{
/*
* TODO: Read current state parameters from hardware,
* TODO: Read current state parameters from hardware,
* or initialize them to sane defaults
*/
state.radioStateUpdated = true;
@ -52,7 +40,7 @@ void state_init()
state.v_bat = platform_getVbat();
state.charge = battery_getCharge(state.v_bat);
state.rssi = rtx_getRssi();
// Set default channel index (it is 1-based)
state.channel_index = 1;
// Read VFO channel from Flash storage
@ -79,7 +67,7 @@ void state_init()
state.voxLevel = 0;
state.emergency = false;
// Read settings from flash memory
int valid = nvm_readSettings(&state.settings);
// Settings in flash memory were not valid, restoring default settings
@ -98,10 +86,16 @@ void state_terminate()
void state_applyTimezone()
{
if(state.time.hour + state.settings.utc_timezone >= 24)
if(state.time.hour + state.settings.utc_timezone >= 24)
{
state.time.hour = state.time.hour - 24 + state.settings.utc_timezone;
else if(state.time.hour + state.settings.utc_timezone < 0)
}
else if(state.time.hour + state.settings.utc_timezone < 0)
{
state.time.hour = state.time.hour + 24 + state.settings.utc_timezone;
}
else
{
state.time.hour += state.settings.utc_timezone;
}
}