Skip to content

Commit c38ab79

Browse files
committed
🐛 Fix NimBLE ^2 compatibility
1 parent a44b061 commit c38ab79

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Change your `platformio.ini` file to the following settings:
178178

179179
```diff
180180
lib_deps =
181-
+ h2zero/NimBLE-Arduino@^1.4.0
181+
+ h2zero/NimBLE-Arduino@^2.0.0
182182

183183
build_flags =
184184
+ -D BLESERIAL_USE_NIMBLE=true

src/BLESerial.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
# include <BLEDevice.h>
2020
#endif // BLESERIAL_USE_NIMBLE
2121

22+
#if !defined(BLESERIAL_NIMBLE_VERSION_MAJOR) && defined(BLESERIAL_USE_NIMBLE) && BLESERIAL_USE_NIMBLE
23+
# if __has_include(<NimBLEAdvertisementData.h>)
24+
# define BLESERIAL_NIMBLE_VERSION_MAJOR 2
25+
# else // __has_include(<NimBLEAdvertisementData.h>)
26+
# define BLESERIAL_NIMBLE_VERSION_MAJOR 1
27+
# endif // __has_include(<NimBLEAdvertisementData.h>)
28+
#endif // BLESERIAL_USE_NIMBLE
29+
2230
#ifndef BLESERIAL_USE_STL
2331
# define BLESERIAL_USE_STL true
2432
#endif // BLESERIAL_USE_STL
@@ -262,7 +270,15 @@ class BLESerialServerCallbacks : public BLEServerCallbacks {
262270
public:
263271
explicit BLESerialServerCallbacks(BLESerial<T>* bleSerial) : bleSerial(bleSerial) {}
264272

273+
#if defined(BLESERIAL_USE_NIMBLE) && BLESERIAL_USE_NIMBLE
274+
# if defined(NIMBLE_VERSION_MAJOR) && NIMBLE_VERSION_MAJOR >= 2
275+
void onDisconnect(NimBLEServer* pServer, NimBLEConnInfo& connInfo, int reason) override
276+
# else // NIMBLE_VERSION_MAJOR >= 2
277+
void onDisconnect(NimBLEServer* pServer, ble_gap_conn_desc* desc) override
278+
# endif // NIMBLE_VERSION_MAJOR >= 2
279+
#else // BLESERIAL_USE_NIMBLE
265280
void onDisconnect(BLEServer* pServer) override
281+
#endif // BLESERIAL_USE_NIMBLE
266282
{
267283
auto* pAdvertising = pServer->getAdvertising();
268284
if (pAdvertising == nullptr) {
@@ -280,7 +296,15 @@ class BLESerialCharacteristicCallbacks : public BLECharacteristicCallbacks {
280296
public:
281297
explicit BLESerialCharacteristicCallbacks(BLESerial<T>* bleSerial) : bleSerial(bleSerial) {}
282298

299+
#if defined(BLESERIAL_USE_NIMBLE) && BLESERIAL_USE_NIMBLE
300+
# if defined(NIMBLE_VERSION_MAJOR) && NIMBLE_VERSION_MAJOR >= 2
301+
void onWrite(NimBLECharacteristic* pCharacteristic, NimBLEConnInfo& connInfo) override
302+
# else // NIMBLE_VERSION_MAJOR >= 2
303+
void onWrite(NimBLECharacteristic* pCharacteristic, ble_gap_conn_desc* desc) override
304+
# endif // NIMBLE_VERSION_MAJOR >= 2
305+
#else // BLESERIAL_USE_NIMBLE
283306
void onWrite(BLECharacteristic* pCharacteristic) override
307+
#endif // BLESERIAL_USE_NIMBLE
284308
{
285309
if (pCharacteristic != bleSerial->m_pRxCharacteristic) {
286310
return;

0 commit comments

Comments
 (0)