Skip to content
Merged
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
4 changes: 4 additions & 0 deletions libraries/BluetoothHCI/src/BluetoothHCI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class BluetoothHCI {

void scanFree(); // Free allocated scan buffers

bool connected() {
return _hciConn != HCI_CON_HANDLE_INVALID;
}

friend class BluetoothHIDMaster;

protected:
Expand Down
17 changes: 16 additions & 1 deletion libraries/BluetoothHIDMaster/src/BluetoothHIDMaster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,22 @@ bool BluetoothHIDMaster::connectBLE(const uint8_t *addr, int addrType) {
}
uint8_t a[6];
memcpy(a, addr, sizeof(a));
return ERROR_CODE_SUCCESS == gap_connect(a, (bd_addr_type_t)addrType);
if (ERROR_CODE_SUCCESS != gap_connect(a, (bd_addr_type_t)addrType)) {
return false;
}
// GAP connection running async. Wait for HCI connect
uint32_t now = millis();
while (millis() - now < 5000) {
if (_hci.connected()) {
break;
}
delay(25);
}
if (!_hci.connected()) {
gap_connect_cancel();
return false;
}
return _hci.connected();
}

bool BluetoothHIDMaster::connectBLE() {
Expand Down