From c69b2086b0942c3c1ccd3a233b26a8a13079178d Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 19:33:45 +0300 Subject: [PATCH] SubGhz: refactoring --- .../main/subghz/helpers/subghz_txrx.c | 5 +---- .../main/subghz/helpers/subghz_txrx.h | 2 +- .../subghz/scenes/subghz_scene_read_raw.c | 8 +------ .../scenes/subghz_scene_receiver_info.c | 5 ++--- applications/main/subghz/subghz.c | 12 ----------- applications/main/subghz/subghz_i.c | 21 +++++++++++++++++++ applications/main/subghz/subghz_i.h | 7 +++---- 7 files changed, 29 insertions(+), 31 deletions(-) diff --git a/applications/main/subghz/helpers/subghz_txrx.c b/applications/main/subghz/helpers/subghz_txrx.c index c99b95e09..f400a1a52 100644 --- a/applications/main/subghz/helpers/subghz_txrx.c +++ b/applications/main/subghz/helpers/subghz_txrx.c @@ -355,12 +355,10 @@ void subghz_txrx_stop(SubGhzTxRx* instance) { case SubGhzTxRxStateTx: subghz_txrx_tx_stop(instance); subghz_txrx_speaker_unmute(instance); - //subghz_txrx_sleep(txrx); break; case SubGhzTxRxStateRx: subghz_txrx_rx_end(instance); subghz_txrx_speaker_mute(instance); - //subghz_txrx_sleep(txrx); break; default: @@ -439,7 +437,7 @@ void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance) { } } -void subghz_txrx_hopper_set_pause(SubGhzTxRx* instance) { +void subghz_txrx_hopper_pause(SubGhzTxRx* instance) { furi_assert(instance); if(instance->hopper_state == SubGhzHopperStateRunning) { instance->hopper_state = SubGhzHopperStatePause; @@ -522,7 +520,6 @@ bool subghz_txrx_load_decoder_by_name_protocol(SubGhzTxRx* instance, const char* furi_assert(instance); furi_assert(name_protocol); bool res = false; - instance->decoder_result = NULL; instance->decoder_result = subghz_receiver_search_decoder_base_by_name(instance->receiver, name_protocol); if(instance->decoder_result) { diff --git a/applications/main/subghz/helpers/subghz_txrx.h b/applications/main/subghz/helpers/subghz_txrx.h index cb50e8334..c1ef132a4 100644 --- a/applications/main/subghz/helpers/subghz_txrx.h +++ b/applications/main/subghz/helpers/subghz_txrx.h @@ -40,7 +40,7 @@ void subghz_txrx_hopper_update(SubGhzTxRx* instance); SubGhzHopperState subghz_txrx_hopper_get_state(SubGhzTxRx* instance); void subghz_txrx_hopper_set_state(SubGhzTxRx* instance, SubGhzHopperState state); void subghz_txrx_hopper_remove_pause(SubGhzTxRx* instance); -void subghz_txrx_hopper_set_pause(SubGhzTxRx* instance); +void subghz_txrx_hopper_pause(SubGhzTxRx* instance); void subghz_txrx_speaker_on(SubGhzTxRx* instance); void subghz_txrx_speaker_off(SubGhzTxRx* instance); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 298ffda06..b7131e66e 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -140,13 +140,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { } else { //Restore default setting if(subghz->raw_send_only) { - subghz_txrx_set_preset( - subghz->txrx, - "AM650", - subghz_setting_get_default_frequency( - subghz_txrx_get_setting(subghz->txrx)), - NULL, - 0); + subghz_set_defalut_preset(subghz); } else { subghz_txrx_set_preset( subghz->txrx, "AM650", subghz->last_settings->frequency, NULL, 0); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 019898025..4e0e9e26f 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -117,13 +117,12 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) SubGhz* subghz = context; if(event.type == SceneManagerEventTypeCustom) { if(event.event == SubGhzCustomEventSceneReceiverInfoTxStart) { - //CC1101 Stop RX -> Start TX - subghz_txrx_hopper_set_pause(subghz->txrx); - if(!subghz_scene_receiver_info_update_parser(subghz)) { return false; } + //CC1101 Stop RX -> Start TX + subghz_txrx_hopper_pause(subghz->txrx); if(!subghz_txrx_tx_start( subghz->txrx, subghz_history_get_raw_data(subghz->history, subghz->idx_menu_chosen))) { diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index ac6297d9e..4bf6e7aaf 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -51,16 +51,6 @@ static void subghz_rpc_command_callback(RpcAppSystemEvent event, void* context) } } -void subghz_blink_start(SubGhz* subghz) { - furi_assert(subghz); - notification_message(subghz->notifications, &sequence_blink_start_magenta); -} - -void subghz_blink_stop(SubGhz* subghz) { - furi_assert(subghz); - notification_message(subghz->notifications, &sequence_blink_stop); -} - SubGhz* subghz_alloc(bool alloc_for_tx_only) { SubGhz* subghz = malloc(sizeof(SubGhz)); @@ -274,9 +264,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->secure_data = malloc(sizeof(SecureData)); subghz->filter = SubGhzProtocolFlag_Decodable; - subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); - subghz_txrx_need_save_callback_set(subghz->txrx, subghz_save_to_file, subghz); //Init Error_str diff --git a/applications/main/subghz/subghz_i.c b/applications/main/subghz/subghz_i.c index 03aaa6da6..101ffdfdf 100644 --- a/applications/main/subghz/subghz_i.c +++ b/applications/main/subghz/subghz_i.c @@ -18,6 +18,27 @@ #define TAG "SubGhz" +void subghz_set_defalut_preset(SubGhz* subghz) { + furi_assert(subghz); + subghz_txrx_set_preset( + subghz->txrx, + "AM650", + subghz_setting_get_default_frequency(subghz_txrx_get_setting(subghz->txrx)), + NULL, + 0); +} + +void subghz_blink_start(SubGhz* subghz) { + furi_assert(subghz); + notification_message(subghz->notifications, &sequence_blink_stop); + notification_message(subghz->notifications, &sequence_blink_start_magenta); +} + +void subghz_blink_stop(SubGhz* subghz) { + furi_assert(subghz); + notification_message(subghz->notifications, &sequence_blink_stop); +} + void subghz_dialog_message_show_only_rx(SubGhz* subghz) { DialogsApp* dialogs = subghz->dialogs; DialogMessage* message = dialog_message_alloc(); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 82cc71752..e955d8360 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -120,32 +120,31 @@ struct SubGhz { void* rpc_ctx; }; +void subghz_set_defalut_preset(SubGhz* subghz); void subghz_blink_start(SubGhz* subghz); void subghz_blink_stop(SubGhz* subghz); void subghz_dialog_message_show_only_rx(SubGhz* subghz); + bool subghz_key_load(SubGhz* subghz, const char* file_path, bool show_dialog); bool subghz_get_next_name_file(SubGhz* subghz, uint8_t max_len); bool subghz_save_protocol_to_file( SubGhz* subghz, FlipperFormat* flipper_format, const char* dev_file_name); - void subghz_save_to_file(void* context); - bool subghz_load_protocol_from_file(SubGhz* subghz); bool subghz_rename_file(SubGhz* subghz); bool subghz_file_available(SubGhz* subghz); bool subghz_delete_file(SubGhz* subghz); void subghz_file_name_clear(SubGhz* subghz); bool subghz_path_is_file(FuriString* path); +SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); void subghz_lock(SubGhz* subghz); void subghz_unlock(SubGhz* subghz); bool subghz_is_locked(SubGhz* subghz); -SubGhzLoadTypeFile subghz_get_load_type_file(SubGhz* subghz); - void subghz_rx_key_state_set(SubGhz* subghz, SubGhzRxKeyState state); SubGhzRxKeyState subghz_rx_key_state_get(SubGhz* subghz);