From c91e3060261b0247cfeeccc942d2e2547c7a88c6 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Mon, 8 Nov 2021 21:44:33 +0100 Subject: [PATCH] Reorganised settings data structure --- openrtx/include/settings.h | 18 +++++++++--------- openrtx/include/state.h | 4 +--- openrtx/src/gps.c | 4 ++-- openrtx/src/state.c | 4 ++-- openrtx/src/threads.c | 2 +- openrtx/src/ui/ui.c | 24 ++++++++++++++++-------- openrtx/src/ui/ui_main.c | 2 +- openrtx/src/ui/ui_menu.c | 2 +- 8 files changed, 33 insertions(+), 27 deletions(-) diff --git a/openrtx/include/settings.h b/openrtx/include/settings.h index d73c0db1..6be470f9 100644 --- a/openrtx/include/settings.h +++ b/openrtx/include/settings.h @@ -25,29 +25,29 @@ typedef struct { - uint8_t valid[7]; // Should contain "OPNRTX" in a valid settings_t - uint8_t brightness; - uint8_t contrast; - int8_t utc_timezone; - bool gps_enabled; - bool gps_set_time; - char callsign[10]; // Plaintext callsign, for future use + uint8_t brightness; // Display brightness + uint8_t contrast; // Display contrast + uint8_t sqlLevel; // Squelch level + uint8_t voxLevel; // Vox level + int8_t utc_timezone; // Timezone + bool gps_enabled; // GPS active + char callsign[10]; // Plaintext callsign, for future use } __attribute__((packed)) settings_t; static const settings_t default_settings = { - "OPNRTX", // Settings valid string 255, // Brightness #ifdef SCREEN_CONTRAST DEFAULT_CONTRAST, // Contrast #else 255, // Contrast #endif + 4, // Squelch level, 4 = S3 + 0, // Vox level 0, // UTC Timezone false, // GPS enabled - true, // GPS set time "" // Empty callsign }; diff --git a/openrtx/include/state.h b/openrtx/include/state.h index 0a167cbe..e121bc0e 100644 --- a/openrtx/include/state.h +++ b/openrtx/include/state.h @@ -98,13 +98,11 @@ typedef struct bool zone_enabled; zone_t zone; uint8_t rtxStatus; - // Squelch steps from 0 to 15 - uint8_t sqlLevel; - uint8_t voxLevel; bool emergency; settings_t settings; gps_t gps_data; + bool gps_set_time; m17_t m17_data; } state_t; diff --git a/openrtx/src/gps.c b/openrtx/src/gps.c index a53c7e99..4894db18 100644 --- a/openrtx/src/gps.c +++ b/openrtx/src/gps.c @@ -36,7 +36,7 @@ void gps_taskFunc(char *line, __attribute__((unused)) int len, state_t *state) // Little mechanism to ensure that RTC is synced with GPS time only once. static bool isRtcSyncronised = false; - if(!state->settings.gps_set_time) + if(!state->gps_set_time) { isRtcSyncronised = false; } @@ -67,7 +67,7 @@ void gps_taskFunc(char *line, __attribute__((unused)) int len, state_t *state) } // Synchronize RTC with GPS UTC clock, only when fix is done - if((state->settings.gps_set_time) && + if((state->gps_set_time) && (state->gps_data.fix_quality > 0) && (!isRtcSyncronised)) { rtc_setTime(state->gps_data.timestamp); diff --git a/openrtx/src/state.c b/openrtx/src/state.c index 4b34ca31..9717f5c8 100644 --- a/openrtx/src/state.c +++ b/openrtx/src/state.c @@ -72,8 +72,8 @@ void state_init() } state.zone_enabled = false; state.rtxStatus = RTX_OFF; - state.sqlLevel = 4; // Default Squelch: S3 = 4 - state.voxLevel = 0; + state.settings.sqlLevel = 4; // Default Squelch: S3 = 4 + state.settings.voxLevel = 0; state.emergency = false; diff --git a/openrtx/src/threads.c b/openrtx/src/threads.c index fe68c373..0d54f11f 100644 --- a/openrtx/src/threads.c +++ b/openrtx/src/threads.c @@ -97,7 +97,7 @@ void *ui_task(void *arg) rtx_cfg.rxFrequency = state.channel.rx_frequency; rtx_cfg.txFrequency = state.channel.tx_frequency; rtx_cfg.txPower = state.channel.power; - rtx_cfg.sqlLevel = state.sqlLevel; + rtx_cfg.sqlLevel = state.settings.sqlLevel; rtx_cfg.rxToneEn = state.channel.fm.rxToneEn; rtx_cfg.rxTone = ctcss_tone[state.channel.fm.rxTone]; rtx_cfg.txToneEn = state.channel.fm.txToneEn; diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 6ae794d3..0947fb40 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -704,18 +704,26 @@ void _ui_fsm_menuMacro(kbd_msg_t msg, bool *sync_rtx) { #ifdef HAS_ABSOLUTE_KNOB // If the radio has an absolute position knob if(msg.keys & KNOB_LEFT || msg.keys & KNOB_RIGHT) { - state.sqlLevel = platform_getChSelector() - 1; + state.settings.sqlLevel = platform_getChSelector() - 1; *sync_rtx = true; } #else // Use left and right buttons or relative position knob // NOTE: Use up and down for UV380 which has not yet a functional knob - if(msg.keys & KEY_LEFT || msg.keys & KEY_DOWN || msg.keys & KNOB_LEFT) { - state.sqlLevel = (state.sqlLevel == 0) ? 0 : state.sqlLevel - 1; - *sync_rtx = true; + if(msg.keys & KEY_LEFT || msg.keys & KEY_DOWN || msg.keys & KNOB_LEFT) + { + if(state.settings.sqlLevel > 0) + { + state.settings.sqlLevel -= 1; + *sync_rtx = true; + } } - else if(msg.keys & KEY_RIGHT || msg.keys & KEY_UP || msg.keys & KNOB_RIGHT) { - state.sqlLevel = (state.sqlLevel == 15) ? 15 : state.sqlLevel + 1; - *sync_rtx = true; + else if(msg.keys & KEY_RIGHT || msg.keys & KEY_UP || msg.keys & KNOB_RIGHT) + { + if(state.settings.sqlLevel < 15) + { + state.settings.sqlLevel += 1; + *sync_rtx = true; + } } #endif } @@ -1416,7 +1424,7 @@ void ui_updateFSM(event_t event, bool *sync_rtx) } break; case G_SET_TIME: - state.settings.gps_set_time = !state.settings.gps_set_time; + state.gps_set_time = !state.gps_set_time; break; case G_TIMEZONE: if(msg.keys & KEY_LEFT || msg.keys & KEY_UP || diff --git a/openrtx/src/ui/ui_main.c b/openrtx/src/ui/ui_main.c index 02b7c147..2d98908b 100644 --- a/openrtx/src/ui/ui_main.c +++ b/openrtx/src/ui/ui_main.c @@ -154,7 +154,7 @@ void _ui_drawMainBottom() { // Squelch bar float rssi = last_state.rssi; - float squelch = last_state.sqlLevel / 16.0f; + float squelch = last_state.settings.sqlLevel / 16.0f; uint16_t meter_width = SCREEN_WIDTH - 2 * layout.horizontal_pad; uint16_t meter_height = layout.bottom_h; point_t meter_pos = { layout.horizontal_pad, diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index f413e7b4..8cc26eb8 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -160,7 +160,7 @@ int _ui_getSettingsGPSValueName(char *buf, uint8_t max_len, uint8_t index) snprintf(buf, max_len, "%s", (last_state.settings.gps_enabled) ? "ON" : "OFF"); break; case G_SET_TIME: - snprintf(buf, max_len, "%s", (last_state.settings.gps_set_time) ? "ON" : "OFF"); + snprintf(buf, max_len, "%s", (last_state.gps_set_time) ? "ON" : "OFF"); break; case G_TIMEZONE: // Add + prefix to positive numbers