Fix many SubGhz history bugs

No "history full" if "delete old signals"
Delete more old signals if history full
Fix visual offset bug with "delete old signals"
Fix led and sound for full history / not
"Delete old signals" in decode raw too
This commit is contained in:
Willy-JL
2024-01-27 19:12:59 +00:00
parent cb635ff2d2
commit 0e8703a7a1
6 changed files with 63 additions and 25 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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) {

View File

@@ -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
*

View File

@@ -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) {