diff --git a/applications/main/subghz/scenes/subghz_scene_receiver.c b/applications/main/subghz/scenes/subghz_scene_receiver.c index d1a6a49fe..15ad94bdb 100644 --- a/applications/main/subghz/scenes/subghz_scene_receiver.c +++ b/applications/main/subghz/scenes/subghz_scene_receiver.c @@ -133,21 +133,17 @@ 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) { - if(subghz_history_get_last_index(subghz->history) >= 54) { - subghz->state_notifications = SubGhzNotificationStateRx; + 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_view_receiver_disable_draw_callback(subghz->subghz_receiver); + subghz_history_delete_item(subghz->history, 0); + subghz_view_receiver_delete_item(subghz->subghz_receiver, 0); - subghz_history_delete_item(subghz->history, 0); - subghz_view_receiver_delete_item(subghz->subghz_receiver, 0); - 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); - 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); + idx--; } if(subghz_history_add_to_history(history, decoder_base, &preset)) { furi_string_reset(item_name); diff --git a/applications/main/subghz/subghz_history.c b/applications/main/subghz/subghz_history.c index f50084f86..fb1de05de 100644 --- a/applications/main/subghz/subghz_history.c +++ b/applications/main/subghz/subghz_history.c @@ -221,8 +221,7 @@ bool subghz_history_add_to_history( furi_assert(instance); furi_assert(context); - if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) return false; - if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return false; + if(subghz_history_full(instance)) return false; SubGhzProtocolDecoderBase* decoder_base = context; uint32_t hash_data = subghz_protocol_decoder_base_get_hash_data_long(decoder_base); @@ -350,3 +349,9 @@ void subghz_history_remove_duplicates(SubGhzHistory* instance) { SubGhzHistoryItemArray_previous(it); } } + +bool subghz_history_full(SubGhzHistory* instance) { + if(memmgr_get_free_heap() < SUBGHZ_HISTORY_FREE_HEAP) return true; + if(instance->last_index_write >= SUBGHZ_HISTORY_MAX) return true; + return false; +} diff --git a/applications/main/subghz/subghz_history.h b/applications/main/subghz/subghz_history.h index 403c91993..d9aacf0e8 100644 --- a/applications/main/subghz/subghz_history.h +++ b/applications/main/subghz/subghz_history.h @@ -156,3 +156,6 @@ float subghz_history_get_longitude(SubGhzHistory* instance, uint16_t idx); // Consolidate history removing existing duplicates void subghz_history_remove_duplicates(SubGhzHistory* instance); + +// Check if memory/history is full +bool subghz_history_full(SubGhzHistory* instance);