From 076f6785cb517d025edd75a0b321817de88780c6 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Tue, 9 May 2023 15:22:08 +0300 Subject: [PATCH] SubGhz: refactoring --- .../scenes/subghz_scene_receiver_info.c | 10 +++------ .../subghz/scenes/subghz_scene_transmitter.c | 9 +------- applications/main/subghz/subghz_radio.c | 22 +++++++++++++++++++ applications/main/subghz/subghz_radio.h | 3 +++ 4 files changed, 29 insertions(+), 15 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index a026371fd..f3cfd0962 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -78,8 +78,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { furi_string_free(modulation_str); furi_string_free(text); - if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == - SubGhzProtocolFlag_Save) { + if(subghz_txrx_protocol_is_preserved(subghz->txrx)) { widget_add_button_element( subghz->widget, GuiButtonTypeRight, @@ -88,9 +87,7 @@ void subghz_scene_receiver_info_draw_widget(SubGhz* subghz) { subghz); } // Removed static check - if(((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == - SubGhzProtocolFlag_Send) && - subghz->txrx->decoder_result->protocol->encoder->deserialize) { + if(subghz_txrx_protocol_is_send(subghz->txrx, false)) { widget_add_button_element( subghz->widget, GuiButtonTypeCenter, @@ -162,8 +159,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) return false; } - if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == - SubGhzProtocolFlag_Save) { + if(subghz_txrx_protocol_is_preserved(subghz->txrx)) { subghz_file_name_clear(subghz); if(subghz->in_decoder_scene) { diff --git a/applications/main/subghz/scenes/subghz_scene_transmitter.c b/applications/main/subghz/scenes/subghz_scene_transmitter.c index 5c4d03403..d5bd45618 100644 --- a/applications/main/subghz/scenes/subghz_scene_transmitter.c +++ b/applications/main/subghz/scenes/subghz_scene_transmitter.c @@ -20,26 +20,19 @@ bool subghz_scene_transmitter_update_data_show(void* context) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); - bool show_button = false; - if(subghz_protocol_decoder_base_deserialize( subghz_txrx_get_decoder(subghz->txrx), subghz_txtx_get_fff_data(subghz->txrx)) == SubGhzProtocolStatusOk) { subghz_protocol_decoder_base_get_string( subghz_txrx_get_decoder(subghz->txrx), key_str); - if((subghz->txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == - SubGhzProtocolFlag_Send) { - show_button = true; - } - subghz_get_frequency_modulation(subghz->txrx, frequency_str, modulation_str, false); subghz_view_transmitter_add_data_to_show( subghz->subghz_transmitter, furi_string_get_cstr(key_str), furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), - show_button); + subghz_txrx_protocol_is_send(subghz->txrx, false)); ret = true; } furi_string_free(frequency_str); diff --git a/applications/main/subghz/subghz_radio.c b/applications/main/subghz/subghz_radio.c index ed3215ebc..cd556efce 100644 --- a/applications/main/subghz/subghz_radio.c +++ b/applications/main/subghz/subghz_radio.c @@ -444,6 +444,28 @@ SubGhzProtocolDecoderBase* subghz_txrx_get_decoder(SubGhzTxRx* txrx) { return txrx->decoder_result; } +bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx) { + furi_assert(txrx); + return ( + (txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Save) == + SubGhzProtocolFlag_Save); +} + +bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type) { + furi_assert(txrx); + if(check_type) { + return ( + ((txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == + SubGhzProtocolFlag_Send) && + txrx->decoder_result->protocol->encoder->deserialize && + txrx->decoder_result->protocol->type == SubGhzProtocolTypeStatic); + } + return ( + ((txrx->decoder_result->protocol->flag & SubGhzProtocolFlag_Send) == + SubGhzProtocolFlag_Send) && + txrx->decoder_result->protocol->encoder->deserialize); +} + //#############Create new Key############## #include #include diff --git a/applications/main/subghz/subghz_radio.h b/applications/main/subghz/subghz_radio.h index 9a9f90d3d..0a51334cb 100644 --- a/applications/main/subghz/subghz_radio.h +++ b/applications/main/subghz/subghz_radio.h @@ -84,6 +84,9 @@ void subghz_txrx_need_save_callback_set( FlipperFormat* subghz_txtx_get_fff_data(SubGhzTxRx* txrx); SubGhzSetting* subghz_txrx_get_setting(SubGhzTxRx* txrx); +bool subghz_txrx_protocol_is_preserved(SubGhzTxRx* txrx); +bool subghz_txrx_protocol_is_send(SubGhzTxRx* txrx, bool check_type); + //#############Create new Key############## bool subghz_gen_data_protocol( void* context,