fix(bluetooth): Corrected use of bt_addr_le_cmp

* Properly compare to zero when comparing LE addresses.
This commit is contained in:
Peter Johanson 2023-07-19 16:21:06 +00:00 committed by Pete Johanson
parent 73e1b526d5
commit ed400c4feb

View file

@ -281,14 +281,14 @@ int zmk_ble_put_peripheral_addr(const bt_addr_le_t *addr) {
for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) { for (int i = 0; i < ZMK_SPLIT_BLE_PERIPHERAL_COUNT; i++) {
// If the address is recognized and already stored in settings, return // If the address is recognized and already stored in settings, return
// index and no additional action is necessary. // index and no additional action is necessary.
if (!bt_addr_le_cmp(&peripheral_addrs[i], addr)) { if (bt_addr_le_cmp(&peripheral_addrs[i], addr) == 0) {
return i; return i;
} }
// If the peripheral address slot is open, store new peripheral in the // If the peripheral address slot is open, store new peripheral in the
// slot and return index. This compares against BT_ADDR_LE_ANY as that // slot and return index. This compares against BT_ADDR_LE_ANY as that
// is the zero value. // is the zero value.
if (!bt_addr_le_cmp(&peripheral_addrs[i], BT_ADDR_LE_ANY)) { if (bt_addr_le_cmp(&peripheral_addrs[i], BT_ADDR_LE_ANY) == 0) {
char addr_str[BT_ADDR_LE_STR_LEN]; char addr_str[BT_ADDR_LE_STR_LEN];
bt_addr_le_to_str(addr, addr_str, sizeof(addr_str)); bt_addr_le_to_str(addr, addr_str, sizeof(addr_str));
LOG_DBG("Storing peripheral %s in slot %d", addr_str, i); LOG_DBG("Storing peripheral %s in slot %d", addr_str, i);