From c92217a1099b4a1e573c2dafe81cee9ea0c1951e Mon Sep 17 00:00:00 2001 From: Sergey Gavrilov Date: Fri, 30 Sep 2022 20:59:11 +1000 Subject: [PATCH 01/10] Thread: Clear TLS after thread stop (#1807) --- furi/core/thread.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/furi/core/thread.c b/furi/core/thread.c index d326e389b..d06fa8b36 100644 --- a/furi/core/thread.c +++ b/furi/core/thread.c @@ -93,14 +93,16 @@ static void furi_thread_body(void* context) { thread->name ? thread->name : ""); } - // clear thread local storage + // flush stdout __furi_thread_stdout_flush(thread); - furi_assert(pvTaskGetThreadLocalStoragePointer(NULL, 0) != NULL); - vTaskSetThreadLocalStoragePointer(NULL, 0, NULL); // from here we can't use thread pointer furi_thread_set_state(thread, FuriThreadStateStopped); + // clear thread local storage + furi_assert(pvTaskGetThreadLocalStoragePointer(NULL, 0) != NULL); + vTaskSetThreadLocalStoragePointer(NULL, 0, NULL); + vTaskDelete(NULL); furi_thread_catch(); } From 836de3df16ca834f985ae6672e6bb318e5d1dd23 Mon Sep 17 00:00:00 2001 From: Nikolay Minaylov Date: Fri, 30 Sep 2022 15:56:12 +0300 Subject: [PATCH 02/10] [FL-2825] iButton GUI fixes (#1805) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Ibutton GUI fixes * Fix memory leak in lfRFID write Co-authored-by: あく --- .../scenes/ibutton_scene_delete_confirm.c | 10 ++-- .../ibutton/scenes/ibutton_scene_emulate.c | 45 +++++------------- .../main/ibutton/scenes/ibutton_scene_info.c | 12 ++--- .../scenes/ibutton_scene_save_success.c | 6 +-- .../main/ibutton/scenes/ibutton_scene_write.c | 46 +++++-------------- .../main/lfrfid/scenes/lfrfid_scene_write.c | 2 - 6 files changed, 36 insertions(+), 85 deletions(-) diff --git a/applications/main/ibutton/scenes/ibutton_scene_delete_confirm.c b/applications/main/ibutton/scenes/ibutton_scene_delete_confirm.c index 51f1f2794..fccefe6ec 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_delete_confirm.c +++ b/applications/main/ibutton/scenes/ibutton_scene_delete_confirm.c @@ -23,7 +23,7 @@ void ibutton_scene_delete_confirm_on_enter(void* context) { ibutton_text_store_set(ibutton, "\e#Delete %s?\e#", string_get_cstr(key_name)); widget_add_text_box_element( - widget, 0, 0, 128, 27, AlignCenter, AlignCenter, ibutton->text_store, false); + widget, 0, 0, 128, 27, AlignCenter, AlignCenter, ibutton->text_store, true); widget_add_button_element( widget, GuiButtonTypeLeft, "Cancel", ibutton_scene_delete_confirm_widget_callback, ibutton); widget_add_button_element( @@ -47,24 +47,24 @@ void ibutton_scene_delete_confirm_on_enter(void* context) { key_data[6], key_data[7]); widget_add_string_element( - widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Dallas"); + widget, 64, 34, AlignCenter, AlignBottom, FontSecondary, "Dallas"); break; case iButtonKeyCyfral: ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]); widget_add_string_element( - widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Cyfral"); + widget, 64, 34, AlignCenter, AlignBottom, FontSecondary, "Cyfral"); break; case iButtonKeyMetakom: ibutton_text_store_set( ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]); widget_add_string_element( - widget, 64, 45, AlignCenter, AlignBottom, FontSecondary, "Metakom"); + widget, 64, 34, AlignCenter, AlignBottom, FontSecondary, "Metakom"); break; } widget_add_string_element( - widget, 64, 33, AlignCenter, AlignBottom, FontSecondary, ibutton->text_store); + widget, 64, 46, AlignCenter, AlignBottom, FontSecondary, ibutton->text_store); view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget); diff --git a/applications/main/ibutton/scenes/ibutton_scene_emulate.c b/applications/main/ibutton/scenes/ibutton_scene_emulate.c index 3420f8471..e6e0ec688 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_emulate.c +++ b/applications/main/ibutton/scenes/ibutton_scene_emulate.c @@ -15,7 +15,7 @@ static void ibutton_scene_emulate_callback(void* context, bool emulated) { void ibutton_scene_emulate_on_enter(void* context) { iButton* ibutton = context; - Popup* popup = ibutton->popup; + Widget* widget = ibutton->widget; iButtonKey* key = ibutton->key; const uint8_t* key_data = ibutton_key_get_data_p(key); @@ -26,20 +26,18 @@ void ibutton_scene_emulate_on_enter(void* context) { path_extract_filename(ibutton->file_path, key_name, true); } - uint8_t line_count = 2; DOLPHIN_DEED(DolphinDeedIbuttonEmulate); // check that stored key has name if(!string_empty_p(key_name)) { - ibutton_text_store_set(ibutton, "emulating\n%s", string_get_cstr(key_name)); - line_count = 2; + ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name)); } else { // if not, show key data switch(ibutton_key_get_type(key)) { case iButtonKeyDS1990: ibutton_text_store_set( ibutton, - "emulating\n%02X %02X %02X %02X\n%02X %02X %02X %02X", + "%02X %02X %02X %02X\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], @@ -48,40 +46,24 @@ void ibutton_scene_emulate_on_enter(void* context) { key_data[5], key_data[6], key_data[7]); - line_count = 3; break; case iButtonKeyCyfral: - ibutton_text_store_set(ibutton, "emulating\n%02X %02X", key_data[0], key_data[1]); - line_count = 2; + ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]); break; case iButtonKeyMetakom: ibutton_text_store_set( - ibutton, - "emulating\n%02X %02X %02X %02X", - key_data[0], - key_data[1], - key_data[2], - key_data[3]); - line_count = 2; + ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]); break; } } - switch(line_count) { - case 3: - popup_set_header(popup, "iButton", 82, 18, AlignCenter, AlignBottom); - popup_set_text(popup, ibutton->text_store, 82, 22, AlignCenter, AlignTop); - break; + widget_add_string_multiline_element( + widget, 90, 10, AlignCenter, AlignTop, FontPrimary, "iButton\nemulating"); + widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44); + widget_add_text_box_element( + widget, 54, 39, 75, 22, AlignCenter, AlignCenter, ibutton->text_store, true); - default: - popup_set_header(popup, "iButton", 82, 24, AlignCenter, AlignBottom); - popup_set_text(popup, ibutton->text_store, 82, 28, AlignCenter, AlignTop); - break; - } - - popup_set_icon(popup, 2, 10, &I_iButtonKey_49x44); - - view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup); + view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget); ibutton_worker_emulate_set_callback( ibutton->key_worker, ibutton_scene_emulate_callback, ibutton); @@ -122,10 +104,7 @@ bool ibutton_scene_emulate_on_event(void* context, SceneManagerEvent event) { void ibutton_scene_emulate_on_exit(void* context) { iButton* ibutton = context; - Popup* popup = ibutton->popup; ibutton_worker_stop(ibutton->key_worker); - popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); - popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); - popup_set_icon(popup, 0, 0, NULL); + widget_reset(ibutton->widget); ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop); } diff --git a/applications/main/ibutton/scenes/ibutton_scene_info.c b/applications/main/ibutton/scenes/ibutton_scene_info.c index bd364ada8..9eec2bee1 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_info.c +++ b/applications/main/ibutton/scenes/ibutton_scene_info.c @@ -14,7 +14,7 @@ void ibutton_scene_info_on_enter(void* context) { ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name)); widget_add_text_box_element( - widget, 0, 0, 128, 28, AlignCenter, AlignCenter, ibutton->text_store, false); + widget, 0, 0, 128, 23, AlignCenter, AlignCenter, ibutton->text_store, true); switch(ibutton_key_get_type(key)) { case iButtonKeyDS1990: @@ -29,26 +29,24 @@ void ibutton_scene_info_on_enter(void* context) { key_data[5], key_data[6], key_data[7]); - widget_add_string_element( - widget, 64, 51, AlignCenter, AlignBottom, FontSecondary, "Dallas"); + widget_add_string_element(widget, 64, 36, AlignCenter, AlignBottom, FontPrimary, "Dallas"); break; case iButtonKeyMetakom: ibutton_text_store_set( ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]); widget_add_string_element( - widget, 64, 51, AlignCenter, AlignBottom, FontSecondary, "Metakom"); + widget, 64, 36, AlignCenter, AlignBottom, FontPrimary, "Metakom"); break; case iButtonKeyCyfral: ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]); - widget_add_string_element( - widget, 64, 51, AlignCenter, AlignBottom, FontSecondary, "Cyfral"); + widget_add_string_element(widget, 64, 36, AlignCenter, AlignBottom, FontPrimary, "Cyfral"); break; } widget_add_string_element( - widget, 64, 35, AlignCenter, AlignBottom, FontPrimary, ibutton->text_store); + widget, 64, 50, AlignCenter, AlignBottom, FontSecondary, ibutton->text_store); view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget); diff --git a/applications/main/ibutton/scenes/ibutton_scene_save_success.c b/applications/main/ibutton/scenes/ibutton_scene_save_success.c index 6c24a897c..43237f429 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_save_success.c +++ b/applications/main/ibutton/scenes/ibutton_scene_save_success.c @@ -29,10 +29,8 @@ bool ibutton_scene_save_success_on_event(void* context, SceneManagerEvent event) if(event.type == SceneManagerEventTypeCustom) { consumed = true; if(event.event == iButtonCustomEventBack) { - const uint32_t possible_scenes[] = { - iButtonSceneReadKeyMenu, iButtonSceneSavedKeyMenu, iButtonSceneAddType}; - scene_manager_search_and_switch_to_previous_scene_one_of( - ibutton->scene_manager, possible_scenes, COUNT_OF(possible_scenes)); + scene_manager_search_and_switch_to_another_scene( + ibutton->scene_manager, iButtonSceneSelectKey); } } diff --git a/applications/main/ibutton/scenes/ibutton_scene_write.c b/applications/main/ibutton/scenes/ibutton_scene_write.c index 195758d2c..af65575c2 100644 --- a/applications/main/ibutton/scenes/ibutton_scene_write.c +++ b/applications/main/ibutton/scenes/ibutton_scene_write.c @@ -14,8 +14,8 @@ static void ibutton_scene_write_callback(void* context, iButtonWorkerWriteResult void ibutton_scene_write_on_enter(void* context) { iButton* ibutton = context; - Popup* popup = ibutton->popup; iButtonKey* key = ibutton->key; + Widget* widget = ibutton->widget; iButtonWorker* worker = ibutton->key_worker; const uint8_t* key_data = ibutton_key_get_data_p(key); @@ -26,19 +26,16 @@ void ibutton_scene_write_on_enter(void* context) { path_extract_filename(ibutton->file_path, key_name, true); } - uint8_t line_count = 2; - // check that stored key has name if(!string_empty_p(key_name)) { - ibutton_text_store_set(ibutton, "writing\n%s", string_get_cstr(key_name)); - line_count = 2; + ibutton_text_store_set(ibutton, "%s", string_get_cstr(key_name)); } else { // if not, show key data switch(ibutton_key_get_type(key)) { case iButtonKeyDS1990: ibutton_text_store_set( ibutton, - "writing\n%02X %02X %02X %02X\n%02X %02X %02X %02X", + "%02X %02X %02X %02X\n%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], @@ -47,40 +44,24 @@ void ibutton_scene_write_on_enter(void* context) { key_data[5], key_data[6], key_data[7]); - line_count = 3; break; case iButtonKeyCyfral: - ibutton_text_store_set(ibutton, "writing\n%02X %02X", key_data[0], key_data[1]); - line_count = 2; + ibutton_text_store_set(ibutton, "%02X %02X", key_data[0], key_data[1]); break; case iButtonKeyMetakom: ibutton_text_store_set( - ibutton, - "writing\n%02X %02X %02X %02X", - key_data[0], - key_data[1], - key_data[2], - key_data[3]); - line_count = 2; + ibutton, "%02X %02X %02X %02X", key_data[0], key_data[1], key_data[2], key_data[3]); break; } } - switch(line_count) { - case 3: - popup_set_header(popup, "iButton", 82, 18, AlignCenter, AlignBottom); - popup_set_text(popup, ibutton->text_store, 82, 22, AlignCenter, AlignTop); - break; + widget_add_string_multiline_element( + widget, 90, 10, AlignCenter, AlignTop, FontPrimary, "iButton\nwriting"); + widget_add_icon_element(widget, 3, 10, &I_iButtonKey_49x44); + widget_add_text_box_element( + widget, 54, 39, 75, 22, AlignCenter, AlignCenter, ibutton->text_store, true); - default: - popup_set_header(popup, "iButton", 82, 24, AlignCenter, AlignBottom); - popup_set_text(popup, ibutton->text_store, 82, 28, AlignCenter, AlignTop); - break; - } - - popup_set_icon(popup, 2, 10, &I_iButtonKey_49x44); - - view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewPopup); + view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewWidget); ibutton_worker_write_set_callback(worker, ibutton_scene_write_callback, ibutton); ibutton_worker_write_start(worker, key); @@ -114,11 +95,8 @@ bool ibutton_scene_write_on_event(void* context, SceneManagerEvent event) { void ibutton_scene_write_on_exit(void* context) { iButton* ibutton = context; - Popup* popup = ibutton->popup; ibutton_worker_stop(ibutton->key_worker); - popup_set_header(popup, NULL, 0, 0, AlignCenter, AlignBottom); - popup_set_text(popup, NULL, 0, 0, AlignCenter, AlignTop); - popup_set_icon(popup, 0, 0, NULL); + widget_reset(ibutton->widget); ibutton_notification_message(ibutton, iButtonNotificationMessageBlinkStop); } diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_write.c b/applications/main/lfrfid/scenes/lfrfid_scene_write.c index 4b03bac15..8e791d529 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_write.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_write.c @@ -38,7 +38,6 @@ void lfrfid_scene_write_on_enter(void* context) { view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup); size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id); - app->old_key_data = (uint8_t*)malloc(size); protocol_dict_get_data(app->dict, app->protocol_id, app->old_key_data, size); lfrfid_worker_start_thread(app->lfworker); @@ -92,5 +91,4 @@ void lfrfid_scene_write_on_exit(void* context) { size_t size = protocol_dict_get_data_size(app->dict, app->protocol_id); protocol_dict_set_data(app->dict, app->protocol_id, app->old_key_data, size); - free(app->old_key_data); } From 0f9ea925d30f7a6183abe1002d680e3d1613a159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=82=E3=81=8F?= Date: Fri, 30 Sep 2022 22:03:57 +0900 Subject: [PATCH 03/10] UnitTests: fix thread join test (#1808) --- applications/debug/unit_tests/storage/storage_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/debug/unit_tests/storage/storage_test.c b/applications/debug/unit_tests/storage/storage_test.c index c3628a4f9..099be0d5c 100644 --- a/applications/debug/unit_tests/storage/storage_test.c +++ b/applications/debug/unit_tests/storage/storage_test.c @@ -58,7 +58,7 @@ MU_TEST(storage_file_open_lock) { storage_file_close(file); // file_locker thread stop - mu_check(furi_thread_join(locker_thread) == FuriStatusOk); + mu_check(furi_thread_join(locker_thread)); furi_thread_free(locker_thread); // clean data @@ -148,7 +148,7 @@ MU_TEST(storage_dir_open_lock) { storage_dir_close(file); // file_locker thread stop - mu_check(furi_thread_join(locker_thread) == FuriStatusOk); + mu_check(furi_thread_join(locker_thread)); furi_thread_free(locker_thread); // clean data From cea14ae9c5843dcce3b4d36985811bd66bcb54a3 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 06:23:09 +0300 Subject: [PATCH 04/10] fix dir creation bug, save files only for RAW TODO: files are broken when they have more than 512 elements in one line Split file to 512 element chunks as it done in regular Read RAW --- applications/main/subghz/subghz_history.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 154bfa8f2..cb8550ed9 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -93,7 +93,7 @@ bool subghz_history_clear_dir_or_create(SubGhzHistory* instance, bool only_remov // Uncomment it // Stage 2 - create dir - if(!only_remove_dir && res) { + if(!only_remove_dir) { res = storage_simply_mkdir(instance->storage, SUBGHZ_HISTORY_TMP_DIR); #if FURI_DEBUG FURI_LOG_D(TAG, "storage_simply_mkdir done: %s", res ? "true" : "false"); @@ -189,9 +189,9 @@ void subghz_history_reset(SubGhzHistory* instance) { instance->last_index_write = 0; instance->code_last_hash_data = 0; - if(instance->write_tmp_files) { + /*if(instance->write_tmp_files) { instance->write_tmp_files = subghz_history_clear_dir_or_create(instance, false); - } + }*/ } uint16_t subghz_history_get_item(SubGhzHistory* instance) { @@ -329,6 +329,8 @@ bool subghz_history_add_to_history( string_init(item->item_str); string_init(item->protocol_name); + bool tmp_file_for_raw = false; + // At this point file mapped to memory otherwise file cannot decoded item->flipper_string = flipper_format_string_alloc(); subghz_protocol_decoder_base_serialize(decoder_base, item->flipper_string, preset); @@ -357,6 +359,7 @@ bool subghz_history_add_to_history( if(!flipper_format_rewind(item->flipper_string)) { FURI_LOG_E(TAG, "Rewind error"); } + tmp_file_for_raw = true; break; } else if(!strcmp(string_get_cstr(instance->tmp_string), "KeeLoq")) { @@ -414,7 +417,7 @@ bool subghz_history_add_to_history( // If we can write to files //bool no_close = false; - if(instance->write_tmp_files) { + if(instance->write_tmp_files && tmp_file_for_raw) { string_t filename; string_t dir_path; string_init(filename); From 85eb740559a5d2b2ab57fb899952e8fdf25845ca Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 06:38:34 +0300 Subject: [PATCH 05/10] do not save detect raw on/off settings --- .../subghz/scenes/subghz_scene_read_raw.c | 2 +- .../scenes/subghz_scene_receiver_config.c | 31 +++++++++++++++++-- .../main/subghz/scenes/subghz_scene_start.c | 6 +++- applications/main/subghz/subghz.c | 7 ++--- .../main/subghz/subghz_last_settings.c | 24 -------------- .../main/subghz/subghz_last_settings.h | 7 ----- 6 files changed, 37 insertions(+), 40 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 3eac03dec..7392221dc 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -341,5 +341,5 @@ void subghz_scene_read_raw_on_exit(void* context) { notification_message(subghz->notifications, &sequence_reset_rgb); //filter restoration - subghz_last_settings_set_detect_raw_values(subghz); + subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); } \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index b782f5a31..0175cd0fd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -29,6 +29,11 @@ const char* const detect_raw_text[DETECT_RAW_COUNT] = { "ON", }; +const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = { + SubGhzProtocolFlag_Decodable, + SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW, +}; + #define RSSI_THRESHOLD_COUNT 7 const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = { "-72db", @@ -100,6 +105,20 @@ uint8_t subghz_scene_receiver_config_hopper_value_index( } } +uint8_t subghz_scene_receiver_config_detect_raw_value_index( + const SubGhzProtocolFlag value, + const SubGhzProtocolFlag values[], + uint8_t values_count) { + uint8_t index = 0; + for(uint8_t i = 0; i < values_count; i++) { + if(value == values[i]) { + index = i; + break; + } + } + return index; +} + uint8_t subghz_scene_receiver_config_rssi_threshold_value_index( const int value, const int values[], @@ -167,9 +186,12 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, detect_raw_text[index]); - subghz->last_settings->detect_raw = index; + subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]); - subghz_last_settings_set_detect_raw_values(subghz); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + (index == 1)); } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -282,7 +304,10 @@ void subghz_scene_receiver_config_on_enter(void* context) { DETECT_RAW_COUNT, subghz_scene_receiver_config_set_detect_raw, subghz); - value_index = subghz->last_settings->detect_raw; + value_index = subghz_scene_receiver_config_detect_raw_value_index( + subghz_receiver_get_filter(subghz->txrx->receiver), + detect_raw_value, + DETECT_RAW_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, detect_raw_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index f64e29e0c..35c7ecb9c 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -21,7 +21,11 @@ void subghz_scene_start_on_enter(void* context) { if(subghz->state_notifications == SubGhzNotificationStateStarting) { subghz->state_notifications = SubGhzNotificationStateIDLE; } - subghz_last_settings_set_detect_raw_values(subghz); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + false); + subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); submenu_add_item( subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 4b7c9077c..8b9dd399f 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -183,10 +183,9 @@ SubGhz* subghz_alloc() { #if FURI_DEBUG FURI_LOG_D( TAG, - "last frequency: %d, preset: %d, detect_raw: %d", + "last frequency: %d, preset: %d", subghz->last_settings->frequency, - subghz->last_settings->preset, - subghz->last_settings->detect_raw); + subghz->last_settings->preset); #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); @@ -216,7 +215,7 @@ SubGhz* subghz_alloc() { subghz_environment_set_nice_flor_s_rainbow_table_file_name( subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); - subghz_last_settings_set_detect_raw_values(subghz); + subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); subghz_worker_set_overrun_callback( subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 8dd2c165a..78bb702b7 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,6 +1,5 @@ #include "subghz_last_settings.h" #include "subghz_i.h" -#include #define TAG "SubGhzLastSettings" @@ -11,11 +10,9 @@ // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 -#define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0 #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" #define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" -#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -38,7 +35,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count uint32_t temp_frequency = 0; int32_t temp_preset = 0; - uint32_t temp_read_raw = 0; if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { @@ -46,8 +42,6 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1); flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1); - flipper_format_read_uint32( - fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, (uint32_t*)&temp_read_raw, 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -56,10 +50,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count FURI_LOG_W(TAG, "Last used frequency not found or can't be used!"); instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; - instance->detect_raw = SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW; } else { instance->frequency = temp_frequency; - instance->detect_raw = temp_read_raw; if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { FURI_LOG_W(TAG, "Last used preset no found"); @@ -105,10 +97,6 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) { break; } - if(!flipper_format_insert_or_update_uint32( - file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, &instance->detect_raw, 1)) { - break; - } saved = true; } while(0); @@ -122,15 +110,3 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { return saved; } - -void subghz_last_settings_set_detect_raw_values(void* context) { - furi_assert(context); - SubGhz* instance = (SubGhz*)context; - bool is_detect_raw = instance->last_settings->detect_raw > 0; - subghz_receiver_set_filter( - instance->txrx->receiver, is_detect_raw ? DETECT_RAW_TRUE : DETECT_RAW_FALSE); - subghz_protocol_decoder_raw_set_auto_mode( - subghz_receiver_search_decoder_base_by_name( - instance->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), - is_detect_raw); -} \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 5efc7ebb0..7e42650c7 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -4,14 +4,9 @@ #include #include #include -#include - -#define DETECT_RAW_FALSE SubGhzProtocolFlag_Decodable -#define DETECT_RAW_TRUE SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW typedef struct { uint32_t frequency; - uint32_t detect_raw; int32_t preset; } SubGhzLastSettings; @@ -22,5 +17,3 @@ void subghz_last_settings_free(SubGhzLastSettings* instance); void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count); bool subghz_last_settings_save(SubGhzLastSettings* instance); - -void subghz_last_settings_set_detect_raw_values(void* context); \ No newline at end of file From e2faf31b4587f18eec6ad4c15e59eb3e4a554101 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 07:34:39 +0300 Subject: [PATCH 06/10] debug in subghz only when compiled with DEBUG=1 --- applications/main/subghz/scenes/subghz_scene_config.h | 2 ++ applications/main/subghz/scenes/subghz_scene_start.c | 8 +++++++- applications/main/subghz/scenes/subghz_scene_test.c | 2 ++ .../main/subghz/scenes/subghz_scene_test_carrier.c | 2 ++ .../main/subghz/scenes/subghz_scene_test_packet.c | 2 ++ .../main/subghz/scenes/subghz_scene_test_static.c | 2 ++ applications/main/subghz/subghz.c | 5 ++++- applications/main/subghz/subghz_i.h | 5 ++++- 8 files changed, 25 insertions(+), 3 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_config.h b/applications/main/subghz/scenes/subghz_scene_config.h index c2731910b..fcc579d93 100644 --- a/applications/main/subghz/scenes/subghz_scene_config.h +++ b/applications/main/subghz/scenes/subghz_scene_config.h @@ -12,10 +12,12 @@ ADD_SCENE(subghz, show_only_rx, ShowOnlyRx) ADD_SCENE(subghz, saved_menu, SavedMenu) ADD_SCENE(subghz, delete, Delete) ADD_SCENE(subghz, delete_success, DeleteSuccess) +#if FURI_DEBUG ADD_SCENE(subghz, test, Test) ADD_SCENE(subghz, test_static, TestStatic) ADD_SCENE(subghz, test_carrier, TestCarrier) ADD_SCENE(subghz, test_packet, TestPacket) +#endif ADD_SCENE(subghz, set_type, SetType) ADD_SCENE(subghz, set_fix_faac_868, SetFixFaac868) ADD_SCENE(subghz, set_cnt_faac_868, SetCntFaac868) diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index 35c7ecb9c..f9500dc96 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -49,10 +49,12 @@ void subghz_scene_start_on_enter(void* context) { SubmenuIndexFrequencyAnalyzer, subghz_scene_start_submenu_callback, subghz); +#if FURI_DEBUG if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { submenu_add_item( subghz->submenu, "Test", SubmenuIndexTest, subghz_scene_start_submenu_callback, subghz); } +#endif submenu_set_selected_item( subghz->submenu, scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneStart)); @@ -93,12 +95,16 @@ bool subghz_scene_start_on_event(void* context, SceneManagerEvent event) { subghz->scene_manager, SubGhzSceneStart, SubmenuIndexFrequencyAnalyzer); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneFrequencyAnalyzer); return true; - } else if(event.event == SubmenuIndexTest) { + + } +#if FURI_DEBUG + else if(event.event == SubmenuIndexTest) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneStart, SubmenuIndexTest); scene_manager_next_scene(subghz->scene_manager, SubGhzSceneTest); return true; } +#endif } return false; } diff --git a/applications/main/subghz/scenes/subghz_scene_test.c b/applications/main/subghz/scenes/subghz_scene_test.c index 65f9bbdef..64473015b 100644 --- a/applications/main/subghz/scenes/subghz_scene_test.c +++ b/applications/main/subghz/scenes/subghz_scene_test.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" enum SubmenuIndex { @@ -59,3 +60,4 @@ void subghz_scene_test_on_exit(void* context) { SubGhz* subghz = context; submenu_reset(subghz->submenu); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_test_carrier.c b/applications/main/subghz/scenes/subghz_scene_test_carrier.c index 9677792ba..4682a627c 100644 --- a/applications/main/subghz/scenes/subghz_scene_test_carrier.c +++ b/applications/main/subghz/scenes/subghz_scene_test_carrier.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" #include "../views/subghz_test_carrier.h" @@ -28,3 +29,4 @@ bool subghz_scene_test_carrier_on_event(void* context, SceneManagerEvent event) void subghz_scene_test_carrier_on_exit(void* context) { UNUSED(context); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_test_packet.c b/applications/main/subghz/scenes/subghz_scene_test_packet.c index 99f0ab179..4757f9f3a 100644 --- a/applications/main/subghz/scenes/subghz_scene_test_packet.c +++ b/applications/main/subghz/scenes/subghz_scene_test_packet.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" #include "../views/subghz_test_packet.h" @@ -28,3 +29,4 @@ bool subghz_scene_test_packet_on_event(void* context, SceneManagerEvent event) { void subghz_scene_test_packet_on_exit(void* context) { UNUSED(context); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_test_static.c b/applications/main/subghz/scenes/subghz_scene_test_static.c index 10e6d02a1..959eb75b8 100644 --- a/applications/main/subghz/scenes/subghz_scene_test_static.c +++ b/applications/main/subghz/scenes/subghz_scene_test_static.c @@ -1,3 +1,4 @@ +#if FURI_DEBUG #include "../subghz_i.h" #include "../views/subghz_test_static.h" @@ -28,3 +29,4 @@ bool subghz_scene_test_static_on_event(void* context, SceneManagerEvent event) { void subghz_scene_test_static_on_exit(void* context) { UNUSED(context); } +#endif \ No newline at end of file diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 8b9dd399f..30e10b106 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -151,6 +151,7 @@ SubGhz* subghz_alloc() { SubGhzViewIdReadRAW, subghz_read_raw_get_view(subghz->subghz_read_raw)); +#if FURI_DEBUG // Carrier Test Module subghz->subghz_test_carrier = subghz_test_carrier_alloc(); view_dispatcher_add_view( @@ -171,6 +172,7 @@ SubGhz* subghz_alloc() { subghz->view_dispatcher, SubGhzViewIdStatic, subghz_test_static_get_view(subghz->subghz_test_static)); +#endif //init setting subghz->setting = subghz_setting_alloc(); @@ -239,6 +241,7 @@ void subghz_free(SubGhz* subghz) { subghz->rpc_ctx = NULL; } +#if FURI_DEBUG // Packet Test view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTestPacket); subghz_test_packet_free(subghz->subghz_test_packet); @@ -250,7 +253,7 @@ void subghz_free(SubGhz* subghz) { // Static view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic); subghz_test_static_free(subghz->subghz_test_static); - +#endif // Receiver view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver); subghz_view_receiver_free(subghz->subghz_receiver); diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 8872d31f6..a1d68c531 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -7,10 +7,11 @@ #include "views/subghz_frequency_analyzer.h" #include "views/subghz_read_raw.h" +#if FURI_DEBUG #include "views/subghz_test_static.h" #include "views/subghz_test_carrier.h" #include "views/subghz_test_packet.h" - +#endif // #include // #include #include @@ -96,9 +97,11 @@ struct SubGhz { SubGhzFrequencyAnalyzer* subghz_frequency_analyzer; SubGhzReadRAW* subghz_read_raw; +#if FURI_DEBUG SubGhzTestStatic* subghz_test_static; SubGhzTestCarrier* subghz_test_carrier; SubGhzTestPacket* subghz_test_packet; +#endif string_t error_str; SubGhzSetting* setting; SubGhzLastSettings* last_settings; From 6bf306200ee3a30e555082cf8dd91a7c592990a2 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 08:50:41 +0300 Subject: [PATCH 07/10] make loading subghz file from favourites a bit faster --- .../subghz/scenes/subghz_scene_read_raw.c | 22 +- applications/main/subghz/subghz.c | 239 +++++++++++------- applications/main/subghz/subghz_i.h | 1 + applications/main/subghz/subghz_setting.c | 89 +++---- applications/main/subghz/subghz_setting.h | 2 +- .../main/subghz/views/subghz_read_raw.c | 52 ++-- .../main/subghz/views/subghz_read_raw.h | 2 +- applications/main/unirfremix/unirfremix_app.c | 2 +- 8 files changed, 237 insertions(+), 172 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 7392221dc..df7d21680 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -134,12 +134,22 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //Restore default setting - subghz_preset_init( - subghz, - subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), - subghz->last_settings->frequency, - NULL, - 0); + if(subghz->raw_send_only) { + subghz_preset_init( + subghz, + "AM650", + subghz_setting_get_default_frequency(subghz->setting), + NULL, + 0); + } else { + subghz_preset_init( + subghz, + subghz_setting_get_preset_name( + subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, + NULL, + 0); + } if(!scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneSaved)) { if(!scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 30e10b106..284f8dc2a 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -61,7 +61,7 @@ void subghz_blink_stop(SubGhz* instance) { notification_message(instance->notifications, &sequence_blink_stop); } -SubGhz* subghz_alloc() { +SubGhz* subghz_alloc(bool alloc_for_tx_only) { SubGhz* subghz = malloc(sizeof(SubGhz)); string_init(subghz->file_path); @@ -88,38 +88,43 @@ SubGhz* subghz_alloc() { // Open Notification record subghz->notifications = furi_record_open(RECORD_NOTIFICATION); - // SubMenu - subghz->submenu = submenu_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu)); - - // Receiver - subghz->subghz_receiver = subghz_view_receiver_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, - SubGhzViewIdReceiver, - subghz_view_receiver_get_view(subghz->subghz_receiver)); + if(!alloc_for_tx_only) { + // SubMenu + subghz->submenu = submenu_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, SubGhzViewIdMenu, submenu_get_view(subghz->submenu)); + // Receiver + subghz->subghz_receiver = subghz_view_receiver_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdReceiver, + subghz_view_receiver_get_view(subghz->subghz_receiver)); + } // Popup subghz->popup = popup_alloc(); view_dispatcher_add_view( subghz->view_dispatcher, SubGhzViewIdPopup, popup_get_view(subghz->popup)); + if(!alloc_for_tx_only) { + // Text Input + subghz->text_input = text_input_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdTextInput, + text_input_get_view(subghz->text_input)); - // Text Input - subghz->text_input = text_input_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdTextInput, text_input_get_view(subghz->text_input)); - - // Byte Input - subghz->byte_input = byte_input_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdByteInput, byte_input_get_view(subghz->byte_input)); - - // Custom Widget - subghz->widget = widget_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget)); + // Byte Input + subghz->byte_input = byte_input_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdByteInput, + byte_input_get_view(subghz->byte_input)); + // Custom Widget + subghz->widget = widget_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, SubGhzViewIdWidget, widget_get_view(subghz->widget)); + } //Dialog subghz->dialogs = furi_record_open(RECORD_DIALOGS); @@ -129,23 +134,23 @@ SubGhz* subghz_alloc() { subghz->view_dispatcher, SubGhzViewIdTransmitter, subghz_view_transmitter_get_view(subghz->subghz_transmitter)); + if(!alloc_for_tx_only) { + // Variable Item List + subghz->variable_item_list = variable_item_list_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdVariableItemList, + variable_item_list_get_view(subghz->variable_item_list)); - // Variable Item List - subghz->variable_item_list = variable_item_list_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, - SubGhzViewIdVariableItemList, - variable_item_list_get_view(subghz->variable_item_list)); - - // Frequency Analyzer - subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc(); - view_dispatcher_add_view( - subghz->view_dispatcher, - SubGhzViewIdFrequencyAnalyzer, - subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer)); - + // Frequency Analyzer + subghz->subghz_frequency_analyzer = subghz_frequency_analyzer_alloc(); + view_dispatcher_add_view( + subghz->view_dispatcher, + SubGhzViewIdFrequencyAnalyzer, + subghz_frequency_analyzer_get_view(subghz->subghz_frequency_analyzer)); + } // Read RAW - subghz->subghz_read_raw = subghz_read_raw_alloc(); + subghz->subghz_read_raw = subghz_read_raw_alloc(alloc_for_tx_only); view_dispatcher_add_view( subghz->view_dispatcher, SubGhzViewIdReadRAW, @@ -176,38 +181,51 @@ SubGhz* subghz_alloc() { //init setting subghz->setting = subghz_setting_alloc(); - subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user")); + if(alloc_for_tx_only) { + subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"), false); + } else { + subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user"), true); + } // Load last used values for Read, Read RAW, etc. or default - subghz->last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load( - subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); + if(!alloc_for_tx_only) { + subghz->last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load( + subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); #if FURI_DEBUG - FURI_LOG_D( - TAG, - "last frequency: %d, preset: %d", - subghz->last_settings->frequency, - subghz->last_settings->preset); + FURI_LOG_D( + TAG, + "last frequency: %d, preset: %d", + subghz->last_settings->frequency, + subghz->last_settings->preset); #endif - subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); - + subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); + } //init Worker & Protocol & History & KeyBoard subghz->lock = SubGhzLockOff; subghz->txrx = malloc(sizeof(SubGhzTxRx)); subghz->txrx->preset = malloc(sizeof(SubGhzPresetDefinition)); string_init(subghz->txrx->preset->name); - subghz_preset_init( - subghz, - subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), - subghz->last_settings->frequency, - NULL, - 0); - + if(!alloc_for_tx_only) { + subghz_preset_init( + subghz, + subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, + NULL, + 0); + } else { + subghz_preset_init( + subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0); + } subghz->txrx->txrx_state = SubGhzTxRxStateSleep; subghz->txrx->hopper_state = SubGhzHopperStateOFF; subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; - subghz->txrx->history = subghz_history_alloc(); - subghz->txrx->worker = subghz_worker_alloc(); + if(!alloc_for_tx_only) { + subghz->txrx->history = subghz_history_alloc(); + } + if(!alloc_for_tx_only) { + subghz->txrx->worker = subghz_worker_alloc(); + } subghz->txrx->fff_data = flipper_format_string_alloc(); subghz->txrx->secure_data = malloc(sizeof(SecureData)); @@ -216,14 +234,17 @@ SubGhz* subghz_alloc() { subghz->txrx->environment, EXT_PATH("subghz/assets/came_atomo")); subghz_environment_set_nice_flor_s_rainbow_table_file_name( subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); + subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); - subghz_worker_set_overrun_callback( - subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); - subghz_worker_set_pair_callback( - subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); - subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); + if(!alloc_for_tx_only) { + subghz_worker_set_overrun_callback( + subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + subghz_worker_set_pair_callback( + subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); + } //Init Error_str string_init(subghz->error_str); @@ -231,7 +252,7 @@ SubGhz* subghz_alloc() { return subghz; } -void subghz_free(SubGhz* subghz) { +void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { furi_assert(subghz); if(subghz->rpc_ctx) { @@ -254,45 +275,47 @@ void subghz_free(SubGhz* subghz) { view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdStatic); subghz_test_static_free(subghz->subghz_test_static); #endif - // Receiver - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver); - subghz_view_receiver_free(subghz->subghz_receiver); - // TextInput - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput); - text_input_free(subghz->text_input); + if(!alloc_for_tx_only) { + // Receiver + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReceiver); + subghz_view_receiver_free(subghz->subghz_receiver); - // ByteInput - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdByteInput); - byte_input_free(subghz->byte_input); + // TextInput + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTextInput); + text_input_free(subghz->text_input); - // Custom Widget - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget); - widget_free(subghz->widget); + // ByteInput + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdByteInput); + byte_input_free(subghz->byte_input); + // Custom Widget + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdWidget); + widget_free(subghz->widget); + } //Dialog furi_record_close(RECORD_DIALOGS); // Transmitter view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdTransmitter); subghz_view_transmitter_free(subghz->subghz_transmitter); + if(!alloc_for_tx_only) { + // Variable Item List + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList); + variable_item_list_free(subghz->variable_item_list); - // Variable Item List - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdVariableItemList); - variable_item_list_free(subghz->variable_item_list); - - // Frequency Analyzer - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer); - subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer); - + // Frequency Analyzer + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdFrequencyAnalyzer); + subghz_frequency_analyzer_free(subghz->subghz_frequency_analyzer); + } // Read RAW view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdReadRAW); subghz_read_raw_free(subghz->subghz_read_raw); - - // Submenu - view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu); - submenu_free(subghz->submenu); - + if(!alloc_for_tx_only) { + // Submenu + view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdMenu); + submenu_free(subghz->submenu); + } // Popup view_dispatcher_remove_view(subghz->view_dispatcher, SubGhzViewIdPopup); popup_free(subghz->popup); @@ -309,14 +332,21 @@ void subghz_free(SubGhz* subghz) { //setting subghz_setting_free(subghz->setting); - subghz_last_settings_free(subghz->last_settings); - + if(!alloc_for_tx_only) { + subghz_last_settings_free(subghz->last_settings); + } //Worker & Protocol & History + subghz_receiver_free(subghz->txrx->receiver); + subghz_environment_free(subghz->txrx->environment); - subghz_worker_free(subghz->txrx->worker); + if(!alloc_for_tx_only) { + subghz_worker_free(subghz->txrx->worker); + } flipper_format_free(subghz->txrx->fff_data); - subghz_history_free(subghz->txrx->history); + if(!alloc_for_tx_only) { + subghz_history_free(subghz->txrx->history); + } string_clear(subghz->txrx->preset->name); free(subghz->txrx->preset); free(subghz->txrx->secure_data); @@ -338,7 +368,20 @@ void subghz_free(SubGhz* subghz) { } int32_t subghz_app(void* p) { - SubGhz* subghz = subghz_alloc(); + bool alloc_for_tx; + if(p && strlen(p)) { + alloc_for_tx = true; + } else { + alloc_for_tx = false; + } + + SubGhz* subghz = subghz_alloc(alloc_for_tx); + + if(alloc_for_tx) { + subghz->raw_send_only = true; + } else { + subghz->raw_send_only = false; + } //Load database bool load_database = subghz_environment_load_keystore( @@ -397,7 +440,7 @@ int32_t subghz_app(void* p) { furi_hal_power_suppress_charge_exit(); - subghz_free(subghz); + subghz_free(subghz, alloc_for_tx); return 0; } diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index a1d68c531..b177c1ba7 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -97,6 +97,7 @@ struct SubGhz { SubGhzFrequencyAnalyzer* subghz_frequency_analyzer; SubGhzReadRAW* subghz_read_raw; + bool raw_send_only; #if FURI_DEBUG SubGhzTestStatic* subghz_test_static; SubGhzTestCarrier* subghz_test_carrier; diff --git a/applications/main/subghz/subghz_setting.c b/applications/main/subghz/subghz_setting.c index 2e94011cf..8f116322f 100644 --- a/applications/main/subghz/subghz_setting.c +++ b/applications/main/subghz/subghz_setting.c @@ -181,7 +181,7 @@ void subghz_setting_load_default(SubGhzSetting* instance) { instance, subghz_frequency_list, subghz_hopper_frequency_list); } -void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { +void subghz_setting_load(SubGhzSetting* instance, const char* file_path, bool not_skip_frequencies) { furi_assert(instance); Storage* storage = furi_record_open(RECORD_STORAGE); @@ -214,53 +214,56 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { } // Standard frequencies (optional) - temp_bool = true; - flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1); - if(!temp_bool) { - FURI_LOG_I(TAG, "Removing standard frequencies"); - FrequencyList_reset(instance->frequencies); - FrequencyList_reset(instance->hopper_frequencies); - } else { - FURI_LOG_I(TAG, "Keeping standard frequencies"); - } - - // Load frequencies - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - while(flipper_format_read_uint32( - fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) { - if(furi_hal_subghz_is_frequency_valid(temp_data32)) { - FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32); - FrequencyList_push_back(instance->frequencies, temp_data32); + if(not_skip_frequencies) { + temp_bool = true; + flipper_format_read_bool(fff_data_file, "Add_standard_frequencies", &temp_bool, 1); + if(!temp_bool) { + FURI_LOG_I(TAG, "Removing standard frequencies"); + FrequencyList_reset(instance->frequencies); + FrequencyList_reset(instance->hopper_frequencies); } else { - FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32); + FURI_LOG_I(TAG, "Keeping standard frequencies"); } - } - // Load hopper frequencies - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - while(flipper_format_read_uint32( - fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) { - if(furi_hal_subghz_is_frequency_valid(temp_data32)) { - FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32); - FrequencyList_push_back(instance->hopper_frequencies, temp_data32); - } else { - FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32); + // Load frequencies + if(!flipper_format_rewind(fff_data_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + while(flipper_format_read_uint32( + fff_data_file, "Frequency", (uint32_t*)&temp_data32, 1)) { + if(furi_hal_subghz_is_frequency_valid(temp_data32)) { + FURI_LOG_I(TAG, "Frequency loaded %lu", temp_data32); + FrequencyList_push_back(instance->frequencies, temp_data32); + } else { + FURI_LOG_E(TAG, "Frequency not supported %lu", temp_data32); + } } - } - // Default frequency (optional) - if(!flipper_format_rewind(fff_data_file)) { - FURI_LOG_E(TAG, "Rewind error"); - break; - } - if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) { - subghz_setting_set_default_frequency(instance, temp_data32); + // Load hopper frequencies + if(!flipper_format_rewind(fff_data_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + while(flipper_format_read_uint32( + fff_data_file, "Hopper_frequency", (uint32_t*)&temp_data32, 1)) { + if(furi_hal_subghz_is_frequency_valid(temp_data32)) { + FURI_LOG_I(TAG, "Hopper frequency loaded %lu", temp_data32); + FrequencyList_push_back(instance->hopper_frequencies, temp_data32); + } else { + FURI_LOG_E(TAG, "Hopper frequency not supported %lu", temp_data32); + } + } + + // Default frequency (optional) + if(!flipper_format_rewind(fff_data_file)) { + FURI_LOG_E(TAG, "Rewind error"); + break; + } + if(flipper_format_read_uint32( + fff_data_file, "Default_frequency", &temp_data32, 1)) { + subghz_setting_set_default_frequency(instance, temp_data32); + } } // custom preset (optional) diff --git a/applications/main/subghz/subghz_setting.h b/applications/main/subghz/subghz_setting.h index d6fde1bd6..3b3b1131a 100644 --- a/applications/main/subghz/subghz_setting.h +++ b/applications/main/subghz/subghz_setting.h @@ -14,7 +14,7 @@ SubGhzSetting* subghz_setting_alloc(void); void subghz_setting_free(SubGhzSetting* instance); -void subghz_setting_load(SubGhzSetting* instance, const char* file_path); +void subghz_setting_load(SubGhzSetting* instance, const char* file_path, bool not_skip_frequencies); size_t subghz_setting_get_frequency_count(SubGhzSetting* instance); diff --git a/applications/main/subghz/views/subghz_read_raw.c b/applications/main/subghz/views/subghz_read_raw.c index ccffaf42f..2d24d9411 100644 --- a/applications/main/subghz/views/subghz_read_raw.c +++ b/applications/main/subghz/views/subghz_read_raw.c @@ -27,6 +27,7 @@ typedef struct { uint8_t ind_write; uint8_t ind_sin; SubGhzReadRAWStatus status; + bool raw_send_only; } SubGhzReadRAWModel; void subghz_read_raw_set_callback( @@ -232,9 +233,11 @@ void subghz_read_raw_draw(Canvas* canvas, SubGhzReadRAWModel* model) { elements_button_right(canvas, "Save"); break; case SubGhzReadRAWStatusLoadKeyIDLE: - elements_button_left(canvas, "New"); + if(!model->raw_send_only) { + elements_button_left(canvas, "New"); + elements_button_right(canvas, "More"); + } elements_button_center(canvas, "Send"); - elements_button_right(canvas, "More"); elements_text_box( canvas, 4, @@ -362,31 +365,35 @@ bool subghz_read_raw_input(InputEvent* event, void* context) { } else if(event->key == InputKeyLeft && event->type == InputTypeShort) { with_view_model( instance->view, (SubGhzReadRAWModel * model) { - if(model->status == SubGhzReadRAWStatusStart) { - //Config - instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context); - } else if( - (model->status == SubGhzReadRAWStatusIDLE) || - (model->status == SubGhzReadRAWStatusLoadKeyIDLE)) { - //Erase - model->status = SubGhzReadRAWStatusStart; - model->rssi_history_end = false; - model->ind_write = 0; - string_set_str(model->sample_write, "0 spl."); - string_reset(model->file_name); - instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context); + if(!model->raw_send_only) { + if(model->status == SubGhzReadRAWStatusStart) { + //Config + instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context); + } else if( + (model->status == SubGhzReadRAWStatusIDLE) || + (model->status == SubGhzReadRAWStatusLoadKeyIDLE)) { + //Erase + model->status = SubGhzReadRAWStatusStart; + model->rssi_history_end = false; + model->ind_write = 0; + string_set_str(model->sample_write, "0 spl."); + string_reset(model->file_name); + instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context); + } } return true; }); } else if(event->key == InputKeyRight && event->type == InputTypeShort) { with_view_model( instance->view, (SubGhzReadRAWModel * model) { - if(model->status == SubGhzReadRAWStatusIDLE) { - //Save - instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context); - } else if(model->status == SubGhzReadRAWStatusLoadKeyIDLE) { - //More - instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context); + if(!model->raw_send_only) { + if(model->status == SubGhzReadRAWStatusIDLE) { + //Save + instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context); + } else if(model->status == SubGhzReadRAWStatusLoadKeyIDLE) { + //More + instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context); + } } return true; }); @@ -487,7 +494,7 @@ void subghz_read_raw_exit(void* context) { }); } -SubGhzReadRAW* subghz_read_raw_alloc() { +SubGhzReadRAW* subghz_read_raw_alloc(bool raw_send_only) { SubGhzReadRAW* instance = malloc(sizeof(SubGhzReadRAW)); // View allocation and configuration @@ -505,6 +512,7 @@ SubGhzReadRAW* subghz_read_raw_alloc() { string_init(model->preset_str); string_init(model->sample_write); string_init(model->file_name); + model->raw_send_only = raw_send_only; model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t)); return true; }); diff --git a/applications/main/subghz/views/subghz_read_raw.h b/applications/main/subghz/views/subghz_read_raw.h index 1d4bb7dc0..a4e16ca98 100644 --- a/applications/main/subghz/views/subghz_read_raw.h +++ b/applications/main/subghz/views/subghz_read_raw.h @@ -25,7 +25,7 @@ void subghz_read_raw_set_callback( SubGhzReadRAWCallback callback, void* context); -SubGhzReadRAW* subghz_read_raw_alloc(); +SubGhzReadRAW* subghz_read_raw_alloc(bool raw_send_only); void subghz_read_raw_free(SubGhzReadRAW* subghz_static); diff --git a/applications/main/unirfremix/unirfremix_app.c b/applications/main/unirfremix/unirfremix_app.c index df2d318ae..13d47988c 100644 --- a/applications/main/unirfremix/unirfremix_app.c +++ b/applications/main/unirfremix/unirfremix_app.c @@ -827,7 +827,7 @@ static void input_callback(InputEvent* input_event, void* ctx) { void unirfremix_subghz_alloc(UniRFRemix* app) { // load subghz presets app->setting = subghz_setting_alloc(); - subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user")); + subghz_setting_load(app->setting, EXT_PATH("subghz/assets/setting_user"), false); // load mfcodes app->environment = subghz_environment_alloc(); From 63fee41a1f3db199edf5668c55bac4c20b594a57 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 09:51:27 +0300 Subject: [PATCH 08/10] enable worker back --- applications/main/subghz/subghz.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 284f8dc2a..33d93d380 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -223,9 +223,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { if(!alloc_for_tx_only) { subghz->txrx->history = subghz_history_alloc(); } - if(!alloc_for_tx_only) { - subghz->txrx->worker = subghz_worker_alloc(); - } + + subghz->txrx->worker = subghz_worker_alloc(); + subghz->txrx->fff_data = flipper_format_string_alloc(); subghz->txrx->secure_data = malloc(sizeof(SecureData)); @@ -238,13 +238,11 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); - if(!alloc_for_tx_only) { - subghz_worker_set_overrun_callback( - subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); - subghz_worker_set_pair_callback( - subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); - subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); - } + subghz_worker_set_overrun_callback( + subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); + subghz_worker_set_pair_callback( + subghz->txrx->worker, (SubGhzWorkerPairCallback)subghz_receiver_decode); + subghz_worker_set_context(subghz->txrx->worker, subghz->txrx->receiver); //Init Error_str string_init(subghz->error_str); @@ -340,9 +338,9 @@ void subghz_free(SubGhz* subghz, bool alloc_for_tx_only) { subghz_receiver_free(subghz->txrx->receiver); subghz_environment_free(subghz->txrx->environment); - if(!alloc_for_tx_only) { - subghz_worker_free(subghz->txrx->worker); - } + + subghz_worker_free(subghz->txrx->worker); + flipper_format_free(subghz->txrx->fff_data); if(!alloc_for_tx_only) { subghz_history_free(subghz->txrx->history); From 4d3f45e9112427b3b83048c5f5c3786116ab95d0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 10:18:31 +0300 Subject: [PATCH 09/10] =?UTF-8?q?Don=E2=80=99t=20show=20temp=20history=20d?= =?UTF-8?q?ir=20in=20filebrowser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- applications/services/gui/modules/file_browser_worker.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/applications/services/gui/modules/file_browser_worker.c b/applications/services/gui/modules/file_browser_worker.c index a316a0779..b533f3853 100644 --- a/applications/services/gui/modules/file_browser_worker.c +++ b/applications/services/gui/modules/file_browser_worker.c @@ -14,6 +14,7 @@ #define ASSETS_DIR "assets" #define BADUSB_LAYOUTS_DIR "layouts" +#define SUBGHZ_TEMP_DIR "tmp_history" #define BROWSER_ROOT STORAGE_ANY_PATH_PREFIX #define FILE_NAME_LEN_MAX 256 #define LONG_LOAD_THRESHOLD 100 @@ -80,7 +81,8 @@ static bool browser_filter_by_name(BrowserWorker* browser, string_t name, bool i // Skip assets folders (if enabled) if(browser->skip_assets) { return ((string_cmp_str(name, ASSETS_DIR) == 0) ? (false) : (true)) && - ((string_cmp_str(name, BADUSB_LAYOUTS_DIR) == 0) ? (false) : (true)); + ((string_cmp_str(name, BADUSB_LAYOUTS_DIR) == 0) ? (false) : (true)) && + ((string_cmp_str(name, SUBGHZ_TEMP_DIR) == 0) ? (false) : (true)); } else { return true; } From 8af749c9650eff6a78ed7a464add8ccacacae64d Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sun, 2 Oct 2022 13:50:29 +0300 Subject: [PATCH 10/10] enable saving detect raw state via define --- .../subghz/scenes/subghz_scene_read_raw.c | 6 ++- .../scenes/subghz_scene_receiver_config.c | 14 ++++++ .../main/subghz/scenes/subghz_scene_start.c | 4 ++ applications/main/subghz/subghz.c | 13 ++++++ .../main/subghz/subghz_last_settings.c | 44 +++++++++++++++++++ .../main/subghz/subghz_last_settings.h | 14 ++++++ 6 files changed, 94 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index df7d21680..b83ad700f 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -350,6 +350,10 @@ void subghz_scene_read_raw_on_exit(void* context) { subghz->state_notifications = SubGhzNotificationStateIDLE; notification_message(subghz->notifications, &sequence_reset_rgb); - //filter restoration +//filter restoration +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); +#endif } \ No newline at end of file diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 0175cd0fd..6d6627743 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -29,10 +29,12 @@ const char* const detect_raw_text[DETECT_RAW_COUNT] = { "ON", }; +#ifndef SUBGHZ_SAVE_DETECT_RAW_SETTING const SubGhzProtocolFlag detect_raw_value[DETECT_RAW_COUNT] = { SubGhzProtocolFlag_Decodable, SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW, }; +#endif #define RSSI_THRESHOLD_COUNT 7 const char* const rssi_threshold_text[RSSI_THRESHOLD_COUNT] = { @@ -105,6 +107,7 @@ uint8_t subghz_scene_receiver_config_hopper_value_index( } } +#ifndef SUBGHZ_SAVE_DETECT_RAW_SETTING uint8_t subghz_scene_receiver_config_detect_raw_value_index( const SubGhzProtocolFlag value, const SubGhzProtocolFlag values[], @@ -118,6 +121,7 @@ uint8_t subghz_scene_receiver_config_detect_raw_value_index( } return index; } +#endif uint8_t subghz_scene_receiver_config_rssi_threshold_value_index( const int value, @@ -186,12 +190,18 @@ static void subghz_scene_receiver_config_set_detect_raw(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, detect_raw_text[index]); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz->last_settings->detect_raw = index; + + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_receiver_set_filter(subghz->txrx->receiver, detect_raw_value[index]); subghz_protocol_decoder_raw_set_auto_mode( subghz_receiver_search_decoder_base_by_name( subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), (index == 1)); +#endif } static void subghz_scene_receiver_config_set_hopping_running(VariableItem* item) { @@ -304,10 +314,14 @@ void subghz_scene_receiver_config_on_enter(void* context) { DETECT_RAW_COUNT, subghz_scene_receiver_config_set_detect_raw, subghz); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + value_index = subghz->last_settings->detect_raw; +#else value_index = subghz_scene_receiver_config_detect_raw_value_index( subghz_receiver_get_filter(subghz->txrx->receiver), detect_raw_value, DETECT_RAW_COUNT); +#endif variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, detect_raw_text[value_index]); diff --git a/applications/main/subghz/scenes/subghz_scene_start.c b/applications/main/subghz/scenes/subghz_scene_start.c index f9500dc96..752fb8a92 100644 --- a/applications/main/subghz/scenes/subghz_scene_start.c +++ b/applications/main/subghz/scenes/subghz_scene_start.c @@ -21,11 +21,15 @@ void subghz_scene_start_on_enter(void* context) { if(subghz->state_notifications == SubGhzNotificationStateStarting) { subghz->state_notifications = SubGhzNotificationStateIDLE; } +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_protocol_decoder_raw_set_auto_mode( subghz_receiver_search_decoder_base_by_name( subghz->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), false); subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); +#endif submenu_add_item( subghz->submenu, "Read", SubmenuIndexRead, subghz_scene_start_submenu_callback, subghz); diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 33d93d380..176e9079e 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -193,11 +193,20 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz_last_settings_load( subghz->last_settings, subghz_setting_get_preset_count(subghz->setting)); #if FURI_DEBUG +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + FURI_LOG_D( + TAG, + "last frequency: %d, preset: %d, detect_raw: %d", + subghz->last_settings->frequency, + subghz->last_settings->preset, + subghz->last_settings->detect_raw); +#else FURI_LOG_D( TAG, "last frequency: %d, preset: %d", subghz->last_settings->frequency, subghz->last_settings->preset); +#endif #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); } @@ -236,7 +245,11 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) { subghz->txrx->environment, EXT_PATH("subghz/assets/nice_flor_s")); subghz->txrx->receiver = subghz_receiver_alloc_init(subghz->txrx->environment); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + subghz_last_settings_set_detect_raw_values(subghz); +#else subghz_receiver_set_filter(subghz->txrx->receiver, SubGhzProtocolFlag_Decodable); +#endif subghz_worker_set_overrun_callback( subghz->txrx->worker, (SubGhzWorkerOverrunCallback)subghz_receiver_reset); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 78bb702b7..91f6fc841 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,5 +1,8 @@ #include "subghz_last_settings.h" #include "subghz_i.h" +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#include +#endif #define TAG "SubGhzLastSettings" @@ -11,9 +14,17 @@ #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#define SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW 0 +#endif + #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY "Frequency" #define SUBGHZ_LAST_SETTING_FIELD_PRESET "Preset" +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#define SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW "DetectRaw" +#endif + SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); return instance; @@ -35,6 +46,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count uint32_t temp_frequency = 0; int32_t temp_preset = 0; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + uint32_t temp_read_raw = 0; +#endif if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { @@ -42,6 +56,10 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_PRESET, (int32_t*)&temp_preset, 1); flipper_format_read_uint32( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, (uint32_t*)&temp_frequency, 1); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + flipper_format_read_uint32( + fff_data_file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, (uint32_t*)&temp_read_raw, 1); +#endif } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); } @@ -50,8 +68,14 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count FURI_LOG_W(TAG, "Last used frequency not found or can't be used!"); instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + instance->detect_raw = SUBGHZ_LAST_SETTING_DEFAULT_READ_RAW; +#endif } else { instance->frequency = temp_frequency; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + instance->detect_raw = temp_read_raw; +#endif if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { FURI_LOG_W(TAG, "Last used preset no found"); @@ -97,6 +121,12 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { file, SUBGHZ_LAST_SETTING_FIELD_FREQUENCY, &instance->frequency, 1)) { break; } +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + if(!flipper_format_insert_or_update_uint32( + file, SUBGHZ_LAST_SETTING_FIELD_DETECT_RAW, &instance->detect_raw, 1)) { + break; + } +#endif saved = true; } while(0); @@ -110,3 +140,17 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { return saved; } + +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +void subghz_last_settings_set_detect_raw_values(void* context) { + furi_assert(context); + SubGhz* instance = (SubGhz*)context; + bool is_detect_raw = instance->last_settings->detect_raw > 0; + subghz_receiver_set_filter( + instance->txrx->receiver, is_detect_raw ? DETECT_RAW_TRUE : DETECT_RAW_FALSE); + subghz_protocol_decoder_raw_set_auto_mode( + subghz_receiver_search_decoder_base_by_name( + instance->txrx->receiver, SUBGHZ_PROTOCOL_RAW_NAME), + is_detect_raw); +} +#endif \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index 7e42650c7..116eacadd 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -1,12 +1,23 @@ #pragma once +// Enable saving detect raw setting state +// #define SUBGHZ_SAVE_DETECT_RAW_SETTING 1 + #include #include #include #include +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +#include +#define DETECT_RAW_FALSE SubGhzProtocolFlag_Decodable +#define DETECT_RAW_TRUE SubGhzProtocolFlag_Decodable | SubGhzProtocolFlag_RAW +#endif typedef struct { uint32_t frequency; +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING + uint32_t detect_raw; +#endif int32_t preset; } SubGhzLastSettings; @@ -17,3 +28,6 @@ void subghz_last_settings_free(SubGhzLastSettings* instance); void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count); bool subghz_last_settings_save(SubGhzLastSettings* instance); +#ifdef SUBGHZ_SAVE_DETECT_RAW_SETTING +void subghz_last_settings_set_detect_raw_values(void* context); +#endif \ No newline at end of file