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/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..7392221dc6 100644 --- a/applications/main/subghz/scenes/subghz_scene_read_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_read_raw.c @@ -136,8 +136,8 @@ bool subghz_scene_read_raw_on_event(void* context, SceneManagerEvent event) { //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( diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index a58777d15c..4a35c5f2c5 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; } @@ -169,8 +175,8 @@ bool subghz_scene_receiver_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( @@ -188,6 +194,8 @@ 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); 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..0175cd0fd0 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, @@ -145,6 +147,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 +158,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)); @@ -238,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:", @@ -258,20 +271,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 +285,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 +310,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 +325,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, @@ -347,6 +355,7 @@ 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( subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet); } diff --git a/applications/main/subghz/subghz.c b/applications/main/subghz/subghz.c index 08de91f919..8b9dd399f3 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 = 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); +#endif + 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, "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; @@ -287,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_i.h b/applications/main/subghz/subghz_i.h index 945228a450..8872d31f6c 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,10 @@ struct SubGhz { SubGhzTestPacket* subghz_test_packet; string_t error_str; SubGhzSetting* setting; + SubGhzLastSettings* last_settings; SubGhzLock lock; bool in_decoder_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..b24273cf32 --- /dev/null +++ b/applications/main/subghz/subghz_last_settings.c @@ -0,0 +1,105 @@ +#include "subghz_last_settings.h" +#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/last_subghz.settings") +// 1 = "AM650" +// "AM270", "AM650", "FM238", "FM476", +#define SUBGHZ_LAST_SETTING_DEFAULT_PRESET 1 +#define SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY 433920000 + +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); + 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; + } 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_file_close(fff_data_file); + 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_file_close(file); + 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 new file mode 100644 index 0000000000..8067bb66a4 --- /dev/null +++ b/applications/main/subghz/subghz_last_settings.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include +#include +#include + +typedef struct { + uint32_t frequency; + int32_t preset; +} SubGhzLastSettings; + +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_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); diff --git a/applications/main/subghz/views/subghz_frequency_analyzer.c b/applications/main/subghz/views/subghz_frequency_analyzer.c index 5be00888fe..9900c32c97 100644 --- a/applications/main/subghz/views/subghz_frequency_analyzer.c +++ b/applications/main/subghz/views/subghz_frequency_analyzer.c @@ -30,6 +30,32 @@ static const NotificationSequence sequence_hw_blink_stop = { NULL, }; +static const NotificationSequence sequence_saved = { + &message_blink_stop, + &message_blue_0, + &message_green_255, + &message_red_0, + &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[] = { + 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, } SubGhzFrequencyAnalyzerStatus; @@ -50,6 +76,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 +190,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 +255,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 +400,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 +451,16 @@ 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) { + furi_assert(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);