add bleconnection connected()
This commit is contained in:
5 files changed
+15
-3
No files matched your search
@@ -110,7 +110,7 @@ bool BLECentral::connected(void)
|
||||
BLEConnection* conn = Bluefruit.Gap.getConnection(c);
|
||||
|
||||
// skip Peripheral Role handle
|
||||
if ( conn && (conn->getRole() == BLE_GAP_ROLE_CENTRAL) )
|
||||
if ( conn && conn->connected() && (conn->getRole() == BLE_GAP_ROLE_CENTRAL) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
BLEConnection::BLEConnection(uint16_t conn_hdl, ble_gap_evt_connected_t const* evt_connected, uint8_t hvn_qsize, uint8_t wrcmd_qsize)
|
||||
{
|
||||
_conn_hdl = conn_hdl;
|
||||
_connected = true;
|
||||
|
||||
_mtu = BLE_GATT_ATT_MTU_DEFAULT;
|
||||
_addr = evt_connected->peer_addr;
|
||||
@@ -72,6 +73,11 @@ uint16_t BLEConnection::handle (void)
|
||||
return _conn_hdl;
|
||||
}
|
||||
|
||||
bool BLEConnection::connected(void)
|
||||
{
|
||||
return _connected;
|
||||
}
|
||||
|
||||
bool BLEConnection::paired (void)
|
||||
{
|
||||
return _paired;
|
||||
@@ -190,6 +196,11 @@ void BLEConnection::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
switch(evt->header.evt_id)
|
||||
{
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
// mark as disconnected
|
||||
_connected = false;
|
||||
break;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
/* First-time Pairing
|
||||
* 1. Either we or peer initiate the process
|
||||
|
||||
@@ -49,6 +49,7 @@ class BLEConnection
|
||||
uint16_t _conn_interval;
|
||||
uint16_t _ediv;
|
||||
uint8_t _role;
|
||||
bool _connected;
|
||||
bool _paired;
|
||||
bool _hvc_received;
|
||||
|
||||
|
||||
@@ -150,7 +150,7 @@ bool BLEGap::setAddr(uint8_t mac[6], uint8_t type)
|
||||
|
||||
bool BLEGap::connected(uint16_t conn_hdl)
|
||||
{
|
||||
return _connection[conn_hdl] != NULL;
|
||||
return (_connection[conn_hdl] != NULL) && (_connection[conn_hdl]->connected());
|
||||
}
|
||||
|
||||
bool BLEGap::requestPairing(uint16_t conn_hdl)
|
||||
|
||||
@@ -544,7 +544,7 @@ bool AdafruitBluefruit::connected(void)
|
||||
bool AdafruitBluefruit::connected(uint16_t conn_hdl)
|
||||
{
|
||||
BLEConnection* conn = Gap.getConnection(conn_hdl);
|
||||
return conn && (conn->getRole() == BLE_GAP_ROLE_PERIPH);
|
||||
return conn && conn->connected() && (conn->getRole() == BLE_GAP_ROLE_PERIPH);
|
||||
}
|
||||
|
||||
bool AdafruitBluefruit::disconnect(void)
|
||||
|
||||
Reference in new issue
Block a user