diff --git a/applications/main/subghz/helpers/subghz_gps.c b/applications/main/subghz/helpers/subghz_gps.c index 62ca596469..14976b3067 100644 --- a/applications/main/subghz/helpers/subghz_gps.c +++ b/applications/main/subghz/helpers/subghz_gps.c @@ -1,7 +1,6 @@ #include "subghz_gps.h" #include "minmea.h" -#include #include #define UART_CH (momentum_settings.uart_nmea_channel) @@ -128,15 +127,13 @@ static int32_t subghz_gps_uart_worker(void* context) { static void subghz_gps_deinit(SubGhzGPS* subghz_gps) { furi_assert(subghz_gps); + furi_thread_flags_set(furi_thread_get_id(subghz_gps->thread), WorkerEvtStop); + furi_thread_join(subghz_gps->thread); + furi_hal_serial_async_rx_stop(subghz_gps->serial_handle); furi_hal_serial_deinit(subghz_gps->serial_handle); furi_hal_serial_control_release(subghz_gps->serial_handle); - expansion_enable(furi_record_open(RECORD_EXPANSION)); - furi_record_close(RECORD_EXPANSION); - - furi_thread_flags_set(furi_thread_get_id(subghz_gps->thread), WorkerEvtStop); - furi_thread_join(subghz_gps->thread); furi_thread_free(subghz_gps->thread); furi_stream_buffer_free(subghz_gps->rx_stream); @@ -220,9 +217,6 @@ static void subghz_gps_init(SubGhzGPS* subghz_gps, uint32_t baudrate) { furi_thread_alloc_ex("SubGhzGPSWorker", 1024, subghz_gps_uart_worker, subghz_gps); furi_thread_start(subghz_gps->thread); - expansion_disable(furi_record_open(RECORD_EXPANSION)); - furi_record_close(RECORD_EXPANSION); - subghz_gps->serial_handle = furi_hal_serial_control_acquire(UART_CH); furi_check(subghz_gps->serial_handle); furi_hal_serial_init(subghz_gps->serial_handle, baudrate); diff --git a/applications/main/subghz/helpers/subghz_gps_plugin.c b/applications/main/subghz/helpers/subghz_gps_plugin.c index 0f41d0b380..3651000657 100644 --- a/applications/main/subghz/helpers/subghz_gps_plugin.c +++ b/applications/main/subghz/helpers/subghz_gps_plugin.c @@ -11,6 +11,9 @@ SubGhzGPS* subghz_gps_plugin_init(uint32_t baudrate) { furi_record_close(RECORD_EXPANSION); if(connected) return NULL; + expansion_disable(furi_record_open(RECORD_EXPANSION)); + furi_record_close(RECORD_EXPANSION); + Storage* storage = furi_record_open(RECORD_STORAGE); FlipperApplication* plugin_app = flipper_application_alloc(storage, firmware_api_interface); do { @@ -60,6 +63,9 @@ SubGhzGPS* subghz_gps_plugin_init(uint32_t baudrate) { } while(false); flipper_application_free(plugin_app); furi_record_close(RECORD_STORAGE); + + expansion_enable(furi_record_open(RECORD_EXPANSION)); + furi_record_close(RECORD_EXPANSION); return NULL; } @@ -68,4 +74,7 @@ void subghz_gps_plugin_deinit(SubGhzGPS* subghz_gps) { flipper_application_free(subghz_gps->plugin_app); free(subghz_gps); furi_record_close(RECORD_STORAGE); + + expansion_enable(furi_record_open(RECORD_EXPANSION)); + furi_record_close(RECORD_EXPANSION); } diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 0483f6c2b9..f293bc86c7 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -153,18 +153,12 @@ static void subghz_scene_receiver_config_set_gps(VariableItem* item) { } subghz_last_settings_save(subghz->last_settings); + if(subghz->gps) { + subghz_gps_plugin_deinit(subghz->gps); + subghz->gps = NULL; + } if(subghz->last_settings->gps_baudrate != 0) { - if(subghz->gps) { - furi_hal_serial_set_br( - subghz->gps->serial_handle, subghz->last_settings->gps_baudrate); - } else { - subghz->gps = subghz_gps_plugin_init(subghz->last_settings->gps_baudrate); - } - } else { - if(subghz->gps) { - subghz_gps_plugin_deinit(subghz->gps); - subghz->gps = NULL; - } + subghz->gps = subghz_gps_plugin_init(subghz->last_settings->gps_baudrate); } }