From 619cda7aeba25350db1997b674039d410cf7c296 Mon Sep 17 00:00:00 2001 From: Federico Amedeo Izzo Date: Sun, 14 Feb 2021 13:55:33 +0100 Subject: [PATCH] Turn off GPS when it's turned off in settings --- openrtx/src/ui/ui.c | 32 ++++++++++++++++++++------------ openrtx/src/ui/ui_menu.c | 21 ++++++++++----------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index a9652103..eca96127 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -67,6 +67,7 @@ #include #include #include +#include #include #include #include @@ -1046,23 +1047,30 @@ void ui_updateFSM(event_t event, bool *sync_rtx) _ui_menuBack(MENU_SETTINGS); break; case SETTINGS_GPS: - if(msg.keys & KEY_LEFT || (msg.keys & KEY_UP && ui_state.edit_mode)) + if(msg.keys & KEY_LEFT || msg.keys & KEY_RIGHT || + ((msg.keys & KEY_UP || msg.keys & KEY_DOWN) && ui_state.edit_mode)) { if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Enabled") == 0) - state.settings.gps_enabled = !state.settings.gps_enabled; + { + // Disable or Enable GPS to stop or start GPS thread + if(state.settings.gps_enabled) + { + state.settings.gps_enabled = !state.settings.gps_enabled; + gps_disable(); + } + else + { + state.settings.gps_enabled = !state.settings.gps_enabled; + gps_enable(); + } + } else if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Set Time") == 0) state.settings.gps_set_time = !state.settings.gps_set_time; else if(strcmp(settings_gps_items[ui_state.menu_selected], "UTC Timezone") == 0) - state.settings.utc_timezone -= 1; - } - else if(msg.keys & KEY_RIGHT || (msg.keys & KEY_DOWN && ui_state.edit_mode)) - { - if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Enabled") == 0) - state.settings.gps_enabled = !state.settings.gps_enabled; - else if(strcmp(settings_gps_items[ui_state.menu_selected], "GPS Set Time") == 0) - state.settings.gps_set_time = !state.settings.gps_set_time; - else if(strcmp(settings_gps_items[ui_state.menu_selected], "UTC Timezone") == 0) - state.settings.utc_timezone += 1; + if(msg.keys & KEY_LEFT || msg.keys & KEY_UP) + state.settings.utc_timezone -= 1; + else if(msg.keys & KEY_RIGHT || msg.keys & KEY_DOWN) + state.settings.utc_timezone += 1; } else if(msg.keys & KEY_UP) _ui_menuUp(settings_gps_num); diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 72fd8732..fca25712 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -146,11 +146,13 @@ int _ui_getSettingsGPSValueName(char *buf, uint8_t max_len, uint8_t index) else if(strcmp(settings_gps_items[index], "GPS Set Time") == 0) snprintf(buf, max_len, "%s", (last_state.settings.gps_set_time) ? "ON" : "OFF"); else if(strcmp(settings_gps_items[index], "UTC Timezone") == 0) + { // Add + prefix to positive numbers if(last_state.settings.utc_timezone > 0) snprintf(buf, max_len, "+%d", last_state.settings.utc_timezone); else snprintf(buf, max_len, "%d", last_state.settings.utc_timezone); + } return 0; } @@ -270,18 +272,15 @@ void _ui_drawMenuGPS(ui_state_t* ui_state) // Print "GPS" on top bar gfx_print(layout.top_pos, "GPS", layout.top_font, TEXT_ALIGN_CENTER, color_white); + point_t fix_pos = {layout.line2_pos.x, SCREEN_HEIGHT * 2 / 5}; // Print GPS status, if no fix, hide details - if (last_state.gps_data.fix_quality == 0) - { - point_t fix_pos = {layout.line2_pos.x, SCREEN_HEIGHT * 2 / 5}; - gfx_print(fix_pos, "No Fix", layout.line3_font, TEXT_ALIGN_CENTER, - color_white); - } else if (last_state.gps_data.fix_quality == 6) - { - point_t fix_pos = {layout.line2_pos.x, SCREEN_HEIGHT * 2 / 5}; - gfx_print(fix_pos, "Fix Lost", layout.line3_font, TEXT_ALIGN_CENTER, - color_white); - } else + if(!last_state.settings.gps_enabled) + gfx_print(fix_pos, "GPS OFF", layout.line3_font, TEXT_ALIGN_CENTER, color_white); + else if (last_state.gps_data.fix_quality == 0) + gfx_print(fix_pos, "No Fix", layout.line3_font, TEXT_ALIGN_CENTER, color_white); + else if (last_state.gps_data.fix_quality == 6) + gfx_print(fix_pos, "Fix Lost", layout.line3_font, TEXT_ALIGN_CENTER, color_white); + else { switch(last_state.gps_data.fix_quality) {