diff --git a/applications/main/subghz/helpers/subghz_gps.c b/applications/main/subghz/helpers/subghz_gps.c index 8b468efbd..88df096e1 100644 --- a/applications/main/subghz/helpers/subghz_gps.c +++ b/applications/main/subghz/helpers/subghz_gps.c @@ -132,7 +132,6 @@ SubGhzGPS* subghz_gps_init() { } furi_hal_uart_set_irq_cb(UART_CH, subghz_gps_uart_on_irq_cb, subghz_gps); - furi_hal_uart_set_br(UART_CH, 9600); return subghz_gps; } @@ -160,6 +159,10 @@ void subghz_gps_stop(SubGhzGPS* subghz_gps) { furi_thread_join(subghz_gps->thread); } +void subghz_gps_set_baudrate(uint32_t baudrate) { + furi_hal_uart_set_br(UART_CH, baudrate); +} + double subghz_gps_deg2rad(double deg) { return (deg * (double)M_PI / 180); } diff --git a/applications/main/subghz/helpers/subghz_gps.h b/applications/main/subghz/helpers/subghz_gps.h index ffab8637f..6408a040d 100644 --- a/applications/main/subghz/helpers/subghz_gps.h +++ b/applications/main/subghz/helpers/subghz_gps.h @@ -61,6 +61,14 @@ void subghz_gps_start(SubGhzGPS* subghz_gps); */ void subghz_gps_stop(SubGhzGPS* subghz_gps); +/** + * Set baudrate for GPS + * + * @param baudrate Baudrate + * @return void +*/ +void subghz_gps_set_baudrate(uint32_t baudrate); + /** * Convert degree to radian * diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index c98e6592f..5ffd2f224 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -32,10 +32,14 @@ const char* const debug_pin_text[DEBUG_P_COUNT] = { "17(1W)", }; -#define GPS_COUNT 2 +#define GPS_COUNT 6 const char* const gps_text[GPS_COUNT] = { "OFF", - "ON", + "9600", + "19200", + "38400", + "57600", + "115200", }; #define DEBUG_COUNTER_COUNT 13 @@ -127,11 +131,30 @@ static void subghz_scene_receiver_config_set_gps(VariableItem* item) { variable_item_set_current_value_text(item, gps_text[index]); - subghz->last_settings->gps_enabled = index == 1; - subghz_last_settings_save( - subghz->last_settings); //TODO, make it to choose baudrate. now it is 9600 + switch(index) { + case 0: + subghz->last_settings->gps_baudrate = 0; + break; + case 1: + subghz->last_settings->gps_baudrate = 9600; + break; + case 2: + subghz->last_settings->gps_baudrate = 19200; + break; + case 3: + subghz->last_settings->gps_baudrate = 38400; + break; + case 4: + subghz->last_settings->gps_baudrate = 57600; + break; + case 5: + subghz->last_settings->gps_baudrate = 115200; + break; + } + subghz_last_settings_save(subghz->last_settings); - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { + subghz_gps_set_baudrate(subghz->last_settings->gps_baudrate); subghz_gps_start(subghz->gps); } else { subghz_gps_stop(subghz->gps); @@ -181,8 +204,15 @@ void subghz_scene_radio_settings_on_enter(void* context) { variable_item_set_current_value_text(item, ext_mod_power_amp_text[value_index]); item = variable_item_list_add( - variable_item_list, "GPS", GPS_COUNT, subghz_scene_receiver_config_set_gps, subghz); - value_index = subghz->last_settings->gps_enabled ? 1 : 0; + variable_item_list, + "GPS Baudrate", + GPS_COUNT, + subghz_scene_receiver_config_set_gps, + subghz); + value_index = value_index_uint32( + subghz->last_settings->gps_baudrate, + (const uint32_t[]){0, 9600, 19200, 38400, 57600, 115200}, + GPS_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, gps_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index ff8613f0d..25267a6c4 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -290,7 +290,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { SubGhzThresholdRssiData ret_rssi = subghz_threshold_get_rssi_data( subghz->threshold_rssi, subghz_txrx_radio_device_get_rssi(subghz->txrx)); - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { FuriHalRtcDateTime datetime; furi_hal_rtc_get_datetime(&datetime); if((datetime.second - subghz->gps->fix_second) > 15) { @@ -310,7 +310,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { switch(subghz->state_notifications) { case SubGhzNotificationStateRx: - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { if(subghz->gps->satellites > 0) { notification_message(subghz->notifications, &sequence_blink_green_10); } else { diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 739005861..b3c7df131 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -19,7 +19,7 @@ void subghz_scene_receiver_info_callback(GuiButtonType result, InputType type, v subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoSave); } else if( (result == GuiButtonTypeLeft) && (type == InputTypeShort) && - subghz->last_settings->gps_enabled) { + subghz->last_settings->gps_baudrate != 0) { view_dispatcher_send_custom_event( subghz->view_dispatcher, SubGhzCustomEventSceneReceiverInfoSats); } @@ -81,7 +81,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { widget_add_string_multiline_element( subghz->widget, 0, 0, AlignLeft, AlignTop, FontSecondary, furi_string_get_cstr(text)); - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { widget_add_button_element( subghz->widget, GuiButtonTypeLeft, @@ -185,7 +185,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) } return true; } else if(event.event == SubGhzCustomEventSceneReceiverInfoSats) { - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowGps); return true; } else { @@ -201,7 +201,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) notification_message(subghz->notifications, &sequence_blink_magenta_10); break; case SubGhzNotificationStateRx: - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { if(subghz->gps->satellites > 0) { notification_message(subghz->notifications, &sequence_blink_green_10); } else { diff --git a/applications/main/subghz/scenes/subghz_scene_saved_show_gps.c b/applications/main/subghz/scenes/subghz_scene_saved_show_gps.c index 968a02a83..fa085888d 100644 --- a/applications/main/subghz/scenes/subghz_scene_saved_show_gps.c +++ b/applications/main/subghz/scenes/subghz_scene_saved_show_gps.c @@ -80,7 +80,7 @@ void subghz_scene_saved_show_gps_on_enter(void* context) { subghz_scene_saved_show_gps_draw_satellites(subghz); - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { subghz->gps->timer = furi_timer_alloc( subghz_scene_saved_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz); furi_timer_start(subghz->gps->timer, 1000); @@ -98,7 +98,7 @@ bool subghz_scene_saved_show_gps_on_event(void* context, SceneManagerEvent event void subghz_scene_saved_show_gps_on_exit(void* context) { SubGhz* subghz = context; - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { furi_timer_stop(subghz->gps->timer); furi_timer_free(subghz->gps->timer); } diff --git a/applications/main/subghz/scenes/subghz_scene_show_gps.c b/applications/main/subghz/scenes/subghz_scene_show_gps.c index 23eea6100..ef3d18709 100644 --- a/applications/main/subghz/scenes/subghz_scene_show_gps.c +++ b/applications/main/subghz/scenes/subghz_scene_show_gps.c @@ -106,7 +106,7 @@ void subghz_scene_show_gps_on_enter(void* context) { subghz_scene_show_gps_draw_satellites(subghz); - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { subghz->gps->timer = furi_timer_alloc(subghz_scene_show_gps_refresh_screen, FuriTimerTypePeriodic, subghz); furi_timer_start(subghz->gps->timer, 1000); @@ -117,7 +117,7 @@ bool subghz_scene_show_gps_on_event(void* context, SceneManagerEvent event) { SubGhz* subghz = context; if(event.type == SceneManagerEventTypeTick) { if(subghz->state_notifications == SubGhzNotificationStateRx) { - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { if(subghz->gps->satellites > 0) { notification_message(subghz->notifications, &sequence_blink_green_10); } else { @@ -134,7 +134,7 @@ bool subghz_scene_show_gps_on_event(void* context, SceneManagerEvent event) { void subghz_scene_show_gps_on_exit(void* context) { SubGhz* subghz = context; - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { furi_timer_stop(subghz->gps->timer); furi_timer_free(subghz->gps->timer); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index fa80e0ea8..744ffc756 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -245,7 +245,8 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->error_str = furi_string_alloc(); subghz->gps = subghz_gps_init(); - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { + subghz_gps_set_baudrate(subghz->last_settings->gps_baudrate); subghz_gps_start(subghz->gps); } @@ -344,7 +345,7 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { furi_string_free(subghz->file_path_tmp); // GPS - if(subghz->last_settings->gps_enabled) { + if(subghz->last_settings->gps_baudrate != 0) { subghz_gps_stop(subghz->gps); } subghz_gps_deinit(subghz->gps); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 74922aa67..dc4e3a5ff 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -56,7 +56,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool ignore_filter_was_read = false; bool frequency_analyzer_feedback_level_was_read = false; bool frequency_analyzer_trigger_was_read = false; - bool temp_gps_enabled = false; + uint32_t temp_gps_baudrate = 0; if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { @@ -94,8 +94,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, (bool*)&temp_external_module_power_amp, 1); - flipper_format_read_bool( - fff_data_file, SUBGHZ_LAST_SETTING_FIELD_GPS, (bool*)&temp_gps_enabled, 1); + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_GPS, (uint32_t*)&temp_gps_baudrate, 1); flipper_format_read_bool( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE, @@ -125,7 +125,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_enabled = false; instance->timestamp_file_names = false; instance->external_module_power_amp = false; - instance->gps_enabled = false; + instance->gps_baudrate = 0; instance->enable_hopping = false; instance->ignore_filter = 0x00; // See bin_raw_value in applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -181,7 +181,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count // Set globally in furi hal furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); - instance->gps_enabled = temp_gps_enabled; + instance->gps_baudrate = temp_gps_baudrate; } flipper_format_file_close(fff_data_file); @@ -261,8 +261,8 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { 1)) { break; } - if(!flipper_format_insert_or_update_bool( - file, SUBGHZ_LAST_SETTING_FIELD_GPS, &instance->gps_enabled, 1)) { + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_GPS, &instance->gps_baudrate, 1)) { break; } if(!flipper_format_insert_or_update_bool( @@ -313,7 +313,7 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) { FURI_LOG_I( TAG, "Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s,\n" - "Hopping: %s,\nPreset: %ld, RSSI: %.2f, " + "GPSBaudrate: %ld, Hopping: %s,\nPreset: %ld, RSSI: %.2f, " "Starline: %s, Cars: %s, Magellan: %s, BinRAW: %s", instance->frequency / 1000000 % 1000, instance->frequency / 10000 % 100, @@ -323,6 +323,7 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) { bool_to_char(instance->external_module_power_5v_disable), bool_to_char(instance->timestamp_file_names), bool_to_char(instance->external_module_power_amp), + instance->gps_baudrate, bool_to_char(instance->enable_hopping), instance->preset_index, (double)instance->rssi, diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index b292f0b06..c5a46946e 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -26,7 +26,7 @@ typedef struct { bool external_module_power_amp; // saved so as not to change the version bool timestamp_file_names; - bool gps_enabled; + uint32_t gps_baudrate; bool enable_hopping; uint32_t ignore_filter; uint32_t filter;