@@ -265,7 +265,6 @@ BLEAdvertising::BLEAdvertising(void)
265265 _stop_timeout = _left_timeout = 0 ;
266266 _stop_cb = NULL ;
267267 _slow_cb = NULL ;
268- _directed = false ; // Broadcast advertising is the default
269268}
270269
271270void BLEAdvertising::setFastTimeout (uint16_t sec)
@@ -316,15 +315,8 @@ void BLEAdvertising::setStopCallback(stop_callback_t fp)
316315 _stop_cb = fp;
317316}
318317
319- void BLEAdvertising::setPeerAddress (const ble_gap_addr_t & peer_addr)
320- {
321- _directed = true ;
322- _peer_addr = peer_addr; // Copy address, used later in start function
323- }
324-
325- void BLEAdvertising::removePeerAddress ()
326- {
327- _directed = false ;
318+ void BLEAdvertising::setPeerAddress (const ble_gap_addr_t & peer_addr) {
319+ _peer_addr = peer_addr;
328320}
329321
330322bool BLEAdvertising::isRunning (void )
@@ -350,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
350342bool BLEAdvertising::_start (uint16_t interval, uint16_t timeout)
351343{
352344 // ADV Params
353- ble_gap_adv_params_t adv_para =
354- {
345+ ble_gap_adv_params_t adv_para = {
355346 .properties = { .type = _type, .anonymous = 0 },
356347 .p_peer_addr = NULL , // Undirected advertisement
357348 .interval = interval , // advertising interval (in units of 0.625 ms)
@@ -366,14 +357,20 @@ bool BLEAdvertising::_start(uint16_t interval, uint16_t timeout)
366357 // , .set_id, .scan_req_notification
367358 };
368359
369- if (_directed) {
370- // Set target address when not using broadcasting
360+ switch (_type) {
361+ case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED_HIGH_DUTY_CYCLE:
362+ case BLE_GAP_ADV_TYPE_CONNECTABLE_NONSCANNABLE_DIRECTED:
363+ case BLE_GAP_ADV_TYPE_EXTENDED_CONNECTABLE_NONSCANNABLE_DIRECTED:
364+ case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_SCANNABLE_DIRECTED:
365+ case BLE_GAP_ADV_TYPE_EXTENDED_NONCONNECTABLE_NONSCANNABLE_DIRECTED:
371366 adv_para.p_peer_addr = &_peer_addr;
367+ break ;
368+
369+ default : break ;
372370 }
373371
374372 // gap_adv long-live is required by SD v6
375- static ble_gap_adv_data_t gap_adv =
376- {
373+ static ble_gap_adv_data_t gap_adv = {
377374 .adv_data = { .p_data = _data, .len = _count },
378375 .scan_rsp_data = { .p_data = Bluefruit.ScanResponse .getData (), .len = Bluefruit.ScanResponse .count () }
379376 };
0 commit comments