Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add paired device listing #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/esp32/esp32_bt_gap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ bool mgos_bt_gap_get_pairing_enable(void);
bool mgos_bt_gap_set_pairing_enable(bool pairing_enable);

int mgos_bt_gap_get_num_paired_devices(void);

/*
* Return list of paired devices; the caller should free it.
*/
bool mgos_bt_gap_get_paired_device_list(int *dev_num, struct mgos_bt_addr *list);

/*
* These are actually async. TODO(rojer): Add callbacks to the API.
* For now, just allow some time for the calls to complete.
Expand Down
19 changes: 19 additions & 0 deletions src/esp32/esp32_bt_gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,25 @@ bool mgos_bt_gap_set_pairing_enable(bool pairing_enable) {
}
}

bool mgos_bt_gap_get_paired_device_list(int *dev_num, struct mgos_bt_addr *list) {
esp_ble_bond_dev_t *dev_list;
bool rc = true;

if(*dev_num == 0)
return false;
if((dev_list = calloc(*dev_num, sizeof(esp_ble_bond_dev_t))) == NULL)
return false;
if(esp_ble_get_bond_device_list(dev_num, dev_list) == ESP_OK) {
for(int i=0; i<*dev_num; i++) {
memcpy(&list->addr, &dev_list[i].bd_addr, sizeof(esp_bd_addr_t));
list->type = MGOS_BT_ADDR_TYPE_NONE;
++list;
}
} else rc = false;
free(dev_list);
return rc;
}

void mgos_bt_gap_remove_paired_device(const esp_bd_addr_t addr) {
esp_ble_remove_bond_device((uint8_t *) addr);
}
Expand Down