add BLECentral disconnect()

This commit is contained in:
hathach committed 2017-07-13 18:32:31 +07:00
1 parent 684bb3dab7
commit 78f3be6dfa
5 files changed
+18 -7

No files matched your search

@@ -121,6 +121,9 @@ void connect_callback(uint16_t conn_handle)
}else
{
Serial.println("Found NONE");
// disconect since we couldn't find bleuart service
Bluefruit.Central.disconnect(conn_handle);
}
}
@@ -135,7 +138,6 @@ void disconnect_callback(uint16_t conn_handle, uint8_t reason)
(void) reason;
Serial.println("Disconnected");
Serial.println("Bluefruit will auto start scanning (default)");
}
/**
+8 -3
View File
@@ -87,6 +87,11 @@ bool BLECentral::connect(const ble_gap_evt_adv_report_t* adv_report)
return connect(&adv_report->peer_addr);
}
bool BLECentral::disconnect(uint16_t conn_handle)
{
return ERROR_NONE == sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
/**
* Check if connected to a specific peripheral
* @param conn_handle
@@ -106,10 +111,10 @@ bool BLECentral::connected(void)
{
for (uint8_t conn=0; conn<BLE_MAX_CONN; conn++)
{
// skip Peripherl Role handle
if (conn != Bluefruit.connHandle() )
// skip Peripheral Role handle
if ( Bluefruit.Gap.connected(conn) && (Bluefruit.Gap.getRole(conn) == BLE_GAP_ROLE_CENTRAL) )
{
if ( Bluefruit.Gap.connected(conn) ) return true;
return true;
}
}
@@ -68,6 +68,8 @@ class BLECentral
bool connect(const ble_gap_evt_adv_report_t* adv_report);
bool connect(const ble_gap_addr_t *peer_addr);
bool disconnect(uint16_t conn_handle);
bool connected (uint16_t conn_handle); // If connected to a specific peripheral
bool connected (void); // If connected to any peripherals
+4 -2
View File
@@ -302,13 +302,15 @@ bool AdafruitBluefruit::connected(void)
return ( _conn_hdl != BLE_CONN_HANDLE_INVALID );
}
void AdafruitBluefruit::disconnect(void)
bool AdafruitBluefruit::disconnect(void)
{
// disconnect if connected
if ( connected() )
{
sd_ble_gap_disconnect(_conn_hdl, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
return ERROR_NONE == sd_ble_gap_disconnect(_conn_hdl, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
}
return true; // not connected still return true
}
void AdafruitBluefruit::setConnectCallback( BLEGap::connect_callback_t fp )
+1 -1
View File
@@ -119,7 +119,7 @@ class AdafruitBluefruit
/* GAP, Connections and Bonding
*------------------------------------------------------------------*/
bool connected (void);
void disconnect (void);
bool disconnect (void);
bool setConnInterval (uint16_t min, uint16_t max);
bool setConnIntervalMS (uint16_t min_ms, uint16_t max_ms);