From 3491844d41984caebabed4b513ca4bbf0093b66d Mon Sep 17 00:00:00 2001 From: DerSkythe Date: Fri, 25 Aug 2023 07:48:04 +0400 Subject: [PATCH] change: add defines to disable load saved preset value and binary RAW add: icon for BinRAW mode in Read screen --- .../subghz/scenes/subghz_scene_decode_raw.c | 6 ++-- .../subghz/scenes/subghz_scene_delete_raw.c | 1 - .../subghz/scenes/subghz_scene_read_raw.c | 6 ++-- .../subghz/scenes/subghz_scene_receiver.c | 14 +++++---- .../scenes/subghz_scene_receiver_config.c | 3 +- .../scenes/subghz_scene_receiver_info.c | 1 - applications/main/subghz/subghz.c | 9 ++++-- applications/main/subghz/subghz_i.h | 2 +- .../main/subghz/subghz_last_settings.c | 29 ++++++++++--------- .../main/subghz/subghz_last_settings.h | 3 +- applications/main/subghz/views/receiver.c | 17 +++++++---- applications/main/subghz/views/receiver.h | 3 +- 12 files changed, 52 insertions(+), 42 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index 6cb231935..85a524117 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -18,7 +18,8 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), furi_string_get_cstr(history_stat_str), - subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF, + READ_BIT(subghz->filter, SubGhzProtocolFlag_BinRAW) > 0); furi_string_free(frequency_str); furi_string_free(modulation_str); @@ -28,7 +29,8 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_get_cstr(history_stat_str), "", "", - subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF, + READ_BIT(subghz->filter, SubGhzProtocolFlag_BinRAW) > 0); } furi_string_free(history_stat_str); } diff --git a/applications/main/subghz/scenes/subghz_scene_delete_raw.c b/applications/main/subghz/scenes/subghz_scene_delete_raw.c index 0b3cfd6ee..ec6b93653 100644 --- a/applications/main/subghz/scenes/subghz_scene_delete_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_delete_raw.c @@ -1,6 +1,5 @@ #include "../subghz.h" #include "../subghz_i.h" -#include "../helpers/subghz_custom_event.h" void subghz_scene_delete_raw_callback(GuiButtonType result, InputType type, void* context) { furi_assert(context); diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 83b7dc854..9651ee641 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -104,16 +104,14 @@ void subghz_scene_read_raw_on_enter(void* context) { if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateBack) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE); +#if SUBGHZ_LAST_SETTING_SAVE_PRESET if(furi_string_empty(file_name)) { subghz_txrx_set_preset_internal( subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index); - subghz_txrx_speaker_set_state( - subghz->txrx, - subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown : - SubGhzSpeakerStateEnable); } +#endif } subghz_scene_read_raw_update_statusbar(subghz); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 2b124b67b..4844d975e 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -70,7 +70,8 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_get_cstr(frequency_str), furi_string_get_cstr(modulation_str), furi_string_get_cstr(history_stat_str), - subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF, + READ_BIT(subghz->filter, SubGhzProtocolFlag_BinRAW) > 0); furi_string_free(frequency_str); furi_string_free(modulation_str); @@ -80,7 +81,8 @@ static void subghz_scene_receiver_update_statusbar(void* context) { furi_string_get_cstr(history_stat_str), "", "", - subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF); + subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF, + READ_BIT(subghz->filter, SubGhzProtocolFlag_BinRAW) > 0); subghz->state_notifications = SubGhzNotificationStateIDLE; } furi_string_free(history_stat_str); @@ -146,12 +148,12 @@ void subghz_scene_receiver_on_enter(void* context) { FuriString* item_time = furi_string_alloc(); if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) { +#if SUBGHZ_LAST_SETTING_SAVE_PRESET subghz_txrx_set_preset_internal( subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index); - subghz_txrx_speaker_set_state( - subghz->txrx, - subghz->last_settings->sound == 0 ? SubGhzSpeakerStateShutdown : - SubGhzSpeakerStateEnable); +#else + subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency); +#endif subghz->filter = subghz->last_settings->filter; subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index c8971f87b..1fad617c7 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -230,8 +230,6 @@ static void subghz_scene_receiver_config_set_speaker(VariableItem* item) { variable_item_set_current_value_text(item, combobox_text[index]); subghz_txrx_speaker_set_state(subghz->txrx, speaker_value[index]); - - subghz->last_settings->sound = index; } static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { @@ -242,6 +240,7 @@ static void subghz_scene_receiver_config_set_bin_raw(VariableItem* item) { subghz->filter = bin_raw_value[index]; subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter); + // We can set here, but during subghz_last_settings_save filter was changed to ignore BinRAW subghz->last_settings->filter = subghz->filter; } diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 5ad1c71f9..cd4f0f836 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -1,5 +1,4 @@ #include "../subghz_i.h" -#include "../helpers/subghz_custom_event.h" #include diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index aaa25fe17..b5e6371e9 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -112,7 +112,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { // Open Notification record subghz->notifications = furi_record_open(RECORD_NOTIFICATION); -#ifdef SUBGHZ_MEASURE_LOADING +#if SUBGHZ_MEASURE_LOADING uint32_t load_ticks = furi_get_tick(); #endif subghz->txrx = subghz_txrx_alloc(); @@ -204,9 +204,12 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_last_settings_log(subghz->last_settings); #endif if(!alloc_for_tx_only) { +#if SUBGHZ_LAST_SETTING_SAVE_PRESET subghz_txrx_set_preset_internal( subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index); - +#else + subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency); +#endif subghz->history = subghz_history_alloc(); } @@ -231,7 +234,7 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->last_settings->rssi = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; } } -#ifdef SUBGHZ_MEASURE_LOADING +#if SUBGHZ_MEASURE_LOADING load_ticks = furi_get_tick() - load_ticks; FURI_LOG_I(TAG, "Loaded: %ld ms.", load_ticks); #endif diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index e348b279f..c661e440a 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -43,7 +43,7 @@ #define SUBGHZ_MAX_LEN_NAME 64 #define SUBGHZ_EXT_PRESET_NAME true #define SUBGHZ_RAW_THRESHOLD_MIN (-90.0f) -#define SUBGHZ_MEASURE_LOADING true +#define SUBGHZ_MEASURE_LOADING false typedef struct { uint8_t fix[4]; diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 762fe0f98..16a53e943 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -23,7 +23,6 @@ #define SUBGHZ_LAST_SETTING_FIELD_HOPPING_ENABLE "Hopping" #define SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER "IgnoreFilter" #define SUBGHZ_LAST_SETTING_FIELD_FILTER "Filter" -#define SUBGHZ_LAST_SETTING_FIELD_SOUND "Sound" #define SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD "RSSI" SubGhzLastSettings* subghz_last_settings_alloc(void) { @@ -52,7 +51,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool temp_enable_hopping = false; uint32_t temp_ignore_filter = 0; uint32_t temp_filter = 0; - uint32_t temp_sound = 0; float temp_rssi = 0; uint32_t temp_preset = 0; @@ -106,8 +104,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count 1); rssi_was_read = flipper_format_read_float( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, (float*)&temp_rssi, 1); - flipper_format_read_uint32( - fff_data_file, SUBGHZ_LAST_SETTING_FIELD_SOUND, (uint32_t*)&temp_sound, 1); ignore_filter_was_read = flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER, @@ -115,7 +111,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count 1); filter_was_read = flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FILTER, (uint32_t*)&temp_filter, 1); - } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -135,7 +130,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->ignore_filter = 0x00; // See bin_raw_value in applications/main/subghz/scenes/subghz_scene_receiver_config.c instance->filter = SubGhzProtocolFlag_Decodable; - instance->sound = 0; instance->rssi = SUBGHZ_RAW_THRESHOLD_MIN; } else { instance->frequency = temp_frequency; @@ -173,8 +167,17 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->rssi = rssi_was_read ? temp_rssi : SUBGHZ_RAW_THRESHOLD_MIN; instance->enable_hopping = temp_enable_hopping; instance->ignore_filter = ignore_filter_was_read ? temp_ignore_filter : 0x00; +#if SUBGHZ_LAST_SETTING_SAVE_BIN_RAW instance->filter = filter_was_read ? temp_filter : SubGhzProtocolFlag_Decodable; - instance->sound = temp_sound; +#else + if(filter_was_read) { + instance->filter = temp_filter != SubGhzProtocolFlag_Decodable ? + SubGhzProtocolFlag_Decodable : + temp_filter; + } else { + instance->filter = SubGhzProtocolFlag_Decodable; + } +#endif // Set globally in furi hal furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); } @@ -187,6 +190,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count bool subghz_last_settings_save(SubGhzLastSettings* instance) { furi_assert(instance); +#if SUBGHZ_LAST_SETTING_SAVE_BIN_RAW != true + instance->filter = SubGhzProtocolFlag_Decodable; +#endif bool saved = false; Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* file = flipper_format_file_alloc(storage); @@ -261,10 +267,6 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_RSSI_THRESHOLD, &instance->rssi, 1)) { break; } - if(!flipper_format_insert_or_update_uint32( - file, SUBGHZ_LAST_SETTING_FIELD_SOUND, &instance->sound, 1)) { - break; - } if(!flipper_format_insert_or_update_uint32( file, SUBGHZ_LAST_SETTING_FIELD_IGNORE_FILTER, &instance->ignore_filter, 1)) { break; @@ -306,7 +308,7 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) { TAG, "Frequency: %03ld.%02ld, FeedbackLevel: %ld, FATrigger: %.2f, External: %s, ExtPower: %s, TimestampNames: %s, ExtPowerAmp: %s,\n" "Hopping: %s,\nPreset: %ld, RSSI: %.2f, " - "Starline: %s, Cars: %s, Magellan: %s, BinRAW: %s, Sound: %ld", + "Starline: %s, Cars: %s, Magellan: %s, BinRAW: %s", instance->frequency / 1000000 % 1000, instance->frequency / 10000 % 100, instance->frequency_analyzer_feedback_level, @@ -324,6 +326,5 @@ void subghz_last_settings_log(SubGhzLastSettings* instance) { instance->ignore_filter, SubGhzProtocolFlag_AutoAlarms), subghz_last_settings_log_filter_get_index( instance->ignore_filter, SubGhzProtocolFlag_Magelan), - subghz_last_settings_log_filter_get_index(instance->filter, SubGhzProtocolFlag_BinRAW), - instance->sound); + subghz_last_settings_log_filter_get_index(instance->filter, SubGhzProtocolFlag_BinRAW)); } diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 06d7bf9b7..5655954ee 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -7,6 +7,8 @@ #include #define SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER (-93.0f) +#define SUBGHZ_LAST_SETTING_SAVE_BIN_RAW true +#define SUBGHZ_LAST_SETTING_SAVE_PRESET true typedef struct { uint32_t frequency; @@ -22,7 +24,6 @@ typedef struct { bool enable_hopping; uint32_t ignore_filter; uint32_t filter; - uint32_t sound; float rssi; } SubGhzLastSettings; diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 8bff2244f..e08c86fb6 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -63,6 +63,7 @@ typedef struct { FuriString* history_stat_str; FuriString* progress_str; bool hopping_enabled; + bool bin_raw_enabled; SubGhzReceiverHistory* history; uint16_t idx; uint16_t list_offset; @@ -202,7 +203,8 @@ void subghz_view_receiver_add_data_statusbar( const char* frequency_str, const char* preset_str, const char* history_stat_str, - bool hopping_enabled) { + bool hopping_enabled, + bool bin_raw_enabled) { furi_assert(subghz_receiver); with_view_model( subghz_receiver->view, @@ -212,6 +214,7 @@ void subghz_view_receiver_add_data_statusbar( furi_string_set(model->preset_str, preset_str); furi_string_set(model->history_stat_str, history_stat_str); model->hopping_enabled = hopping_enabled; + model->bin_raw_enabled = bin_raw_enabled; }, true); } @@ -330,11 +333,11 @@ void subghz_view_receiver_draw(Canvas* canvas, SubGhzViewReceiverModel* model) { //canvas_draw_line(canvas, 46, 51, 125, 51); canvas_set_font(canvas, FontSecondary); - // if(model->hopping_enabled) { - // const uint8_t vertical_offset = 0; - // const uint8_t horizontal_offset = 3; - // canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Dynamic_9x7); - // } + if(model->bin_raw_enabled) { + const uint8_t vertical_offset = 17; + const uint8_t horizontal_offset = 118; + canvas_draw_icon(canvas, horizontal_offset, vertical_offset, &I_Raw_9x7); + } } else { canvas_draw_icon( canvas, @@ -564,6 +567,7 @@ void subghz_view_receiver_exit(void* context) { model->history_item = 0; model->nodraw = false; model->hopping_enabled = false; + model->bin_raw_enabled = false; }, false); furi_timer_stop(subghz_receiver->timer); @@ -601,6 +605,7 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() { model->nodraw = false; model->history = malloc(sizeof(SubGhzReceiverHistory)); model->hopping_enabled = false; + model->bin_raw_enabled = false; SubGhzReceiverMenuItemArray_init(model->history->data); }, true); diff --git a/applications/main/subghz/views/receiver.h b/applications/main/subghz/views/receiver.h index 264d8a983..c280e1de6 100644 --- a/applications/main/subghz/views/receiver.h +++ b/applications/main/subghz/views/receiver.h @@ -32,7 +32,8 @@ void subghz_view_receiver_add_data_statusbar( const char* frequency_str, const char* preset_str, const char* history_stat_str, - bool hopping_enabled); + bool hopping_enabled, + bool bin_raw_enabled); void subghz_view_receiver_set_radio_device_type( SubGhzViewReceiver* subghz_receiver,