Skip to content

Commit d26b0ff

Browse files
committed
implement 2022-11-09 suggested changes
1 parent 22f0f5b commit d26b0ff

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

app/src/ble.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ static int ble_profiles_handle_set(const char *name, size_t len, settings_read_c
362362
}
363363

364364
int i = atoi(next);
365-
if (i >= ZMK_BLE_SPLIT_PERIPHERAL_COUNT) {
365+
if (i < 0 || i >= ZMK_BLE_SPLIT_PERIPHERAL_COUNT) {
366366
LOG_ERR("Failed to store peripheral address in memory");
367367
} else {
368368
int err = read_cb(cb_arg, &peripheral_addrs[i], sizeof(bt_addr_le_t));

app/src/split/bluetooth/central.c

+10-22
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ static int stop_scanning() {
357357
is_scanning = false;
358358

359359
int err = bt_le_scan_stop();
360-
if (err) {
360+
if (err < 0) {
361361
LOG_ERR("Stop LE scan failed (err %d)", err);
362362
return err;
363363
}
@@ -370,7 +370,7 @@ static bool split_central_eir_found(const bt_addr_le_t *addr) {
370370

371371
// Stop scanning so we can connect to the peripheral device.
372372
int err = stop_scanning();
373-
if (err) {
373+
if (err < 0) {
374374
return false;
375375
}
376376

@@ -382,25 +382,13 @@ static bool split_central_eir_found(const bt_addr_le_t *addr) {
382382

383383
struct peripheral_slot *slot = &peripherals[slot_idx];
384384

385-
slot->conn = bt_conn_lookup_addr_le(BT_ID_DEFAULT, addr);
386-
if (slot->conn) {
387-
LOG_DBG("Found existing connection");
388-
split_central_process_connection(slot->conn);
389-
err = bt_conn_le_phy_update(slot->conn, BT_CONN_LE_PHY_PARAM_2M);
390-
if (err) {
391-
LOG_ERR("Update phy conn failed (err %d)", err);
392-
}
393-
} else {
394-
struct bt_le_conn_param *param = BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400);
395-
396-
LOG_DBG("Initiating new connnection");
397-
398-
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &slot->conn);
399-
if (err) {
400-
LOG_ERR("Create conn failed (err %d) (create conn? 0x%04x)", err,
401-
BT_HCI_OP_LE_CREATE_CONN);
402-
start_scanning();
403-
}
385+
LOG_DBG("Initiating new connnection");
386+
struct bt_le_conn_param *param = BT_LE_CONN_PARAM(0x0006, 0x0006, 30, 400);
387+
err = bt_conn_le_create(addr, BT_CONN_LE_CREATE_CONN, param, &slot->conn);
388+
if (err < 0) {
389+
LOG_ERR("Create conn failed (err %d) (create conn? 0x%04x)", err, BT_HCI_OP_LE_CREATE_CONN);
390+
release_peripheral_slot(slot_idx);
391+
start_scanning();
404392
}
405393

406394
return false;
@@ -484,7 +472,7 @@ static int start_scanning(void) {
484472
// Start scanning otherwise.
485473
is_scanning = true;
486474
int err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, split_central_device_found);
487-
if (err) {
475+
if (err < 0) {
488476
LOG_ERR("Scanning failed to start (err %d)", err);
489477
return err;
490478
}

0 commit comments

Comments
 (0)