From 58f86cb7bdb7f5beb257dde4ff3744ab245cbaaa Mon Sep 17 00:00:00 2001 From: psitto <59241379+psitto@users.noreply.github.com> Date: Thu, 29 Feb 2024 21:34:53 -0300 Subject: [PATCH 1/6] Fix inconsistent use of time units (#143) Seconds to milliseconds --- docs/Improvements_and_updates.md | 2 +- docs/Migration_guide.md | 2 +- examples/Advanced/NimBLE_Client/main/main.cpp | 6 +++--- examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp | 2 +- src/NimBLEScan.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/Improvements_and_updates.md b/docs/Improvements_and_updates.md index 220ed5c..a7504d5 100644 --- a/docs/Improvements_and_updates.md +++ b/docs/Improvements_and_updates.md @@ -66,7 +66,7 @@ If false the service is only removed from visibility by clients. The pointers to # Advertising `NimBLEAdvertising::start` -Now takes 2 optional parameters, the first is the duration to advertise for (in seconds), the second is a callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API). +Now takes 2 optional parameters, the first is the duration to advertise for (in milliseconds), the second is a callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API). This provides an opportunity to update the advertisement data if desired. diff --git a/docs/Migration_guide.md b/docs/Migration_guide.md index d6362e2..b655190 100644 --- a/docs/Migration_guide.md +++ b/docs/Migration_guide.md @@ -255,7 +255,7 @@ Calling `NimBLEAdvertising::setAdvertisementData` will entirely replace any data > BLEAdvertising::start (NimBLEAdvertising::start) -Now takes 2 optional parameters, the first is the duration to advertise for (in seconds), the second is a callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API). +Now takes 2 optional parameters, the first is the duration to advertise for (in milliseconds), the second is a callback that is invoked when advertising ends and takes a pointer to a `NimBLEAdvertising` object (similar to the `NimBLEScan::start` API). This provides an opportunity to update the advertisement data if desired.
diff --git a/examples/Advanced/NimBLE_Client/main/main.cpp b/examples/Advanced/NimBLE_Client/main/main.cpp index e30bd64..aab186c 100644 --- a/examples/Advanced/NimBLE_Client/main/main.cpp +++ b/examples/Advanced/NimBLE_Client/main/main.cpp @@ -146,8 +146,8 @@ bool connectToServer() { * Min interval: 12 * 1.25ms = 15, Max interval: 12 * 1.25ms = 15, 0 latency, 12 * 10ms = 120ms timeout */ pClient->setConnectionParams(6,6,0,15); - /** Set how long we are willing to wait for the connection to complete (seconds), default is 30. */ - pClient->setConnectTimeout(5); + /** Set how long we are willing to wait for the connection to complete (milliseconds), default is 30000. */ + pClient->setConnectTimeout(5 * 1000); if (!pClient->connect(advDevice)) { @@ -358,7 +358,7 @@ void app_main (void){ * but will use more energy from both devices */ pScan->setActiveScan(true); - /** Start scanning for advertisers for the scan time specified (in seconds) 0 = forever + /** Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever * Optional callback for when scanning stops. */ pScan->start(scanTime); diff --git a/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp b/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp index c9013d9..3572e59 100644 --- a/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp +++ b/examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp @@ -154,7 +154,7 @@ void app_main (void) { */ pScan->setActiveScan(true); - /* Start scanning for advertisers for the scan time specified (in seconds) 0 = forever + /* Start scanning for advertisers for the scan time specified (in milliseconds) 0 = forever * Optional callback for when scanning stops. */ pScan->start(scanTime); diff --git a/src/NimBLEScan.cpp b/src/NimBLEScan.cpp index c7ee07a..72130fe 100644 --- a/src/NimBLEScan.cpp +++ b/src/NimBLEScan.cpp @@ -459,7 +459,7 @@ void NimBLEScan::onHostSync() { /** * @brief Start scanning and block until scanning has been completed. - * @param [in] duration The duration in seconds for which to scan. + * @param [in] duration The duration in milliseconds for which to scan. * @param [in] is_continue Set to true to save previous scan results, false to clear them. * @return The scan results. */ From bf4b5d4ffa8ecfc0a20356ed12b3588847bb8632 Mon Sep 17 00:00:00 2001 From: kiss81 <61309045+kiss81@users.noreply.github.com> Date: Fri, 1 Mar 2024 20:29:18 +0100 Subject: [PATCH 2/6] ESP IDF 5.2 include fix (#144) --- src/NimBLEAttValue.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/NimBLEAttValue.h b/src/NimBLEAttValue.h index be346d5..786bc8b 100644 --- a/src/NimBLEAttValue.h +++ b/src/NimBLEAttValue.h @@ -24,6 +24,7 @@ #include #include +#include #ifndef CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED # define CONFIG_NIMBLE_CPP_ATT_VALUE_TIMESTAMP_ENABLED 0 From 226c67f729b049498e95eb68cc97673f4a214de2 Mon Sep 17 00:00:00 2001 From: Sebastian Holder Date: Sat, 20 Apr 2024 17:14:55 +0200 Subject: [PATCH 3/6] Initialize ble_gatt_chr_def[]. Fixes #148 (#150) IDF 5.2 introduced a new member, cpfd, to the ble_gatt_chr_def struct. It needs to be initialized to nullptr in order to avoid accessing uninitialized memory. By initializing the whole struct, we get everything initialized in a backward-compatible way. --- src/NimBLEService.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NimBLEService.cpp b/src/NimBLEService.cpp index 6c4780c..02195ac 100644 --- a/src/NimBLEService.cpp +++ b/src/NimBLEService.cpp @@ -159,7 +159,7 @@ bool NimBLEService::start() { // Nimble requires the last characteristic to have it's uuid = 0 to indicate the end // of the characteristics for the service. We create 1 extra and set it to null // for this purpose. - pChr_a = new ble_gatt_chr_def[numChrs + 1]; + pChr_a = new ble_gatt_chr_def[numChrs + 1]{}; int i = 0; for(auto chr_it = m_chrVec.begin(); chr_it != m_chrVec.end(); ++chr_it) { if((*chr_it)->m_removed > 0) { From 6fa3783206db27cef7c2797571ce8e46f6e1617c Mon Sep 17 00:00:00 2001 From: afpineda <74291754+afpineda@users.noreply.github.com> Date: Sat, 25 Mar 2023 12:49:37 +0100 Subject: [PATCH 4/6] Bug fix on PNP info Fixed issue #492 --- src/NimBLEHIDDevice.cpp | 23 ++++++++++++++++++++--- src/NimBLEHIDDevice.h | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/NimBLEHIDDevice.cpp b/src/NimBLEHIDDevice.cpp index a2310eb..de81fb2 100644 --- a/src/NimBLEHIDDevice.cpp +++ b/src/NimBLEHIDDevice.cpp @@ -35,6 +35,12 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) { */ m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a50, NIMBLE_PROPERTY::READ); + /* + * Non-mandatory characteristics for device info service + * Will be created on demand + */ + m_manufacturerCharacteristic = nullptr; + /* * Mandatory characteristics for HID service */ @@ -86,7 +92,10 @@ void NimBLEHIDDevice::startServices() { * @brief Create a manufacturer characteristic (this characteristic is optional). */ NimBLECharacteristic* NimBLEHIDDevice::manufacturer() { - m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a29, NIMBLE_PROPERTY::READ); + if (m_manufacturerCharacteristic == nullptr) { + m_manufacturerCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a29, NIMBLE_PROPERTY::READ); + } + return m_manufacturerCharacteristic; } @@ -95,7 +104,7 @@ NimBLECharacteristic* NimBLEHIDDevice::manufacturer() { * @param [in] name The manufacturer name of this HID device. */ void NimBLEHIDDevice::manufacturer(std::string name) { - m_manufacturerCharacteristic->setValue(name); + manufacturer()->setValue(name); } /** @@ -106,7 +115,15 @@ void NimBLEHIDDevice::manufacturer(std::string name) { * @param [in] version The produce version number. */ void NimBLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version) { - uint8_t pnp[] = { sig, (uint8_t) (vid >> 8), (uint8_t) vid, (uint8_t) (pid >> 8), (uint8_t) pid, (uint8_t) (version >> 8), (uint8_t) version }; + uint8_t pnp[] = { + sig, + ((uint8_t *)&vid)[0], + ((uint8_t *)&vid)[1], + ((uint8_t *)&pid)[0], + ((uint8_t *)&pid)[1], + ((uint8_t *)&version)[0], + ((uint8_t *)&version)[1] + }; m_pnpCharacteristic->setValue(pnp, sizeof(pnp)); } diff --git a/src/NimBLEHIDDevice.h b/src/NimBLEHIDDevice.h index 0e8b282..6461a4f 100644 --- a/src/NimBLEHIDDevice.h +++ b/src/NimBLEHIDDevice.h @@ -33,6 +33,7 @@ #define HID_DIGITAL_PEN 0x03C7 #define HID_BARCODE 0x03C8 +#define PNPVersionField(MajorVersion, MinorVersion, PatchVersion) ((MajorVersion << 16) & 0xFF00) | ((MinorVersion << 8) & 0x00F0) | (PatchVersion & 0x000F) /** * @brief A model of a %BLE Human Interface Device. From 7c0300c34ef868a6fb6813949e5e8f4cd5cfa69e Mon Sep 17 00:00:00 2001 From: h2zero Date: Sun, 2 Jun 2024 16:40:32 -0600 Subject: [PATCH 5/6] Change NimBLEHIDDevice formatting for consistency. --- src/NimBLEHIDDevice.cpp | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/NimBLEHIDDevice.cpp b/src/NimBLEHIDDevice.cpp index de81fb2..12c14de 100644 --- a/src/NimBLEHIDDevice.cpp +++ b/src/NimBLEHIDDevice.cpp @@ -26,14 +26,14 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) { /* * Here we create mandatory services described in bluetooth specification */ - m_deviceInfoService = server->createService(NimBLEUUID((uint16_t) 0x180a)); - m_hidService = server->createService(NimBLEUUID((uint16_t) 0x1812)); - m_batteryService = server->createService(NimBLEUUID((uint16_t) 0x180f)); + m_deviceInfoService = server->createService(NimBLEUUID((uint16_t)0x180a)); + m_hidService = server->createService(NimBLEUUID((uint16_t)0x1812)); + m_batteryService = server->createService(NimBLEUUID((uint16_t)0x180f)); /* * Mandatory characteristic for device info service */ - m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t) 0x2a50, NIMBLE_PROPERTY::READ); + m_pnpCharacteristic = m_deviceInfoService->createCharacteristic((uint16_t)0x2a50, NIMBLE_PROPERTY::READ); /* * Non-mandatory characteristics for device info service @@ -44,16 +44,16 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) { /* * Mandatory characteristics for HID service */ - m_hidInfoCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4a, NIMBLE_PROPERTY::READ); - m_reportMapCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4b, NIMBLE_PROPERTY::READ); - m_hidControlCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4c, NIMBLE_PROPERTY::WRITE_NR); - m_protocolModeCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4e, NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::READ); + m_hidInfoCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4a, NIMBLE_PROPERTY::READ); + m_reportMapCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4b, NIMBLE_PROPERTY::READ); + m_hidControlCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4c, NIMBLE_PROPERTY::WRITE_NR); + m_protocolModeCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4e, NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::READ); /* * Mandatory battery level characteristic with notification and presence descriptor */ - m_batteryLevelCharacteristic = m_batteryService->createCharacteristic((uint16_t) 0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); - NimBLE2904* batteryLevelDescriptor = (NimBLE2904*)m_batteryLevelCharacteristic->createDescriptor((uint16_t) 0x2904); + m_batteryLevelCharacteristic = m_batteryService->createCharacteristic((uint16_t)0x2a19, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY); + NimBLE2904 *batteryLevelDescriptor = (NimBLE2904*)m_batteryLevelCharacteristic->createDescriptor((uint16_t)0x2904); batteryLevelDescriptor->setFormat(NimBLE2904::FORMAT_UINT8); batteryLevelDescriptor->setNamespace(1); batteryLevelDescriptor->setUnit(0x27ad); @@ -62,8 +62,8 @@ NimBLEHIDDevice::NimBLEHIDDevice(NimBLEServer* server) { * This value is setup here because its default value in most usage cases, its very rare to use boot mode * and we want to simplify library using as much as possible */ - const uint8_t pMode[] = { 0x01 }; - protocolMode()->setValue((uint8_t*) pMode, 1); + const uint8_t pMode[] = {0x01}; + protocolMode()->setValue((uint8_t*)pMode, 1); } NimBLEHIDDevice::~NimBLEHIDDevice() { @@ -117,12 +117,12 @@ void NimBLEHIDDevice::manufacturer(std::string name) { void NimBLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t version) { uint8_t pnp[] = { sig, - ((uint8_t *)&vid)[0], - ((uint8_t *)&vid)[1], - ((uint8_t *)&pid)[0], - ((uint8_t *)&pid)[1], - ((uint8_t *)&version)[0], - ((uint8_t *)&version)[1] + ((uint8_t*)&vid)[0], + ((uint8_t*)&vid)[1], + ((uint8_t*)&pid)[0], + ((uint8_t*)&pid)[1], + ((uint8_t*)&version)[0], + ((uint8_t*)&version)[1] }; m_pnpCharacteristic->setValue(pnp, sizeof(pnp)); } @@ -133,7 +133,7 @@ void NimBLEHIDDevice::pnp(uint8_t sig, uint16_t vid, uint16_t pid, uint16_t vers * @param [in] flags The HID Class Specification release number to use. */ void NimBLEHIDDevice::hidInfo(uint8_t country, uint8_t flags) { - uint8_t info[] = { 0x11, 0x1, country, flags }; + uint8_t info[] = {0x11, 0x1, country, flags}; m_hidInfoCharacteristic->setValue(info, sizeof(info)); } @@ -143,11 +143,11 @@ void NimBLEHIDDevice::hidInfo(uint8_t country, uint8_t flags) { * @return pointer to new input report characteristic */ NimBLECharacteristic* NimBLEHIDDevice::inputReport(uint8_t reportID) { - NimBLECharacteristic* inputReportCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4d, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::READ_ENC); - NimBLEDescriptor* inputReportDescriptor = inputReportCharacteristic->createDescriptor((uint16_t) 0x2908, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC); + NimBLECharacteristic *inputReportCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4d, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::NOTIFY | NIMBLE_PROPERTY::READ_ENC); + NimBLEDescriptor *inputReportDescriptor = inputReportCharacteristic->createDescriptor((uint16_t)0x2908, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::READ_ENC); - uint8_t desc1_val[] = { reportID, 0x01 }; - inputReportDescriptor->setValue((uint8_t*) desc1_val, 2); + uint8_t desc1_val[] = {reportID, 0x01}; + inputReportDescriptor->setValue((uint8_t*)desc1_val, 2); return inputReportCharacteristic; } @@ -158,11 +158,11 @@ NimBLECharacteristic* NimBLEHIDDevice::inputReport(uint8_t reportID) { * @return Pointer to new output report characteristic */ NimBLECharacteristic* NimBLEHIDDevice::outputReport(uint8_t reportID) { - NimBLECharacteristic* outputReportCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4d, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); - NimBLEDescriptor* outputReportDescriptor = outputReportCharacteristic->createDescriptor((uint16_t) 0x2908, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); + NimBLECharacteristic *outputReportCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4d, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); + NimBLEDescriptor *outputReportDescriptor = outputReportCharacteristic->createDescriptor((uint16_t)0x2908, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); - uint8_t desc1_val[] = { reportID, 0x02 }; - outputReportDescriptor->setValue((uint8_t*) desc1_val, 2); + uint8_t desc1_val[] = {reportID, 0x02}; + outputReportDescriptor->setValue((uint8_t*)desc1_val, 2); return outputReportCharacteristic; } @@ -173,11 +173,11 @@ NimBLECharacteristic* NimBLEHIDDevice::outputReport(uint8_t reportID) { * @return Pointer to new feature report characteristic */ NimBLECharacteristic* NimBLEHIDDevice::featureReport(uint8_t reportID) { - NimBLECharacteristic* featureReportCharacteristic = m_hidService->createCharacteristic((uint16_t) 0x2a4d, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); - NimBLEDescriptor* featureReportDescriptor = featureReportCharacteristic->createDescriptor((uint16_t) 0x2908, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); + NimBLECharacteristic *featureReportCharacteristic = m_hidService->createCharacteristic((uint16_t)0x2a4d, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); + NimBLEDescriptor *featureReportDescriptor = featureReportCharacteristic->createDescriptor((uint16_t)0x2908, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::READ_ENC | NIMBLE_PROPERTY::WRITE_ENC); - uint8_t desc1_val[] = { reportID, 0x03 }; - featureReportDescriptor->setValue((uint8_t*) desc1_val, 2); + uint8_t desc1_val[] = {reportID, 0x03}; + featureReportDescriptor->setValue((uint8_t*)desc1_val, 2); return featureReportCharacteristic; } @@ -186,14 +186,14 @@ NimBLECharacteristic* NimBLEHIDDevice::featureReport(uint8_t reportID) { * @brief Creates a keyboard boot input report characteristic */ NimBLECharacteristic* NimBLEHIDDevice::bootInput() { - return m_hidService->createCharacteristic((uint16_t) 0x2a22, NIMBLE_PROPERTY::NOTIFY); + return m_hidService->createCharacteristic((uint16_t)0x2a22, NIMBLE_PROPERTY::NOTIFY); } /** * @brief Create a keyboard boot output report characteristic */ NimBLECharacteristic* NimBLEHIDDevice::bootOutput() { - return m_hidService->createCharacteristic((uint16_t) 0x2a32, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR); + return m_hidService->createCharacteristic((uint16_t)0x2a32, NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_NR); } /** From 51bf1f3c7cf4afa3eb7169e0932dbc2a688862fb Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Tue, 4 Jun 2024 08:12:20 -0500 Subject: [PATCH 6/6] feat(NimBLEAdvertising): support std::function for advertising complete callback (#157) Updates the interface to use a typedef'd std::function for the advertise callback, which is backwards compatible but also allows std::bind and lambda functions. --- src/NimBLEAdvertising.cpp | 2 +- src/NimBLEAdvertising.h | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/NimBLEAdvertising.cpp b/src/NimBLEAdvertising.cpp index 50a9e89..3d752a6 100644 --- a/src/NimBLEAdvertising.cpp +++ b/src/NimBLEAdvertising.cpp @@ -402,7 +402,7 @@ void NimBLEAdvertising::setScanResponseData(NimBLEAdvertisementData& advertiseme * @param [in] dirAddr The address of a peer to directly advertise to. * @return True if advertising started successfully. */ -bool NimBLEAdvertising::start(uint32_t duration, void (*advCompleteCB)(NimBLEAdvertising *pAdv), NimBLEAddress* dirAddr) { +bool NimBLEAdvertising::start(uint32_t duration, advCompleteCB_t advCompleteCB, NimBLEAddress* dirAddr) { NIMBLE_LOGD(LOG_TAG, ">> Advertising start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData); diff --git a/src/NimBLEAdvertising.h b/src/NimBLEAdvertising.h index 14c3466..fe3af77 100644 --- a/src/NimBLEAdvertising.h +++ b/src/NimBLEAdvertising.h @@ -33,6 +33,7 @@ #include "NimBLEUUID.h" #include "NimBLEAddress.h" +#include #include /* COMPATIBILITY - DO NOT USE */ @@ -44,6 +45,9 @@ #define ESP_BLE_ADV_FLAG_NON_LIMIT_DISC (0x00 ) /* ************************* */ +class NimBLEAdvertising; + +typedef std::function advCompleteCB_t; /** * @brief Advertisement data set by the programmer to be published by the %BLE server. @@ -92,7 +96,7 @@ public: void addServiceUUID(const NimBLEUUID &serviceUUID); void addServiceUUID(const char* serviceUUID); void removeServiceUUID(const NimBLEUUID &serviceUUID); - bool start(uint32_t duration = 0, void (*advCompleteCB)(NimBLEAdvertising *pAdv) = nullptr, NimBLEAddress* dirAddr = nullptr); + bool start(uint32_t duration = 0, advCompleteCB_t advCompleteCB = nullptr, NimBLEAddress* dirAddr = nullptr); bool stop(); void setAppearance(uint16_t appearance); void setName(const std::string &name); @@ -129,7 +133,7 @@ private: bool m_customScanResponseData; bool m_scanResp; bool m_advDataSet; - void (*m_advCompCB)(NimBLEAdvertising *pAdv); + advCompleteCB_t m_advCompCB{nullptr}; uint8_t m_slaveItvl[4]; uint32_t m_duration; std::vector m_svcData16;