SubGhz remove previous duplicates on enable/click (#373)

This commit is contained in:
Willy-JL
2023-12-10 21:03:20 +00:00
parent 9fbb9ebbae
commit 2547431bf1
4 changed files with 40 additions and 2 deletions

View File

@@ -82,6 +82,7 @@ typedef enum {
SubGhzCustomEventSceneShowOnlyRX,
SubGhzCustomEventSceneAnalyzerLock,
SubGhzCustomEventSceneAnalyzerUnlock,
SubGhzCustomEventSceneSettingRemoveDuplicates,
SubGhzCustomEventSceneSettingLock,
SubGhzCustomEventSceneSettingResetToDefault,

View File

@@ -275,6 +275,10 @@ static void subghz_scene_receiver_config_set_duplicates(VariableItem* item) {
variable_item_set_current_value_text(item, combobox_text[index]);
subghz->last_settings->remove_duplicates = subghz->remove_duplicates = index;
if(index) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneSettingRemoveDuplicates);
}
}
static inline bool subghz_scene_receiver_config_ignore_filter_get_index(
@@ -313,7 +317,10 @@ static void subghz_scene_receiver_config_set_tpms(VariableItem* item) {
static void subghz_scene_receiver_config_var_list_enter_callback(void* context, uint32_t index) {
furi_assert(context);
SubGhz* subghz = context;
if(index == SubGhzSettingIndexLock) {
if(index == SubGhzSettingIndexRemoveDuplicates) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneSettingRemoveDuplicates);
} else if(index == SubGhzSettingIndexLock) {
view_dispatcher_send_custom_event(
subghz->view_dispatcher, SubGhzCustomEventSceneSettingLock);
} else if(index == SubGhzSettingIndexResetToDefault) {
@@ -582,7 +589,11 @@ bool subghz_scene_receiver_config_on_event(void* context, SceneManagerEvent even
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubGhzCustomEventSceneSettingLock) {
if(event.event == SubGhzCustomEventSceneSettingRemoveDuplicates) {
subghz_history_remove_duplicates(subghz->history);
scene_manager_previous_scene(subghz->scene_manager);
consumed = true;
} else if(event.event == SubGhzCustomEventSceneSettingLock) {
subghz_lock(subghz);
scene_manager_previous_scene(subghz->scene_manager);
consumed = true;

View File

@@ -332,3 +332,26 @@ bool subghz_history_add_to_history(
instance->last_index_write++;
return true;
}
void subghz_history_remove_duplicates(SubGhzHistory* instance) {
furi_assert(instance);
SubGhzHistoryItemArray_it_t it;
SubGhzHistoryItemArray_it_last(it, instance->history->data);
while(!SubGhzHistoryItemArray_end_p(it)) {
SubGhzHistoryItem* i = SubGhzHistoryItemArray_ref(it);
SubGhzHistoryItemArray_it_t jt;
SubGhzHistoryItemArray_it_set(jt, it);
SubGhzHistoryItemArray_previous(jt);
while(!SubGhzHistoryItemArray_end_p(jt)) {
SubGhzHistoryItem* j = SubGhzHistoryItemArray_ref(jt);
if(j->hash_data == i->hash_data) {
subghz_history_delete_item(instance, jt->index);
}
SubGhzHistoryItemArray_previous(jt);
}
SubGhzHistoryItemArray_previous(it);
}
}

View File

@@ -153,3 +153,6 @@ float subghz_history_get_latitude(SubGhzHistory* instance, uint16_t idx);
* @return longitude - Float
*/
float subghz_history_get_longitude(SubGhzHistory* instance, uint16_t idx);
// Consolidate history removing existing duplicates
void subghz_history_remove_duplicates(SubGhzHistory* instance);