Skip to content

Commit 51ee8d7

Browse files
authored
Update BLEDevice.cpp
1 parent 7dd2a02 commit 51ee8d7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/BLEDevice.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525

2626
#include "BLEDevice.h"
2727

28+
#include "ble/AdvertisingParameters.h"
29+
#include "ble/Gap.h"
30+
31+
2832
extern "C" int strcasecmp(char const *a, char const *b);
2933

3034
BLEDevice::BLEDevice() :
@@ -576,3 +580,25 @@ bool BLEDevice::discovered()
576580
return (_advertisementTypeMask & 0x18) != 0;
577581
}
578582

583+
void BLEDevice::setTxPower(int8_t dbm) {
584+
if (!_ble_interface.hasInitialized()) return;
585+
_ble_interface.gap().setTxPower(dbm);
586+
}
587+
588+
void BLEDevice::enableCodedPHYAdvertising(bool enabled) {
589+
if (!_ble_interface.hasInitialized()) return;
590+
591+
ble::AdvertisingParameters advParams(
592+
ble::advertising_type_t::NON_CONNECTABLE_UNDIRECTED,
593+
ble::adv_interval_t(ble::millisecond_t(200))
594+
);
595+
if (enabled) {
596+
advParams.setPhy(ble::phy_t::LE_1M, ble::phy_t::LE_CODED);
597+
}
598+
auto& gap = _ble_interface.gap();
599+
gap.setAdvertisingParameters(_adv_handle, advParams);
600+
601+
// Set TX power here if not using setTxPower separately
602+
gap.setTxPower(4);
603+
}
604+

0 commit comments

Comments
 (0)