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;
|
||||
|
||||
@@ -153,6 +153,8 @@ private:
|
||||
bool _start_if_disconnect;
|
||||
bool _runnning;
|
||||
|
||||
uint32_t _conn_mask;
|
||||
|
||||
uint16_t _fast_interval; // in 0.625 ms
|
||||
uint16_t _slow_interval; // in 0.625 ms
|
||||
uint16_t _active_interval; // in 0.625 ms
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -100,6 +100,8 @@ private:
|
||||
uint8_t _scan_data[BLE_GAP_SCAN_BUFFER_MAX];
|
||||
ble_data_t _report_data;
|
||||
|
||||
uint32_t _conn_mask;
|
||||
|
||||
bool _runnning;
|
||||
bool _start_if_disconnect;
|
||||
|
||||
|
||||
@@ -763,7 +763,7 @@ void adafruit_ble_task(void* arg)
|
||||
*/
|
||||
void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
{
|
||||
// conn handle has fixed offset regardless of event type
|
||||
// conn handle has fixed offset for all events
|
||||
uint16_t const evt_conn_hdl = evt->evt.common_evt.conn_handle;
|
||||
|
||||
LOG_LV1("BLE", "%s : Conn Handle = %d", dbg_ble_event_str(evt->header.evt_id), evt_conn_hdl);
|
||||
|
||||
Reference in new issue
Block a user