diff --git a/applications/main/subghz/scenes/subghz_scene_decode_raw.c b/applications/main/subghz/scenes/subghz_scene_decode_raw.c index df976c0b7f..d6ada49fb6 100644 --- a/applications/main/subghz/scenes/subghz_scene_decode_raw.c +++ b/applications/main/subghz/scenes/subghz_scene_decode_raw.c @@ -7,7 +7,10 @@ static void subghz_scene_receiver_update_statusbar(void* context) { SubGhz* subghz = context; FuriString* history_stat_str = furi_string_alloc(); if(!subghz_history_get_text_space_left( - subghz->history, history_stat_str, subghz->gps->satellites)) { + subghz->history, + history_stat_str, + subghz->gps->satellites, + subghz->last_settings->delete_old_signals)) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); @@ -57,6 +60,20 @@ static void subghz_scene_add_to_history_callback( preset.latitude = subghz->gps->latitude; preset.longitude = subghz->gps->longitude; + if(subghz->last_settings->delete_old_signals && subghz_history_full(subghz->history)) { + subghz_view_receiver_disable_draw_callback(subghz->subghz_receiver); + + while(idx > 0 && subghz_history_full(subghz->history)) { + subghz_history_delete_item(subghz->history, 0); + subghz_view_receiver_delete_item(subghz->subghz_receiver, 0); + idx--; + } + + subghz_view_receiver_enable_draw_callback(subghz->subghz_receiver); + subghz_scene_receiver_update_statusbar(subghz); + subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); + } + if(subghz_history_add_to_history(subghz->history, decoder_base, &preset)) { furi_string_reset(item_name); furi_string_reset(item_time); @@ -80,9 +97,6 @@ static void subghz_scene_add_to_history_callback( // Restore ui state subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); subghz_view_receiver_enable_draw_callback(subghz->subghz_receiver); - if(subghz_history_get_last_index(subghz->history) == 0) { - subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); - } } subghz_history_get_text_item_menu(subghz->history, item_name, idx); diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index 15ad94bdb7..9197171db2 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -50,7 +50,10 @@ static void subghz_scene_receiver_update_statusbar(void* context) { SubGhz* subghz = context; FuriString* history_stat_str = furi_string_alloc(); if(!subghz_history_get_text_space_left( - subghz->history, history_stat_str, subghz->gps->satellites)) { + subghz->history, + history_stat_str, + subghz->gps->satellites, + subghz->last_settings->delete_old_signals)) { FuriString* frequency_str = furi_string_alloc(); FuriString* modulation_str = furi_string_alloc(); @@ -96,7 +99,6 @@ static void subghz_scene_receiver_update_statusbar(void* context) { subghz_txrx_hopper_get_state(subghz->txrx) != SubGhzHopperStateOFF, READ_BIT(subghz->filter, SubGhzProtocolFlag_BinRAW) > 0, subghz->repeater); - subghz->state_notifications = SubGhzNotificationStateIDLE; } furi_string_free(history_stat_str); @@ -134,24 +136,28 @@ static void subghz_scene_add_to_history_callback( preset.longitude = subghz->gps->longitude; if(subghz->last_settings->delete_old_signals && subghz_history_full(subghz->history)) { - subghz->state_notifications = SubGhzNotificationStateRx; subghz_view_receiver_disable_draw_callback(subghz->subghz_receiver); - subghz_history_delete_item(subghz->history, 0); - subghz_view_receiver_delete_item(subghz->subghz_receiver, 0); + while(idx > 0 && subghz_history_full(subghz->history)) { + subghz_history_delete_item(subghz->history, 0); + subghz_view_receiver_delete_item(subghz->subghz_receiver, 0); + idx--; + } subghz_view_receiver_enable_draw_callback(subghz->subghz_receiver); + if(idx == 0) { + subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); + } subghz_scene_receiver_update_statusbar(subghz); subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); - idx--; } + if(subghz_history_add_to_history(history, decoder_base, &preset)) { furi_string_reset(item_name); furi_string_reset(item_time); //If the repeater is on, dont add to the menu, just TX the signal. if(subghz->repeater != SubGhzRepeaterStateOff) { - //subghz_scene_receiver_update_statusbar(subghz); view_dispatcher_send_custom_event( subghz->view_dispatcher, SubGhzCustomEventViewRepeaterStart); } else { @@ -176,7 +182,7 @@ static void subghz_scene_add_to_history_callback( subghz->idx_menu_chosen = subghz_view_receiver_get_idx_menu(subghz->subghz_receiver); subghz_view_receiver_enable_draw_callback(subghz->subghz_receiver); - if(subghz_history_get_last_index(subghz->history) == 0) { + if(idx == 0) { subghz_rx_key_state_set(subghz, SubGhzRxKeyStateStart); } } @@ -191,8 +197,12 @@ static void subghz_scene_add_to_history_callback( subghz_history_get_repeats(history, idx)); subghz_scene_receiver_update_statusbar(subghz); - if(subghz_history_get_text_space_left(subghz->history, NULL, 0)) { + if(!subghz->last_settings->delete_old_signals && + subghz_history_full(subghz->history)) { + subghz->state_notifications = SubGhzNotificationStateIDLE; notification_message(subghz->notifications, &sequence_error); + } else { + subghz->state_notifications = SubGhzNotificationStateRxDone; } } } @@ -253,8 +263,10 @@ void subghz_scene_receiver_on_enter(void* context) { subghz->subghz_receiver, subghz_scene_receiver_callback, subghz); subghz_txrx_set_rx_callback(subghz->txrx, subghz_scene_add_to_history_callback, subghz); - if(!subghz_history_get_text_space_left(subghz->history, NULL, 0)) { + if(!subghz_history_full(subghz->history)) { subghz->state_notifications = SubGhzNotificationStateRx; + } else { + subghz->state_notifications = SubGhzNotificationStateIDLE; } // Check if hopping was enabled diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_config.c b/applications/main/subghz/scenes/subghz_scene_receiver_config.c index 535351de42..fc309ca091 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_config.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_config.c @@ -12,6 +12,7 @@ enum SubGhzSettingIndex { SubGhzSettingIndexRAWRSSIThreshold = SubGhzSettingIndexBinRAW, SubGhzSettingIndexRepeater, SubGhzSettingIndexRemoveDuplicates, + SubGhzSettingIndexDeleteOldSignals, SubGhzSettingIndexIgnoreStarline, SubGhzSettingIndexIgnoreCars, SubGhzSettingIndexIgnoreMagellan, @@ -19,7 +20,6 @@ enum SubGhzSettingIndex { SubGhzSettingIndexIgnoreNiceFlorS, SubGhzSettingIndexIgnoreWeather, SubGhzSettingIndexIgnoreTPMS, - SubGhzSettingIndexDeleteOldSignals, SubGhzSettingIndexSound, SubGhzSettingIndexResetToDefault, SubGhzSettingIndexLock, @@ -346,6 +346,15 @@ static void subghz_scene_receiver_config_set_duplicates(VariableItem* item) { if(index) subghz_history_remove_duplicates(subghz->history); } +static void subghz_scene_receiver_config_set_delete_old_signals(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, combobox_text[index]); + + subghz->last_settings->delete_old_signals = index == 1; +} + static inline bool subghz_scene_receiver_config_ignore_filter_get_index( SubGhzProtocolFilter filter, SubGhzProtocolFilter flag) { @@ -379,15 +388,6 @@ static void subghz_scene_receiver_config_set_tpms(VariableItem* item) { subghz_scene_receiver_config_set_ignore_filter(item, SubGhzProtocolFilter_TPMS); } -static void subghz_scene_receiver_config_set_delete_old_signals(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, combobox_text[index]); - - subghz->last_settings->delete_old_signals = index == 1; -} - static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) { furi_assert(context); SubGhz* subghz = context; @@ -535,6 +535,17 @@ void subghz_scene_receiver_config_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, combobox_text[value_index]); + item = variable_item_list_add( + subghz->variable_item_list, + "Delete Old Signals on Full Memory", + COMBO_BOX_COUNT, + subghz_scene_receiver_config_set_delete_old_signals, + subghz); + + value_index = subghz->last_settings->delete_old_signals; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, combobox_text[value_index]); + item = variable_item_list_add( subghz->variable_item_list, "Ignore Starline", @@ -618,17 +629,6 @@ void subghz_scene_receiver_config_on_enter(void* context) { subghz->ignore_filter, SubGhzProtocolFilter_TPMS); variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, combobox_text[value_index]); - - item = variable_item_list_add( - subghz->variable_item_list, - "Delete Old Signals on Full Memory", - COMBO_BOX_COUNT, - subghz_scene_receiver_config_set_delete_old_signals, - subghz); - - value_index = subghz->last_settings->delete_old_signals; - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, combobox_text[value_index]); } // Enable speaker, will send all incoming noises and signals to speaker so you can listen how your remote sounds like :) diff --git a/applications/main/subghz/scenes/subghz_scene_receiver_info.c b/applications/main/subghz/scenes/subghz_scene_receiver_info.c index 0e34338b73..63048e1625 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver_info.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver_info.c @@ -127,7 +127,7 @@ void subghz_scene_receiver_info_on_enter(void* context) { subghz_scene_receiver_info_draw_widget(subghz); - if(!subghz_history_get_text_space_left(subghz->history, NULL, 0)) { + if(!subghz_history_full(subghz->history)) { subghz->state_notifications = SubGhzNotificationStateRx; } } @@ -163,7 +163,7 @@ bool subghz_scene_receiver_info_on_event(void* context, SceneManagerEvent event) subghz_txrx_rx_start(subghz->txrx); subghz_txrx_hopper_unpause(subghz->txrx); - if(!subghz_history_get_text_space_left(subghz->history, NULL, 0)) { + if(!subghz_history_full(subghz->history)) { subghz->state_notifications = SubGhzNotificationStateRx; } } diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index 05cfbf533e..31437cf71a 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -182,15 +182,21 @@ FlipperFormat* subghz_history_get_raw_data(SubGhzHistory* instance, uint16_t idx return NULL; } } -bool subghz_history_get_text_space_left(SubGhzHistory* instance, FuriString* output, uint8_t sats) { +bool subghz_history_get_text_space_left( + SubGhzHistory* instance, + FuriString* output, + uint8_t sats, + bool ignore_full) { furi_assert(instance); - if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) { - if(output != NULL) furi_string_printf(output, " Memory is FULL"); - return true; - } - if(instance->last_index_write == SUBGHZ_HISTORY_MAX) { - if(output != NULL) furi_string_printf(output, " History is FULL"); - return true; + if(!ignore_full) { + if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) { + if(output != NULL) furi_string_printf(output, " Memory is FULL"); + return true; + } + if(instance->last_index_write == SUBGHZ_HISTORY_MAX) { + if(output != NULL) furi_string_printf(output, " History is FULL"); + return true; + } } if(output != NULL) { if(sats == 0) { diff --git a/applications/main/subghz/subghz_history.h b/applications/main/subghz/subghz_history.h index f648499a06..642812f74b 100644 --- a/applications/main/subghz/subghz_history.h +++ b/applications/main/subghz/subghz_history.h @@ -115,9 +115,14 @@ void subghz_history_get_time_item_menu(SubGhzHistory* instance, FuriString* outp * @param instance - SubGhzHistory instance * @param output - FuriString* output * @param sats - Number of satellites + * @param ignore_full - Ignore if history is full * @return bool - is FULL */ -bool subghz_history_get_text_space_left(SubGhzHistory* instance, FuriString* output, uint8_t sats); +bool subghz_history_get_text_space_left( + SubGhzHistory* instance, + FuriString* output, + uint8_t sats, + bool ignore_full); /** Return last index * diff --git a/applications/main/subghz/views/receiver.c b/applications/main/subghz/views/receiver.c index 3722838893..8c060e4bbc 100644 --- a/applications/main/subghz/views/receiver.c +++ b/applications/main/subghz/views/receiver.c @@ -736,6 +736,7 @@ void subghz_view_receiver_delete_item(SubGhzViewReceiver* subghz_receiver, uint1 } }, true); + subghz_view_receiver_update_offset(subghz_receiver); } void subghz_view_receiver_enable_draw_callback(SubGhzViewReceiver* subghz_receiver) {