From 417dedd3176605f9b921ba0f6d91f623d1adb0d5 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Wed, 14 Jun 2023 01:24:05 +0300 Subject: [PATCH] SubGhz App: remove kostily and velosipedy --- .../subghz/scenes/subghz_scene_receiver.c | 78 +++++++------------ .../scenes/subghz_scene_receiver_config.c | 70 ++++++++--------- applications/main/subghz/subghz.c | 1 + applications/main/subghz/subghz_i.h | 5 +- lib/subghz/protocols/kia.c | 3 +- lib/subghz/protocols/magellan.c | 3 +- lib/subghz/protocols/scher_khan.c | 2 +- lib/subghz/protocols/star_line.c | 3 +- lib/subghz/types.h | 3 + 9 files changed, 75 insertions(+), 93 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index d9fd38836..8bba21b2b 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -92,35 +92,41 @@ static void subghz_scene_add_to_history_callback( void* context) { furi_assert(context); SubGhz* subghz = context; - SubGhzHistory* history = subghz->history; - FuriString* item_name = furi_string_alloc(); - FuriString* item_time = furi_string_alloc(); - uint16_t idx = subghz_history_get_item(history); - SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); - if(subghz_history_add_to_history(history, decoder_base, &preset)) { - furi_string_reset(item_name); - furi_string_reset(item_time); + // The check can be moved to /lib/subghz/receiver.c, but may result in false positives + if((decoder_base->protocol->flag & subghz->ignore_filter) == 0) { + SubGhzHistory* history = subghz->history; + FuriString* item_name = furi_string_alloc(); + FuriString* item_time = furi_string_alloc(); + uint16_t idx = subghz_history_get_item(history); - subghz->state_notifications = SubGhzNotificationStateRxDone; + SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx); + if(subghz_history_add_to_history(history, decoder_base, &preset)) { + furi_string_reset(item_name); + furi_string_reset(item_time); - subghz_history_get_text_item_menu(history, item_name, idx); - subghz_history_get_time_item_menu(history, item_time, idx); - subghz_view_receiver_add_item_to_menu( - subghz->subghz_receiver, - furi_string_get_cstr(item_name), - furi_string_get_cstr(item_time), - subghz_history_get_type_protocol(history, idx)); + subghz->state_notifications = SubGhzNotificationStateRxDone; - subghz_scene_receiver_update_statusbar(subghz); - if(subghz_history_get_text_space_left(subghz->history, NULL)) { - notification_message(subghz->notifications, &sequence_error); + subghz_history_get_text_item_menu(history, item_name, idx); + subghz_history_get_time_item_menu(history, item_time, idx); + subghz_view_receiver_add_item_to_menu( + subghz->subghz_receiver, + furi_string_get_cstr(item_name), + furi_string_get_cstr(item_time), + subghz_history_get_type_protocol(history, idx)); + + subghz_scene_receiver_update_statusbar(subghz); + if(subghz_history_get_text_space_left(subghz->history, NULL)) { + notification_message(subghz->notifications, &sequence_error); + } } + subghz_receiver_reset(receiver); + furi_string_free(item_name); + furi_string_free(item_time); + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); + } else { + FURI_LOG_I(TAG, "%s protocol ignored", decoder_base->protocol->name); } - subghz_receiver_reset(receiver); - furi_string_free(item_name); - furi_string_free(item_time); - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateAddKey); } void subghz_scene_receiver_on_enter(void* context) { @@ -161,32 +167,6 @@ void subghz_scene_receiver_on_enter(void* context) { subghz->subghz_receiver, subghz_scene_receiver_callback, subghz); subghz_txrx_set_rx_calback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); - // TODO: Replace with proper solution based on protocol flags, remove kostily and velosipedy from here - // Needs to be done after subghz refactoring merge!!! - if(subghz->ignore_starline == true) { - if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Star Line")) { - subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); - } - } - if(subghz->ignore_auto_alarms == true) { - if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "KIA Seed")) { - subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); - } - - if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Scher-Khan")) { - subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); - } - } - if(subghz->ignore_magellan == true) { - if(subghz_txrx_load_decoder_by_name_protocol(subghz->txrx, "Magellan")) { - subghz_protocol_decoder_base_set_decoder_callback( - subghz_txrx_get_decoder(subghz->txrx), NULL, NULL); - } - } - if(!subghz_history_get_text_space_left(subghz->history, NULL)) { subghz->state_notifications = SubGhzNotificationStateRx; } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 29d55c03a..62ee53871 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -71,20 +71,8 @@ const uint32_t bin_raw_value[BIN_RAW_COUNT] = { SubGhzProtocolFlag_Decodable, SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_BinRAW, }; -#define STARLINE_COUNT 2 -const char* const starline_text[STARLINE_COUNT] = { - "OFF", - "ON", -}; - -#define AUTO_ALARMS_COUNT 2 -const char* const auto_alarms_text[AUTO_ALARMS_COUNT] = { - "OFF", - "ON", -}; - -#define MAGELLAN_COUNT 2 -const char* const magellan_text[MAGELLAN_COUNT] = { +#define PROTOCOL_IGNORE_COUNT 2 +const char* const protocol_ignore_text[PROTOCOL_IGNORE_COUNT] = { "OFF", "ON", }; @@ -257,28 +245,35 @@ static void subghz_scene_receiver_config_set_raw_threshold_rssi(VariableItem* it subghz_threshold_rssi_set(subghz->threshold_rssi, raw_threshold_rssi_value[index]); } -static void subghz_scene_receiver_config_set_starline(VariableItem* item) { +static inline void + subghz_scene_receiver_config_set_ignore_filter(VariableItem* item, SubGhzProtocolFlag filter) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); - variable_item_set_current_value_text(item, starline_text[index]); - subghz->ignore_starline = (index == 1); + variable_item_set_current_value_text(item, protocol_ignore_text[index]); + + if(index == 0) { + CLEAR_BIT(subghz->ignore_filter, filter); + } else { + SET_BIT(subghz->ignore_filter, filter); + } +} +static inline bool subghz_scene_receiver_config_ignore_filter_get_index( + SubGhzProtocolFlag filter, + SubGhzProtocolFlag flag) { + return READ_BIT(filter, flag) > 0; +} + +static void subghz_scene_receiver_config_set_starline(VariableItem* item) { + subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFlag_StarLine); } static void subghz_scene_receiver_config_set_auto_alarms(VariableItem* item) { - SubGhz* subghz = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - - variable_item_set_current_value_text(item, auto_alarms_text[index]); - subghz->ignore_auto_alarms = (index == 1); + subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFlag_AutoAlarms); } static void subghz_scene_receiver_config_set_magellan(VariableItem* item) { - SubGhz* subghz = variable_item_get_context(item); - uint8_t index = variable_item_get_current_value_index(item); - - variable_item_set_current_value_text(item, magellan_text[index]); - subghz->ignore_magellan = (index == 1); + subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFlag_Magelan); } static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) { @@ -362,35 +357,38 @@ void subghz_scene_receiver_config_on_enter(void* context) { item = variable_item_list_add( subghz->variable_item_list, "Ignore Starline:", - STARLINE_COUNT, + PROTOCOL_IGNORE_COUNT, subghz_scene_receiver_config_set_starline, subghz); - value_index = subghz->ignore_starline; + value_index = subghz_scene_receiver_config_ignore_filter_get_index( + subghz->ignore_filter, SubGhzProtocolFlag_StarLine); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, starline_text[value_index]); + variable_item_set_current_value_text(item, protocol_ignore_text[value_index]); item = variable_item_list_add( subghz->variable_item_list, "Ignore Cars:", - AUTO_ALARMS_COUNT, + PROTOCOL_IGNORE_COUNT, subghz_scene_receiver_config_set_auto_alarms, subghz); - value_index = subghz->ignore_auto_alarms; + value_index = subghz_scene_receiver_config_ignore_filter_get_index( + subghz->ignore_filter, SubGhzProtocolFlag_AutoAlarms); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, auto_alarms_text[value_index]); + variable_item_set_current_value_text(item, protocol_ignore_text[value_index]); item = variable_item_list_add( subghz->variable_item_list, "Ignore Magellan:", - MAGELLAN_COUNT, + PROTOCOL_IGNORE_COUNT, subghz_scene_receiver_config_set_magellan, subghz); - value_index = subghz->ignore_magellan; + value_index = subghz_scene_receiver_config_ignore_filter_get_index( + subghz->ignore_filter, SubGhzProtocolFlag_Magelan); variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, magellan_text[value_index]); + variable_item_set_current_value_text(item, protocol_ignore_text[value_index]); } // Enable speaker, will send all incoming noises and signals to speaker so you can listen how your remote sounds like :) diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index aab154f2d..db63ab1fe 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -242,6 +242,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->secure_data = malloc(sizeof(SecureData)); subghz->filter = SubGhzProtocolFlag_Decodable; + subghz->ignore_filter = 0x0; subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); subghz_txrx_set_need_save_callback(subghz->txrx, subghz_save_to_file, subghz); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 3d1c2db9c..08658e9b2 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -89,13 +89,10 @@ struct SubGhz { SubGhzLastSettings* last_settings; SubGhzProtocolFlag filter; + SubGhzProtocolFlag ignore_filter; FuriString* error_str; SubGhzLock lock; - bool ignore_starline; - bool ignore_auto_alarms; - bool ignore_magellan; - SecureData* secure_data; SubGhzFileEncoderWorker* decode_raw_file_worker_encoder; diff --git a/lib/subghz/protocols/kia.c b/lib/subghz/protocols/kia.c index 1d134f7ba..2d2ceaa1d 100644 --- a/lib/subghz/protocols/kia.c +++ b/lib/subghz/protocols/kia.c @@ -63,7 +63,8 @@ const SubGhzProtocolEncoder subghz_protocol_kia_encoder = { const SubGhzProtocol subghz_protocol_kia = { .name = SUBGHZ_PROTOCOL_KIA_NAME, .type = SubGhzProtocolTypeDynamic, - .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable, + .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable | + SubGhzProtocolFlag_AutoAlarms, .decoder = &subghz_protocol_kia_decoder, .encoder = &subghz_protocol_kia_encoder, diff --git a/lib/subghz/protocols/magellan.c b/lib/subghz/protocols/magellan.c index 2d02a866c..be819ff31 100644 --- a/lib/subghz/protocols/magellan.c +++ b/lib/subghz/protocols/magellan.c @@ -64,7 +64,8 @@ const SubGhzProtocol subghz_protocol_magellan = { .name = SUBGHZ_PROTOCOL_MAGELLAN_NAME, .type = SubGhzProtocolTypeStatic, .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | - SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send, + SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send | + SubGhzProtocolFlag_Magelan, .decoder = &subghz_protocol_magellan_decoder, .encoder = &subghz_protocol_magellan_encoder, diff --git a/lib/subghz/protocols/scher_khan.c b/lib/subghz/protocols/scher_khan.c index c2fa77b2f..53b7935d6 100644 --- a/lib/subghz/protocols/scher_khan.c +++ b/lib/subghz/protocols/scher_khan.c @@ -70,7 +70,7 @@ const SubGhzProtocol subghz_protocol_scher_khan = { .name = SUBGHZ_PROTOCOL_SCHER_KHAN_NAME, .type = SubGhzProtocolTypeDynamic, .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_FM | SubGhzProtocolFlag_Decodable | - SubGhzProtocolFlag_Save, + SubGhzProtocolFlag_Save | SubGhzProtocolFlag_AutoAlarms, .decoder = &subghz_protocol_scher_khan_decoder, .encoder = &subghz_protocol_scher_khan_encoder, diff --git a/lib/subghz/protocols/star_line.c b/lib/subghz/protocols/star_line.c index 05afd80a6..bf338b35d 100644 --- a/lib/subghz/protocols/star_line.c +++ b/lib/subghz/protocols/star_line.c @@ -79,7 +79,8 @@ const SubGhzProtocol subghz_protocol_star_line = { .name = SUBGHZ_PROTOCOL_STAR_LINE_NAME, .type = SubGhzProtocolTypeDynamic, .flag = SubGhzProtocolFlag_433 | SubGhzProtocolFlag_AM | SubGhzProtocolFlag_Decodable | - SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send, + SubGhzProtocolFlag_Load | SubGhzProtocolFlag_Save | SubGhzProtocolFlag_Send | + SubGhzProtocolFlag_StarLine, .decoder = &subghz_protocol_star_line_decoder, .encoder = &subghz_protocol_star_line_encoder, diff --git a/lib/subghz/types.h b/lib/subghz/types.h index ce65789a9..70a57d3f9 100644 --- a/lib/subghz/types.h +++ b/lib/subghz/types.h @@ -117,6 +117,9 @@ typedef enum { SubGhzProtocolFlag_Load = (1 << 8), SubGhzProtocolFlag_Send = (1 << 9), SubGhzProtocolFlag_BinRAW = (1 << 10), + SubGhzProtocolFlag_StarLine = (1 << 11), + SubGhzProtocolFlag_AutoAlarms = (1 << 12), + SubGhzProtocolFlag_Magelan = (1 << 13), } SubGhzProtocolFlag; struct SubGhzProtocol {