SubGhz: refactoring

This commit is contained in:
gid9798
2023-05-09 15:22:08 +03:00
parent 07203f0989
commit 076f6785cb
4 changed files with 29 additions and 15 deletions

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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 <lib/subghz/protocols/protocol_items.h>
#include <lib/subghz/protocols/keeloq.h>

View File

@@ -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,