fix issue with advertising and scanner when disconnected
This commit is contained in:
5 files changed
+26
-7
No files matched your search
@@ -41,14 +41,13 @@ BLEScanner::BLEScanner(void)
|
||||
_report_data.p_data = _scan_data;
|
||||
_report_data.len = BLE_GAP_SCAN_BUFFER_MAX;
|
||||
|
||||
_conn_mask = 0;
|
||||
_runnning = false;
|
||||
_start_if_disconnect = true;
|
||||
|
||||
_filter_rssi = INT8_MIN;
|
||||
|
||||
_filter_msd_en = false;
|
||||
_filter_msd_id = 0; // Irrelevant
|
||||
|
||||
_filter_uuid_count = 0;
|
||||
_filter_uuid = NULL;
|
||||
|
||||
@@ -331,6 +330,9 @@ void BLEScanner::clearFilters(void)
|
||||
*/
|
||||
void BLEScanner::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
// conn handle has fixed offset for all events
|
||||
uint16_t const conn_hdl = evt->evt.common_evt.conn_handle;
|
||||
|
||||
switch ( evt->header.evt_id )
|
||||
{
|
||||
case BLE_GAP_EVT_ADV_REPORT:
|
||||
@@ -387,15 +389,19 @@ void BLEScanner::_eventHandler(ble_evt_t* evt)
|
||||
|
||||
if ( para->role == BLE_GAP_ROLE_CENTRAL)
|
||||
{
|
||||
bitSet(_conn_mask, conn_hdl);
|
||||
|
||||
_runnning = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
if ( BLE_GAP_ROLE_CENTRAL == Bluefruit.Gap.getRole(evt->evt.common_evt.conn_handle) )
|
||||
if ( bitRead(_conn_mask, conn_hdl) && (0 == Bluefruit.Central.connected()) )
|
||||
{
|
||||
// Auto start if enabled
|
||||
bitClear(_conn_mask, conn_hdl);
|
||||
|
||||
// Auto start if enabled and not connected to any peripherals
|
||||
if ( !_runnning && _start_if_disconnect ) start(_param.timeout);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user