Skip to content

Commit

Permalink
SubGHz: Refactor last settings logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Willy-JL committed Apr 5, 2024
1 parent 7413cd8 commit ff7cb37
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ bool subghz_scene_frequency_analyzer_on_event(void* context, SceneManagerEvent e
subghz_frequency_analyzer_get_frequency_to_save(subghz->subghz_frequency_analyzer);
if(frequency > 0) {
subghz->last_settings->frequency = frequency;
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings);
#endif
// Disable Hopping before opening the receiver scene!
if(subghz->last_settings->enable_hopping) {
subghz->last_settings->enable_hopping = false;
Expand Down
2 changes: 0 additions & 2 deletions applications/main/subghz/scenes/subghz_scene_read_raw.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,12 @@ void subghz_scene_read_raw_on_enter(void* context) {

if(subghz_rx_key_state_get(subghz) != SubGhzRxKeyStateBack) {
subghz_rx_key_state_set(subghz, SubGhzRxKeyStateIDLE);
#if SUBGHZ_LAST_SETTING_SAVE_PRESET
if(furi_string_empty(file_name)) {
subghz_txrx_set_preset_internal(
subghz->txrx,
subghz->last_settings->frequency,
subghz->last_settings->preset_index);
}
#endif
}
subghz_scene_read_raw_update_statusbar(subghz);

Expand Down
4 changes: 0 additions & 4 deletions applications/main/subghz/scenes/subghz_scene_receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,8 @@ void subghz_scene_receiver_on_enter(void* context) {
FuriString* item_time = furi_string_alloc();

if(subghz_rx_key_state_get(subghz) == SubGhzRxKeyStateIDLE) {
#if SUBGHZ_LAST_SETTING_SAVE_PRESET
subghz_txrx_set_preset_internal(
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
#else
subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency);
#endif

subghz->filter = subghz->last_settings->filter;
subghz_txrx_receiver_set_filter(subghz->txrx, subghz->filter);
Expand Down
10 changes: 0 additions & 10 deletions applications/main/subghz/scenes/subghz_scene_receiver_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,10 @@ static void subghz_scene_receiver_config_var_list_enter_callback(void* context,
subghz->view_dispatcher, SubGhzCustomEventSceneSettingLock);
} else if(index == SubGhzSettingIndexResetToDefault) {
// Reset all values to default state!
#if SUBGHZ_LAST_SETTING_SAVE_PRESET
subghz_txrx_set_preset_internal(
subghz->txrx,
SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY,
SUBGHZ_LAST_SETTING_DEFAULT_PRESET);
#else
subghz_txrx_set_default_preset(subghz->txrx, SUBGHZ_LAST_SETTING_DEFAULT_FREQUENCY);
#endif
SubGhzSetting* setting = subghz_txrx_get_setting(subghz->txrx);
SubGhzRadioPreset preset = subghz_txrx_get_preset(subghz->txrx);
const char* preset_name = furi_string_get_cstr(preset.name);
Expand Down Expand Up @@ -449,9 +445,6 @@ static void subghz_scene_receiver_config_var_list_enter_callback(void* context,

variable_item_list_set_selected_item(subghz->variable_item_list, default_index);
variable_item_list_reset(subghz->variable_item_list);
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings);
#endif
subghz_last_settings_save(subghz->last_settings);

view_dispatcher_send_custom_event(
Expand Down Expand Up @@ -745,9 +738,6 @@ void subghz_scene_receiver_config_on_exit(void* context) {

variable_item_list_set_selected_item(subghz->variable_item_list, 0);
variable_item_list_reset(subghz->variable_item_list);
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings);
#endif
subghz_last_settings_save(subghz->last_settings);
scene_manager_set_scene_state(
subghz->scene_manager, SubGhzSceneReadRAW, SubGhzCustomEventManagerNoSet);
Expand Down
7 changes: 0 additions & 7 deletions applications/main/subghz/subghz.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,9 @@ SubGhz* subghz_alloc(bool alloc_for_tx_only) {
subghz->last_settings = subghz_last_settings_alloc();
size_t preset_count = subghz_setting_get_preset_count(setting);
subghz_last_settings_load(subghz->last_settings, preset_count);
#ifdef FURI_DEBUG
subghz_last_settings_log(subghz->last_settings);
#endif
if(!alloc_for_tx_only) {
#if SUBGHZ_LAST_SETTING_SAVE_PRESET
subghz_txrx_set_preset_internal(
subghz->txrx, subghz->last_settings->frequency, subghz->last_settings->preset_index);
#else
subghz_txrx_set_default_preset(subghz->txrx, subghz->last_settings->frequency);
#endif
subghz->history = subghz_history_alloc();
}

Expand Down
Loading

0 comments on commit ff7cb37

Please sign in to comment.