fix issue with advertising and scanner when disconnected
This commit is contained in:
5 files changed
+26
-7
No files matched your search
@@ -255,6 +255,8 @@ BLEAdvertising::BLEAdvertising(void)
|
||||
_start_if_disconnect = true;
|
||||
_runnning = false;
|
||||
|
||||
_conn_mask = 0;
|
||||
|
||||
_fast_interval = BLE_ADV_INTERVAL_FAST_DFLT;
|
||||
_slow_interval = BLE_ADV_INTERVAL_SLOW_DFLT;
|
||||
_active_interval = _fast_interval;
|
||||
@@ -397,6 +399,9 @@ bool BLEAdvertising::stop(void)
|
||||
|
||||
void BLEAdvertising::_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_CONNECTED:
|
||||
@@ -405,15 +410,19 @@ void BLEAdvertising::_eventHandler(ble_evt_t* evt)
|
||||
|
||||
if ( para->role == BLE_GAP_ROLE_PERIPH )
|
||||
{
|
||||
bitSet(_conn_mask, conn_hdl);
|
||||
|
||||
_runnning = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
if ( BLE_GAP_ROLE_PERIPH == Bluefruit.Gap.getRole(evt->evt.common_evt.conn_handle) )
|
||||
if ( bitRead(_conn_mask, conn_hdl) && (0 == Bluefruit.connected()) )
|
||||
{
|
||||
// Auto start if enabled
|
||||
bitClear(_conn_mask, conn_hdl);
|
||||
|
||||
// Auto start if enabled and not connected to any central
|
||||
if ( !_runnning && _start_if_disconnect ) start(_stop_timeout);
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in new issue
Block a user