From 497be7ccb055533063cb44f8209fc5a0f456df55 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 02:01:09 +0400 Subject: [PATCH 01/12] Last SubGHz settings is ready --- .../subghz/scenes/subghz_scene_need_saving.c | 4 +- .../subghz/scenes/subghz_scene_read_raw.c | 15 +++++- .../subghz/scenes/subghz_scene_receiver.c | 18 +++++-- .../scenes/subghz_scene_receiver_config.c | 49 +++++++++---------- applications/main/subghz/subghz.c | 21 +++++++- applications/main/subghz/subghz_i.h | 4 +- .../main/subghz/subghz_last_settings.c | 19 +++++++ .../main/subghz/subghz_last_settings.h | 36 ++++++++++++++ .../subghz/subghz_last_settings_filename.h | 3 ++ applications/main/subghz/subghz_setting.c | 21 +++++--- applications/main/subghz/subghz_setting.h | 2 + 11 files changed, 150 insertions(+), 42 deletions(-) create mode 100644 applications/main/subghz/subghz_last_settings.c create mode 100644 applications/main/subghz/subghz_last_settings.h create mode 100644 applications/main/subghz/subghz_last_settings_filename.h diff --git a/applications/main/subghz/scenes/subghz_scene_need_saving.c b/applications/main/subghz/scenes/subghz_scene_need_saving.c index 53bffedc84..6f04be6690 100644 --- a/applications/main/subghz/scenes/subghz_scene_need_saving.c +++ b/applications/main/subghz/scenes/subghz_scene_need_saving.c @@ -50,8 +50,8 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) { subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_preset_init( subghz, - "AM650", - subghz_setting_get_default_frequency(subghz->setting), + subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, NULL, 0); scene_manager_search_and_switch_to_previous_scene( diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 60783b060a..8a087e1346 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -131,13 +131,14 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) || (subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) { subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; + subghz->current_scene = SubGhzSceneNeedSaving; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //Restore default setting subghz_preset_init( subghz, - "AM650", - subghz_setting_get_default_frequency(subghz->setting), + 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( @@ -146,7 +147,11 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->scene_manager, SubGhzSceneStart)) { scene_manager_stop(subghz->scene_manager); view_dispatcher_stop(subghz->view_dispatcher); + } else { + subghz->current_scene = SubGhzSceneStart; } + } else { + subghz->current_scene = SubGhzSceneSaved; } } consumed = true; @@ -170,6 +175,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWConfig: scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet); + subghz->current_scene = SubGhzSceneReceiverConfig; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); consumed = true; break; @@ -191,6 +197,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet); subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; + subghz->current_scene = SubGhzSceneMoreRAW; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW); consumed = true; } else { @@ -210,6 +217,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz->current_scene = SubGhzSceneShowOnlyRx; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); } else { DOLPHIN_DEED(DolphinDeedSubGhzSend); @@ -269,6 +277,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWREC: if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) { + subghz->current_scene = SubGhzSceneNeedSaving; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //subghz_get_preset_name(subghz, subghz->error_str); @@ -289,6 +298,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; } else { string_set_str(subghz->error_str, "Function requires\nan SD card."); + subghz->current_scene = SubGhzSceneShowError; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } } @@ -300,6 +310,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW); subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; + subghz->current_scene = SubGhzSceneSaveName; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); } consumed = true; diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index a58777d15c..1e2bbbbcdd 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -1,6 +1,8 @@ #include "../subghz_i.h" #include "../views/receiver.h" +#define TAG "SubGhzSceneReceiver" + const NotificationSequence subghz_sequence_rx = { &message_green_255, @@ -103,7 +105,11 @@ void subghz_scene_receiver_on_enter(void* context) { if(subghz->txrx->rx_key_state == SubGhzRxKeyStateIDLE) { subghz_preset_init( - subghz, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0); + subghz, + subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, + NULL, + 0); subghz_history_reset(subghz->txrx->history); subghz->txrx->rx_key_state = SubGhzRxKeyStateStart; } @@ -164,15 +170,17 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; + subghz->current_scene = SubGhzSceneNeedSaving; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; subghz_preset_init( subghz, - "AM650", - subghz_setting_get_default_frequency(subghz->setting), + subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, NULL, 0); + subghz->current_scene = SubGhzSceneStart; scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } @@ -181,6 +189,7 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReceiverOK: subghz->txrx->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + subghz->current_scene = SubGhzSceneReceiverInfo; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo); consumed = true; break; @@ -188,6 +197,9 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz->state_notifications = SubGhzNotificationStateIDLE; subghz->txrx->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + scene_manager_set_scene_state( + subghz->scene_manager, SubGhzViewIdReceiver, SubGhzCustomEventManagerSet); + subghz->current_scene = SubGhzSceneReceiverConfig; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); consumed = true; break; diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index d565666a1e..55c177f6d3 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -145,6 +145,8 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { (subghz_setting_get_frequency(subghz->setting, index) % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); subghz->txrx->preset->frequency = subghz_setting_get_frequency(subghz->setting, index); + subghz->last_settings->frequency = subghz->txrx->preset->frequency; + subghz_setting_set_default_frequency(subghz->setting, subghz->txrx->preset->frequency); } else { variable_item_set_current_value_index( item, subghz_setting_get_frequency_default_index(subghz->setting)); @@ -154,11 +156,13 @@ static void subghz_scene_receiver_config_set_frequency(VariableItem* item) { static void subghz_scene_receiver_config_set_preset(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, subghz_setting_get_preset_name(subghz->setting, index)); + const char* preset_name = subghz_setting_get_preset_name(subghz->setting, index); + variable_item_set_current_value_text(item, preset_name); + subghz->last_settings->preset = index; + subghz_preset_init( subghz, - subghz_setting_get_preset_name(subghz->setting, index), + preset_name, subghz->txrx->preset->frequency, subghz_setting_get_preset_data(subghz->setting, index), subghz_setting_get_preset_data_size(subghz->setting, index)); @@ -246,8 +250,6 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz); value_index = subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz); - scene_manager_set_scene_state( - subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item); variable_item_set_current_value_index(item, value_index); char text_buf[10] = {0}; snprintf( @@ -258,20 +260,6 @@ void subghz_scene_receiver_config_on_enter(void* context) { (subghz_setting_get_frequency(subghz->setting, value_index) % 1000000) / 10000); variable_item_set_current_value_text(item, text_buf); - if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != - SubGhzCustomEventManagerSet) { - item = variable_item_list_add( - subghz->variable_item_list, - "Hopping:", - HOPPING_COUNT, - subghz_scene_receiver_config_set_hopping_running, - subghz); - value_index = subghz_scene_receiver_config_hopper_value_index( - subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, hopping_text[value_index]); - } - item = variable_item_list_add( subghz->variable_item_list, "Modulation:", @@ -286,6 +274,19 @@ void subghz_scene_receiver_config_on_enter(void* context) { if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != SubGhzCustomEventManagerSet) { + // Hopping + item = variable_item_list_add( + subghz->variable_item_list, + "Hopping:", + HOPPING_COUNT, + subghz_scene_receiver_config_set_hopping_running, + subghz); + value_index = subghz_scene_receiver_config_hopper_value_index( + subghz->txrx->hopper_state, hopping_value, HOPPING_COUNT, subghz); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, hopping_text[value_index]); + + // Detect Raw item = variable_item_list_add( subghz->variable_item_list, "Detect Raw:", @@ -298,10 +299,8 @@ void subghz_scene_receiver_config_on_enter(void* context) { DETECT_RAW_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, detect_raw_text[value_index]); - } - if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != - SubGhzCustomEventManagerSet) { + // RSSI item = variable_item_list_add( subghz->variable_item_list, "RSSI for Raw:", @@ -315,10 +314,8 @@ void subghz_scene_receiver_config_on_enter(void* context) { RSSI_THRESHOLD_COUNT); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, rssi_threshold_text[value_index]); - } - if(scene_manager_get_scene_state(subghz->scene_manager, SubGhzSceneReadRAW) != - SubGhzCustomEventManagerSet) { + // Lock keyboard variable_item_list_add(subghz->variable_item_list, "Lock Keyboard", 1, NULL, NULL); variable_item_list_set_enter_callback( subghz->variable_item_list, @@ -345,8 +342,8 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even void subghz_scene_receiver_config_on_exit(void* context) { SubGhz* subghz = context; - variable_item_list_set_selected_item(subghz->variable_item_list, 0); variable_item_list_reset(subghz->variable_item_list); + SAVE_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 08de91f919..666246af62 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -5,6 +5,8 @@ #include #include "subghz_i.h" +#define TAG "SubGhzApp" + bool subghz_custom_event_callback(void* context, uint32_t event) { furi_assert(context); SubGhz* subghz = context; @@ -174,13 +176,30 @@ SubGhz* subghz_alloc() { subghz->setting = subghz_setting_alloc(); subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user")); + // Load last used values for Read, Read RAW, etc. or default + subghz_last_settings_check_struct(); + LOAD_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); +#if DEBUG + FURI_LOG_I( + 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); + SAVE_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); + //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, "AM650", subghz_setting_get_default_frequency(subghz->setting), NULL, 0); + subghz, + subghz_setting_get_preset_name(subghz->setting, subghz->last_settings->preset), + subghz->last_settings->frequency, + NULL, + 0); subghz->txrx->txrx_state = SubGhzTxRxStateSleep; subghz->txrx->hopper_state = SubGhzHopperStateOFF; diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index 945228a450..f141b5399a 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -33,6 +33,7 @@ #include "subghz_history.h" #include "subghz_setting.h" +#include "subghz_last_settings.h" #include #include @@ -100,10 +101,11 @@ struct SubGhz { SubGhzTestPacket* subghz_test_packet; string_t error_str; SubGhzSetting* setting; + SubGhzLastSettings* last_settings; SubGhzLock lock; bool in_decoder_scene; - + SubGhzScene current_scene; void* rpc_ctx; }; diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c new file mode 100644 index 0000000000..cfc7b4e2e7 --- /dev/null +++ b/applications/main/subghz/subghz_last_settings.c @@ -0,0 +1,19 @@ +#include "subghz_last_settings.h" + +#define TAG "SubGhzLastSettings" + +// 1 = "AM650" +// "AM270", "AM650", "FM238", "FM476", +#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 +#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 + +void subghz_last_settings_check_struct(void) { + Storage* storage = furi_record_open(RECORD_STORAGE); + if(!storage_file_exists(storage, SUBGHZ_LAST_SETTINGS_PATH)) { + SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); + instance->frequency = SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY; + instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; + SAVE_SUBGHZ_LAST_SETTINGS(&instance); + } + furi_record_close(RECORD_STORAGE); +} \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h new file mode 100644 index 0000000000..27e67e2520 --- /dev/null +++ b/applications/main/subghz/subghz_last_settings.h @@ -0,0 +1,36 @@ +#pragma once + +#include "subghz_last_settings_filename.h" + +#include +#include +#include +#include +#include + +#define SUBGHZ_LAST_SETTINGS_VER (1) +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH(SUBGHZ_LAST_SETTINGS_FILE_NAME) +#define SUBGHZ_LAST_SETTINGS_MAGIC (0xCC) + +#define SAVE_SUBGHZ_LAST_SETTINGS(x) \ + saved_struct_save( \ + SUBGHZ_LAST_SETTINGS_PATH, \ + (x), \ + sizeof(SubGhzLastSettings), \ + SUBGHZ_LAST_SETTINGS_MAGIC, \ + SUBGHZ_LAST_SETTINGS_VER) + +#define LOAD_SUBGHZ_LAST_SETTINGS(x) \ + saved_struct_load( \ + SUBGHZ_LAST_SETTINGS_PATH, \ + (x), \ + sizeof(SubGhzLastSettings), \ + SUBGHZ_LAST_SETTINGS_MAGIC, \ + SUBGHZ_LAST_SETTINGS_VER) + +typedef struct { + uint32_t frequency; + uint8_t preset; +} SubGhzLastSettings; + +void subghz_last_settings_check_struct(void); \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings_filename.h b/applications/main/subghz/subghz_last_settings_filename.h new file mode 100644 index 0000000000..3f34262c35 --- /dev/null +++ b/applications/main/subghz/subghz_last_settings_filename.h @@ -0,0 +1,3 @@ +#pragma once + +#define SUBGHZ_LAST_SETTINGS_FILE_NAME ".subghz.settings" \ No newline at end of file diff --git a/applications/main/subghz/subghz_setting.c b/applications/main/subghz/subghz_setting.c index b8f3794eb7..2e94011cfd 100644 --- a/applications/main/subghz/subghz_setting.c +++ b/applications/main/subghz/subghz_setting.c @@ -260,13 +260,7 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { break; } if(flipper_format_read_uint32(fff_data_file, "Default_frequency", &temp_data32, 1)) { - for - M_EACH(frequency, instance->frequencies, FrequencyList_t) { - *frequency &= FREQUENCY_MASK; - if(*frequency == temp_data32) { - *frequency |= FREQUENCY_FLAG_DEFAULT; - } - } + subghz_setting_set_default_frequency(instance, temp_data32); } // custom preset (optional) @@ -294,6 +288,16 @@ void subghz_setting_load(SubGhzSetting* instance, const char* file_path) { } } +void subghz_setting_set_default_frequency(SubGhzSetting* instance, uint32_t frequency_to_setup) { + for + M_EACH(frequency, instance->frequencies, FrequencyList_t) { + *frequency &= FREQUENCY_MASK; + if(*frequency == frequency_to_setup) { + *frequency |= FREQUENCY_FLAG_DEFAULT; + } + } +} + size_t subghz_setting_get_frequency_count(SubGhzSetting* instance) { furi_assert(instance); return FrequencyList_size(instance->frequencies); @@ -311,6 +315,9 @@ size_t subghz_setting_get_preset_count(SubGhzSetting* instance) { const char* subghz_setting_get_preset_name(SubGhzSetting* instance, size_t idx) { furi_assert(instance); + if(idx >= SubGhzSettingCustomPresetItemArray_size(instance->preset->data)) { + idx = 0; + } SubGhzSettingCustomPresetItem* item = SubGhzSettingCustomPresetItemArray_get(instance->preset->data, idx); return string_get_cstr(item->custom_preset_name); diff --git a/applications/main/subghz/subghz_setting.h b/applications/main/subghz/subghz_setting.h index 0590cf499f..d6fde1bd6f 100644 --- a/applications/main/subghz/subghz_setting.h +++ b/applications/main/subghz/subghz_setting.h @@ -46,3 +46,5 @@ uint32_t subghz_setting_get_hopper_frequency(SubGhzSetting* instance, size_t idx uint32_t subghz_setting_get_frequency_default_index(SubGhzSetting* instance); uint32_t subghz_setting_get_default_frequency(SubGhzSetting* instance); + +void subghz_setting_set_default_frequency(SubGhzSetting* instance, uint32_t frequency_to_setup); From 0f0473bee6ba87d239682a7f7cafa54d4dee8770 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 03:27:47 +0400 Subject: [PATCH 02/12] fix bug with invalid settings values in config --- applications/main/subghz/subghz.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 666246af62..39196fbfcf 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -179,8 +179,8 @@ SubGhz* subghz_alloc() { // Load last used values for Read, Read RAW, etc. or default subghz_last_settings_check_struct(); LOAD_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); -#if DEBUG - FURI_LOG_I( +#if FURI_DEBUG + FURI_LOG_D( TAG, "last frequency: %d, preset: %d", subghz->last_settings->frequency, From a3db6718c2d10d32f4c1e04c5a7007747e5f9397 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 04:31:29 +0400 Subject: [PATCH 03/12] fix bug with invalid settings values in config --- .../main/subghz/scenes/subghz_scene_receiver_config.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 55c177f6d3..5fc019f711 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -2,6 +2,8 @@ #include +#define TAG "SubGhzSceneReceiverConfig" + enum SubGhzSettingIndex { SubGhzSettingIndexFrequency, SubGhzSettingIndexHopping, @@ -242,6 +244,13 @@ void subghz_scene_receiver_config_on_enter(void* context) { VariableItem* item; uint8_t value_index; +#if FURI_DEBUG + FURI_LOG_D( + TAG, + "last frequency: %d, preset: %d", + subghz->last_settings->frequency, + subghz->last_settings->preset); +#endif item = variable_item_list_add( subghz->variable_item_list, "Frequency:", From 22a87d570707309adc738b1595af7cf2f54d4904 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 05:49:06 +0400 Subject: [PATCH 04/12] struct doesn't correct written --- .../scenes/subghz_scene_receiver_config.c | 2 +- applications/main/subghz/subghz.c | 7 +- .../main/subghz/subghz_last_settings.c | 94 ++++++++++++++++++- .../main/subghz/subghz_last_settings.h | 33 ++----- .../subghz/subghz_last_settings_filename.h | 3 - 5 files changed, 103 insertions(+), 36 deletions(-) delete mode 100644 applications/main/subghz/subghz_last_settings_filename.h diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 5fc019f711..affb01a0b9 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -352,7 +352,7 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even void subghz_scene_receiver_config_on_exit(void* context) { SubGhz* subghz = context; variable_item_list_reset(subghz->variable_item_list); - SAVE_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); + subghz_last_settings_save(subghz->last_settings); scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 39196fbfcf..8b9dd399f3 100644 --- a/applications/main/subghz/subghz.c +++ b/applications/main/subghz/subghz.c @@ -177,8 +177,9 @@ SubGhz* subghz_alloc() { subghz_setting_load(subghz->setting, EXT_PATH("subghz/assets/setting_user")); // Load last used values for Read, Read RAW, etc. or default - subghz_last_settings_check_struct(); - LOAD_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); + 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, @@ -187,7 +188,6 @@ SubGhz* subghz_alloc() { subghz->last_settings->preset); #endif subghz_setting_set_default_frequency(subghz->setting, subghz->last_settings->frequency); - SAVE_SUBGHZ_LAST_SETTINGS(&subghz->last_settings); //init Worker & Protocol & History & KeyBoard subghz->lock = SubGhzLockOff; @@ -306,6 +306,7 @@ void subghz_free(SubGhz* subghz) { //setting subghz_setting_free(subghz->setting); + subghz_last_settings_free(subghz->last_settings); //Worker & Protocol & History subghz_receiver_free(subghz->txrx->receiver); diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index cfc7b4e2e7..764c78fea9 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,19 +1,105 @@ #include "subghz_last_settings.h" +#include +#include +#include #define TAG "SubGhzLastSettings" +#define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" +#define SUBGHZ_LAST_SETTING_FILE_VERSION 1 +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH(".subghz.settings") // 1 = "AM650" // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 #define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 -void subghz_last_settings_check_struct(void) { +SubGhzLastSettings* subghz_last_settings_alloc(void) { + SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); + return instance; +} + +void subghz_last_settings_free(SubGhzLastSettings* instance) { + furi_assert(instance); + free(instance); +} + +void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count) { + furi_assert(instance); +#if FURI_DEBUG + FURI_LOG_I(TAG, "subghz_last_settings_load"); +#endif + Storage* storage = furi_record_open(RECORD_STORAGE); - if(!storage_file_exists(storage, SUBGHZ_LAST_SETTINGS_PATH)) { - SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); + FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); + + uint32_t temp_frequency = 0; + int32_t temp_preset = 0; + + if(FSE_OK == storage_sd_status(storage) && SUBGHZ_LAST_SETTINGS_PATH && + flipper_format_file_open_existing(fff_data_file, SUBGHZ_LAST_SETTINGS_PATH)) { + flipper_format_read_int32(fff_data_file, "Preset", (int32_t*)&temp_preset, 1); + flipper_format_read_uint32(fff_data_file, "Frequency", (uint32_t*)&temp_frequency, 1); + } else { + FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); + } + + if(temp_frequency == 0 || !furi_hal_subghz_is_tx_allowed(temp_frequency)) { + 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; - SAVE_SUBGHZ_LAST_SETTINGS(&instance); + } else { + instance->frequency = temp_frequency; + + if(temp_preset > (int32_t)preset_count - 1 || temp_preset < 0) { + FURI_LOG_W(TAG, "Last used preset no found"); + instance->preset = SUBGHZ_LAST_SETTING_DEFAULT_PRESET; + } else { + instance->preset = temp_preset; + } } + + flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); +} + +bool subghz_last_settings_save(SubGhzLastSettings* instance) { + furi_assert(instance); +#if FURI_DEBUG + FURI_LOG_I(TAG, "subghz_last_settings_save"); +#endif + + bool saved = false; + Storage* storage = furi_record_open(RECORD_STORAGE); + FlipperFormat* file = flipper_format_file_alloc(storage); + + do { + if(FSE_OK != storage_sd_status(storage)) { + break; + } + + // Open file + if(!flipper_format_file_open_always(file, SUBGHZ_LAST_SETTINGS_PATH)) break; + + // Write header + if(!flipper_format_write_header_cstr( + file, SUBGHZ_LAST_SETTING_FILE_TYPE, SUBGHZ_LAST_SETTING_FILE_VERSION)) + break; + + if(!flipper_format_insert_or_update_int32(file, "Preset", &instance->preset, 1)) { + break; + } + if(!flipper_format_insert_or_update_uint32(file, "Frequency", &instance->frequency, 1)) { + break; + } + saved = true; + } while(0); + + if(!saved) { + FURI_LOG_E(TAG, "Error save file %s", SUBGHZ_LAST_SETTINGS_PATH); + } + + flipper_format_free(file); + furi_record_close(RECORD_STORAGE); + + return saved; } \ 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 27e67e2520..8067bb66a4 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -1,36 +1,19 @@ #pragma once -#include "subghz_last_settings_filename.h" - #include #include #include -#include #include -#define SUBGHZ_LAST_SETTINGS_VER (1) -#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH(SUBGHZ_LAST_SETTINGS_FILE_NAME) -#define SUBGHZ_LAST_SETTINGS_MAGIC (0xCC) - -#define SAVE_SUBGHZ_LAST_SETTINGS(x) \ - saved_struct_save( \ - SUBGHZ_LAST_SETTINGS_PATH, \ - (x), \ - sizeof(SubGhzLastSettings), \ - SUBGHZ_LAST_SETTINGS_MAGIC, \ - SUBGHZ_LAST_SETTINGS_VER) - -#define LOAD_SUBGHZ_LAST_SETTINGS(x) \ - saved_struct_load( \ - SUBGHZ_LAST_SETTINGS_PATH, \ - (x), \ - sizeof(SubGhzLastSettings), \ - SUBGHZ_LAST_SETTINGS_MAGIC, \ - SUBGHZ_LAST_SETTINGS_VER) - typedef struct { uint32_t frequency; - uint8_t preset; + int32_t preset; } SubGhzLastSettings; -void subghz_last_settings_check_struct(void); \ No newline at end of file +SubGhzLastSettings* subghz_last_settings_alloc(void); + +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); \ No newline at end of file diff --git a/applications/main/subghz/subghz_last_settings_filename.h b/applications/main/subghz/subghz_last_settings_filename.h deleted file mode 100644 index 3f34262c35..0000000000 --- a/applications/main/subghz/subghz_last_settings_filename.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -#define SUBGHZ_LAST_SETTINGS_FILE_NAME ".subghz.settings" \ No newline at end of file From 406247c5d875db68f3144e464fa70645bc3d8ccf Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 06:22:02 +0400 Subject: [PATCH 05/12] Ok button in frequency analyzer will set this frequency to receiver --- .../scenes/subghz_scene_frequency_analyzer.c | 15 ++- .../subghz/views/subghz_frequency_analyzer.c | 114 ++++++++++++++++++ .../subghz/views/subghz_frequency_analyzer.h | 2 + 3 files changed, 128 insertions(+), 3 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c index f067f98599..a78fccd3f7 100644 --- a/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c +++ b/applications/main/subghz/scenes/subghz_scene_frequency_analyzer.c @@ -1,5 +1,4 @@ #include "../subghz_i.h" -#include "../views/subghz_frequency_analyzer.h" #include void subghz_scene_frequency_analyzer_callback(SubGhzCustomEvent event, void* context) { @@ -17,8 +16,18 @@ void subghz_scene_frequency_analyzer_on_enter(void* context) { } bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent event) { - UNUSED(context); - UNUSED(event); + SubGhz* subghz = context; + if(event.type == SceneManagerEventTypeCustom && + event.event == SubGhzCustomEventViewReceiverOK) { + uint32_t frequency = + subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer); + if(frequency > 0) { + subghz->last_settings->frequency = frequency; + subghz_last_settings_save(subghz->last_settings); + } + + return true; + } return false; } diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 5be00888fe..7d1239cd8e 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -30,6 +30,43 @@ static const NotificationSequence sequence_hw_blink_stop = { NULL, }; +static const NotificationSequence sequence_saved = { + &message_blink_stop, + &message_blue_0, + &message_green_0, + &message_red_255, + &message_vibro_on, + &message_delay_100, + &message_vibro_off, + NULL, +}; +static const NotificationSequence sequence_not_saved = { + &message_blink_stop, + &message_green_255, + &message_blue_255, + &message_red_255, + NULL, +}; + +static const uint32_t subghz_frequency_list[17] = { + 300000000, + 303875000, + 304250000, + 310000000, + 315000000, + 318000000, + 390000000, + 418000000, + 433075000, + 433420000, + 433920000, + 434420000, + 434775000, + 438900000, + 868350000, + 915000000, + 925000000}; + typedef enum { SubGhzFrequencyAnalyzerStatusIDLE, } SubGhzFrequencyAnalyzerStatus; @@ -50,6 +87,7 @@ struct SubGhzFrequencyAnalyzer { typedef struct { uint32_t frequency; uint32_t frequency_last; + uint32_t frequency_to_save; float rssi; float rssi_last; float trigger; @@ -163,6 +201,33 @@ void subghz_frequency_analyzer_draw(Canvas* canvas, SubGhzFrequencyAnalyzerModel elements_button_right(canvas, "T+"); } +uint32_t subghz_frequency_find_correct(uint32_t input) { + uint32_t prev_freq = 0; + uint32_t current = 0; + uint32_t result = 0; +#if FURI_DEBUG + FURI_LOG_D(TAG, "input: %d", input); +#endif + for(size_t i = 0; i < sizeof(subghz_frequency_list); i++) { + current = subghz_frequency_list[i]; + if(current == input) { + result = current; + break; + } + if(current > input && prev_freq < input) { + if(current - input < input - prev_freq) { + result = current; + } else { + result = prev_freq; + } + break; + } + prev_freq = current; + } + + return result; +} + bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { furi_assert(context); SubGhzFrequencyAnalyzer* instance = context; @@ -201,6 +266,43 @@ bool subghz_frequency_analyzer_input(InputEvent* event, void* context) { need_redraw = true; } + if(event->type == InputTypeShort && event->key == InputKeyOk) { + with_view_model( + instance->view, (SubGhzFrequencyAnalyzerModel * model) { + uint32_t prev_freq_to_save = model->frequency_to_save; + uint32_t frequency_candidate = 0; + if(model->frequency != 0) { + frequency_candidate = model->frequency; + } else if(model->frequency_last != 0) { + frequency_candidate = model->frequency_last; + } + if(frequency_candidate == 0 || + !furi_hal_subghz_is_frequency_valid(frequency_candidate) || + prev_freq_to_save == frequency_candidate) { + frequency_candidate = 0; + } else { + frequency_candidate = subghz_frequency_find_correct(frequency_candidate); + } + if(frequency_candidate > 0 && frequency_candidate != model->frequency_to_save) { +#if FURI_DEBUG + FURI_LOG_D( + TAG, + "frequency_to_save: %d, candidate: %d", + model->frequency_to_save, + frequency_candidate); +#endif + model->frequency_to_save = frequency_candidate; + notification_message(instance->notifications, &sequence_saved); + instance->callback(SubGhzCustomEventViewReceiverOK, instance->context); + notification_message(instance->notifications, &sequence_hw_blink); + } else { + notification_message(instance->notifications, &sequence_not_saved); + notification_message(instance->notifications, &sequence_hw_blink); + } + return true; + }); + } + if(need_redraw) { SubGhzFrequencyAnalyzer* instance = context; with_view_model( @@ -309,6 +411,7 @@ void subghz_frequency_analyzer_enter(void* context) { model->rssi_last = 0; model->frequency = 0; model->frequency_last = 0; + model->frequency_to_save = 0; model->trigger = RSSI_MIN; return true; }); @@ -359,4 +462,15 @@ void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* instance) { View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) { furi_assert(instance); return instance->view; +} + +uint32_t subghz_frequency_analyzer_get_frequency_to_save(SubGhzFrequencyAnalyzer* instance) { + uint32_t frequency; + with_view_model( + instance->view, (SubGhzFrequencyAnalyzerModel * model) { + frequency = model->frequency_to_save; + return false; + }); + + return frequency; } \ No newline at end of file diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.h b/applications/main/subghz/views/subghz_frequency_analyzer.h index 3de003bf83..5e00c64448 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.h +++ b/applications/main/subghz/views/subghz_frequency_analyzer.h @@ -17,3 +17,5 @@ SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc(); void subghz_frequency_analyzer_free(SubGhzFrequencyAnalyzer* subghz_static); View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* subghz_static); + +uint32_t subghz_frequency_analyzer_get_frequency_to_save(SubGhzFrequencyAnalyzer* instance); From 8be08093e2825ad874a13f6268eaa1a90ca76a72 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 06:28:23 +0400 Subject: [PATCH 06/12] Change name of file to not able to "Run in App" in Browser --- applications/main/subghz/subghz_last_settings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 764c78fea9..a4e89c0eef 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -7,7 +7,7 @@ #define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" #define SUBGHZ_LAST_SETTING_FILE_VERSION 1 -#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH(".subghz.settings") +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz.settings") // 1 = "AM650" // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 From 746b732034ae833c65aed1dfde9f9aadbb99ce2e Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 28 Sep 2022 05:49:21 +0300 Subject: [PATCH 07/12] remove unused code --- .../main/subghz/scenes/subghz_scene_read_raw.c | 11 ----------- .../main/subghz/scenes/subghz_scene_receiver.c | 4 ---- applications/main/subghz/subghz_i.h | 1 - 3 files changed, 16 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_read_raw.c b/applications/main/subghz/scenes/subghz_scene_read_raw.c index 8a087e1346..7392221dc6 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -131,7 +131,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { if((subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) || (subghz->txrx->rx_key_state == SubGhzRxKeyStateBack)) { subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; - subghz->current_scene = SubGhzSceneNeedSaving; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //Restore default setting @@ -147,11 +146,7 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->scene_manager, SubGhzSceneStart)) { scene_manager_stop(subghz->scene_manager); view_dispatcher_stop(subghz->view_dispatcher); - } else { - subghz->current_scene = SubGhzSceneStart; } - } else { - subghz->current_scene = SubGhzSceneSaved; } } consumed = true; @@ -175,7 +170,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWConfig: scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet); - subghz->current_scene = SubGhzSceneReceiverConfig; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); consumed = true; break; @@ -197,7 +191,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSet); subghz->txrx->rx_key_state = SubGhzRxKeyStateRAWLoad; - subghz->current_scene = SubGhzSceneMoreRAW; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneMoreRAW); consumed = true; } else { @@ -217,7 +210,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { (subghz->txrx->txrx_state == SubGhzTxRxStateSleep)) { if(!subghz_tx_start(subghz, subghz->txrx->fff_data)) { subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; - subghz->current_scene = SubGhzSceneShowOnlyRx; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowOnlyRx); } else { DOLPHIN_DEED(DolphinDeedSubGhzSend); @@ -277,7 +269,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReadRAWREC: if(subghz->txrx->rx_key_state != SubGhzRxKeyStateIDLE) { - subghz->current_scene = SubGhzSceneNeedSaving; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { //subghz_get_preset_name(subghz, subghz->error_str); @@ -298,7 +289,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { subghz->txrx->rx_key_state = SubGhzRxKeyStateAddKey; } else { string_set_str(subghz->error_str, "Function requires\nan SD card."); - subghz->current_scene = SubGhzSceneShowError; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneShowError); } } @@ -310,7 +300,6 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { scene_manager_set_scene_state( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerSetRAW); subghz->txrx->rx_key_state = SubGhzRxKeyStateBack; - subghz->current_scene = SubGhzSceneSaveName; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneSaveName); } consumed = true; diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 1e2bbbbcdd..4a35c5f2c5 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -170,7 +170,6 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { if(subghz->txrx->rx_key_state == SubGhzRxKeyStateAddKey) { subghz->txrx->rx_key_state = SubGhzRxKeyStateExit; - subghz->current_scene = SubGhzSceneNeedSaving; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneNeedSaving); } else { subghz->txrx->rx_key_state = SubGhzRxKeyStateIDLE; @@ -180,7 +179,6 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz->last_settings->frequency, NULL, 0); - subghz->current_scene = SubGhzSceneStart; scene_manager_search_and_switch_to_previous_scene( subghz->scene_manager, SubGhzSceneStart); } @@ -189,7 +187,6 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { case SubGhzCustomEventViewReceiverOK: subghz->txrx->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); - subghz->current_scene = SubGhzSceneReceiverInfo; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverInfo); consumed = true; break; @@ -199,7 +196,6 @@ bool subghz_scene_receiver_on_event(void* context, SceneManagerEvent event) { subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); scene_manager_set_scene_state( subghz->scene_manager, SubGhzViewIdReceiver, SubGhzCustomEventManagerSet); - subghz->current_scene = SubGhzSceneReceiverConfig; scene_manager_next_scene(subghz->scene_manager, SubGhzSceneReceiverConfig); consumed = true; break; diff --git a/applications/main/subghz/subghz_i.h b/applications/main/subghz/subghz_i.h index f141b5399a..8872d31f6c 100644 --- a/applications/main/subghz/subghz_i.h +++ b/applications/main/subghz/subghz_i.h @@ -105,7 +105,6 @@ struct SubGhz { SubGhzLock lock; bool in_decoder_scene; - SubGhzScene current_scene; void* rpc_ctx; }; From 006d27ed935d58dac6676984679de30e762ba477 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 06:53:52 +0400 Subject: [PATCH 08/12] Add removed fixed --- applications/main/subghz/scenes/subghz_scene_receiver_config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index affb01a0b9..3469de5737 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -351,6 +351,7 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even void subghz_scene_receiver_config_on_exit(void* context) { SubGhz* subghz = context; + variable_item_list_set_selected_item(subghz->variable_item_list, 0); variable_item_list_reset(subghz->variable_item_list); subghz_last_settings_save(subghz->last_settings); scene_manager_set_scene_state( From 0c5f11f713974322d29f7b8af6f238377c825960 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 28 Sep 2022 06:02:23 +0300 Subject: [PATCH 09/12] return fix --- applications/main/subghz/scenes/subghz_scene_receiver_config.c | 3 +++ applications/main/subghz/subghz_last_settings.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index affb01a0b9..0175cd0fd0 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -259,6 +259,8 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz); value_index = subghz_scene_receiver_config_next_frequency(subghz->txrx->preset->frequency, subghz); + scene_manager_set_scene_state( + subghz->scene_manager, SubGhzSceneReceiverConfig, (uint32_t)item); variable_item_set_current_value_index(item, value_index); char text_buf[10] = {0}; snprintf( @@ -351,6 +353,7 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even void subghz_scene_receiver_config_on_exit(void* context) { SubGhz* subghz = context; + variable_item_list_set_selected_item(subghz->variable_item_list, 0); variable_item_list_reset(subghz->variable_item_list); subghz_last_settings_save(subghz->last_settings); scene_manager_set_scene_state( diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 764c78fea9..241d8e950e 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -7,7 +7,7 @@ #define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" #define SUBGHZ_LAST_SETTING_FILE_VERSION 1 -#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH(".subghz.settings") +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/.subghz.settings") // 1 = "AM650" // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 From 8f2bd3be571a3f949d0817dda8474d7624594751 Mon Sep 17 00:00:00 2001 From: derskythe Date: Wed, 28 Sep 2022 07:14:38 +0400 Subject: [PATCH 10/12] Update list of frequencies and change name of file of settings to not able to run in browser --- .../main/subghz/subghz_last_settings.c | 4 +-- .../subghz/views/subghz_frequency_analyzer.c | 25 ++++++------------- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 241d8e950e..0a45e36ba0 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -1,13 +1,11 @@ #include "subghz_last_settings.h" -#include -#include #include #define TAG "SubGhzLastSettings" #define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" #define SUBGHZ_LAST_SETTING_FILE_VERSION 1 -#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/.subghz.settings") +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/subghz.settings") // 1 = "AM650" // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 7d1239cd8e..f7c41f627c 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -48,24 +48,13 @@ static const NotificationSequence sequence_not_saved = { NULL, }; -static const uint32_t subghz_frequency_list[17] = { - 300000000, - 303875000, - 304250000, - 310000000, - 315000000, - 318000000, - 390000000, - 418000000, - 433075000, - 433420000, - 433920000, - 434420000, - 434775000, - 438900000, - 868350000, - 915000000, - 925000000}; +static const uint32_t subghz_frequency_list[] = { + 300000000, 302757000, 303875000, 304250000, 307000000, 307500000, 307800000, + 309000000, 310000000, 312000000, 312100000, 313000000, 313850000, 314000000, + 314350000, 315000000, 318000000, 345000000, 348000000, 387000000, 390000000, + 418000000, 433075000, 433220000, 433420000, 433657070, 433889000, 433920000, + 434176948, 434420000, 434775000, 438900000, 464000000, 779000000, 868350000, + 868400000, 868950000, 906400000, 915000000, 925000000, 928000000}; typedef enum { SubGhzFrequencyAnalyzerStatusIDLE, From 0ebb3f060ebc2e2b312a39dbc2534cf5efa17565 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 28 Sep 2022 06:46:45 +0300 Subject: [PATCH 11/12] add a bit of changes --- applications/main/subghz/subghz_last_settings.c | 2 +- applications/main/subghz/views/subghz_frequency_analyzer.c | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 0a45e36ba0..aa234c6023 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -5,7 +5,7 @@ #define SUBGHZ_LAST_SETTING_FILE_TYPE "Flipper SubGhz Last Setting File" #define SUBGHZ_LAST_SETTING_FILE_VERSION 1 -#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/subghz.settings") +#define SUBGHZ_LAST_SETTINGS_PATH EXT_PATH("subghz/assets/last_subghz.settings") // 1 = "AM650" // "AM270", "AM650", "FM238", "FM476", #define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index f7c41f627c..9900c32c97 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -33,8 +33,8 @@ static const NotificationSequence sequence_hw_blink_stop = { static const NotificationSequence sequence_saved = { &message_blink_stop, &message_blue_0, - &message_green_0, - &message_red_255, + &message_green_255, + &message_red_0, &message_vibro_on, &message_delay_100, &message_vibro_off, @@ -454,6 +454,7 @@ View* subghz_frequency_analyzer_get_view(SubGhzFrequencyAnalyzer* instance) { } uint32_t subghz_frequency_analyzer_get_frequency_to_save(SubGhzFrequencyAnalyzer* instance) { + furi_assert(instance); uint32_t frequency; with_view_model( instance->view, (SubGhzFrequencyAnalyzerModel * model) { From b934c41ed04a305b6895709d8a1f8a278ab1f03a Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Wed, 28 Sep 2022 06:51:13 +0300 Subject: [PATCH 12/12] close file --- applications/main/subghz/subghz_last_settings.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index aa234c6023..b24273cf32 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -56,6 +56,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count } } + flipper_format_file_close(fff_data_file); flipper_format_free(fff_data_file); furi_record_close(RECORD_STORAGE); } @@ -96,6 +97,7 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { FURI_LOG_E(TAG, "Error save file %s", SUBGHZ_LAST_SETTINGS_PATH); } + flipper_format_file_close(file); flipper_format_free(file); furi_record_close(RECORD_STORAGE);