Bluefruit.connected(void) return number of connected as prph, Central.connected(void) return number of connection as central
This commit is contained in:
4 files changed
+20
-18
No files matched your search
@@ -95,28 +95,21 @@ bool BLECentral::disconnect(uint16_t conn_hdl)
|
||||
bool BLECentral::connected(uint16_t conn_hdl)
|
||||
{
|
||||
BLEConnection* conn = Bluefruit.Gap.getConnection(conn_hdl);
|
||||
return conn && (conn->getRole() == BLE_GAP_ROLE_CENTRAL);
|
||||
return conn && conn->connected() && (conn->getRole() == BLE_GAP_ROLE_CENTRAL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if connected to ANY peripherals
|
||||
* @param conn_handle
|
||||
* @return
|
||||
* @return number of peripherals
|
||||
*/
|
||||
bool BLECentral::connected(void)
|
||||
uint8_t BLECentral::connected(void)
|
||||
{
|
||||
for (uint8_t c=0; c<BLE_MAX_CONN; c++)
|
||||
uint8_t count = 0;
|
||||
for (uint16_t c=0; c<BLE_MAX_CONN; c++)
|
||||
{
|
||||
BLEConnection* conn = Bluefruit.Gap.getConnection(c);
|
||||
|
||||
// skip Peripheral Role handle
|
||||
if ( conn && conn->connected() && (conn->getRole() == BLE_GAP_ROLE_CENTRAL) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( this->connected(c) ) count++;
|
||||
}
|
||||
|
||||
return false;
|
||||
return count;
|
||||
}
|
||||
|
||||
void BLECentral::setConnectCallback( BLEGap::connect_callback_t fp)
|
||||
|
||||
@@ -68,8 +68,8 @@ class BLECentral
|
||||
bool connect(const ble_gap_addr_t *peer_addr);
|
||||
bool disconnect(uint16_t conn_hdl);
|
||||
|
||||
bool connected (uint16_t conn_hdl); // If connected to a specific peripheral
|
||||
bool connected (void); // If connected to any peripherals
|
||||
bool connected(uint16_t conn_hdl); // Connected as central to this connection
|
||||
uint8_t connected(void); // Number of connected Peripherals
|
||||
|
||||
void clearBonds (void);
|
||||
|
||||
|
||||
@@ -536,9 +536,18 @@ uint16_t AdafruitBluefruit::getApperance(void)
|
||||
/* GAP, Connections and Bonding
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
bool AdafruitBluefruit::connected(void)
|
||||
uint8_t AdafruitBluefruit::connected(void)
|
||||
{
|
||||
return ( _conn_hdl != BLE_CONN_HANDLE_INVALID );
|
||||
|
||||
uint8_t count = 0;
|
||||
for (uint16_t c=0; c<BLE_MAX_CONN; c++)
|
||||
{
|
||||
// skip Peripheral Role handle
|
||||
if ( this->connected(c) ) count++;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
bool AdafruitBluefruit::connected(uint16_t conn_hdl)
|
||||
|
||||
@@ -154,7 +154,7 @@ class AdafruitBluefruit
|
||||
/*------------------------------------------------------------------*/
|
||||
/* GAP, Connections and Bonding
|
||||
*------------------------------------------------------------------*/
|
||||
bool connected (void); // connected with any central
|
||||
uint8_t connected (void); // Number of connected central
|
||||
bool connected (uint16_t conn_hdl); // connected to a specific central
|
||||
bool disconnect (void);
|
||||
|
||||
|
||||
Reference in new issue
Block a user