Skip to content

Commit f96d9ce

Browse files
committed
auto use peerAddress if adv type is set to one of directed type
1 parent ea3dd12 commit f96d9ce

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

.gitignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
*.obj
44

55
# Visual Studio Code
6-
**/.vscode/
6+
.vscode/
7+
.idea/
8+
.pio/
9+
.piopm
710

811
# Executables
912
*.out
@@ -13,12 +16,11 @@
1316
/tools/.idea/
1417
/tools/midi_tests/node_modules
1518

16-
.idea/
1719
.DS_Store
1820
*.swp
1921
/Output
2022

2123
# Ignore local overrides of platform.txt and boards.txt,
2224
/boards.local.txt
2325
/platform.local.txt
24-
/libraries/**/build/
26+

libraries/Bluefruit52Lib/src/BLEAdvertising.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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

271270
void 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

330322
bool BLEAdvertising::isRunning(void)
@@ -350,8 +342,7 @@ void BLEAdvertising::restartOnDisconnect(bool enable)
350342
bool 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
};

libraries/Bluefruit52Lib/src/BLEAdvertising.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,9 @@ class BLEAdvertising : public BLEAdvertisingData
134134
bool setBeacon(BLEBeacon& beacon);
135135
bool setBeacon(EddyStoneUrl& eddy_url);
136136

137-
/// Advertise to a single peer instead of broadcasting
137+
// Advertise to a single peer instead of broadcasting
138138
void setPeerAddress(const ble_gap_addr_t& peer_addr);
139139

140-
/// Revert to broadcast advertising
141-
void removePeerAddress();
142-
143140
bool isRunning(void);
144141

145142
void restartOnDisconnect(bool enable);
@@ -159,7 +156,6 @@ class BLEAdvertising : public BLEAdvertisingData
159156
bool _start_if_disconnect;
160157
bool _runnning;
161158
ble_gap_addr_t _peer_addr; //! Target address for an ADV_DIRECT_IND advertisement
162-
bool _directed; //! Whether the advertisements are directed or broadcast
163159

164160
uint32_t _conn_mask;
165161

0 commit comments

Comments
 (0)