Skip to content

Commit

Permalink
check for duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
ldab committed Jul 9, 2024
1 parent 5ded1f3 commit bce4260
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/src/applications/lea_assistant/lea_assistant_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

#include "message_handler.h"

#define MAX_DEVICES_NUM 16

typedef struct devices_list {
uint8_t num;
bt_addr_le_t addr[MAX_DEVICES_NUM];
} devices_list_t;

LOG_MODULE_REGISTER(lea_assistant_app, CONFIG_ZSW_LEA_ASSISTANT_APP_LOG_LEVEL);

// Functions needed for all applications
Expand All @@ -37,6 +44,10 @@ static application_t app = {
.stop_func = lea_assistant_app_stop
};

static devices_list_t devices_list = {
.num = 0,
};

static void close_app(void)
{
zsw_app_manager_app_close_request(&app);
Expand All @@ -55,6 +66,8 @@ static void on_sink_selected(lea_assistant_device_t *device)
{
LOG_DBG("Sink %s selected", device->name);

devices_list.num = 0;

message_handler(&(struct webusb_message ) {
.sub_type = MESSAGE_SUBTYPE_STOP_SCAN
}, 0);
Expand Down Expand Up @@ -83,6 +96,8 @@ static void lea_assistant_app_stop(void)
message_handler(&(struct webusb_message ) {
.sub_type = MESSAGE_SUBTYPE_STOP_SCAN
}, 0);

devices_list.num = 0;
}

static int lea_assistant_app_add(void)
Expand All @@ -94,6 +109,21 @@ static int lea_assistant_app_add(void)

void lea_assistant_app_add_entry(lea_assistant_device_t *device)
{
for (size_t i = 0; i < devices_list.num; i++) {
if (bt_addr_le_cmp(&device->addr, &devices_list.addr[i]) == 0) {
LOG_DBG("Device already added (%s)", device->name);
return;
}
}

if (devices_list.num > MAX_DEVICES_NUM) {
LOG_WRN("MAX devices reached");
return;
}

bt_addr_le_copy(&devices_list.addr[devices_list.num], &device->addr);
devices_list.num++;

lea_assistant_ui_add_list_entry(device);
}

Expand Down

0 comments on commit bce4260

Please sign in to comment.