mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
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.
This commit is contained in:
parent
7c0300c34e
commit
51bf1f3c7c
2 changed files with 7 additions and 3 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "NimBLEUUID.h"
|
||||
#include "NimBLEAddress.h"
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
/* COMPATIBILITY - DO NOT USE */
|
||||
|
@ -44,6 +45,9 @@
|
|||
#define ESP_BLE_ADV_FLAG_NON_LIMIT_DISC (0x00 )
|
||||
/* ************************* */
|
||||
|
||||
class NimBLEAdvertising;
|
||||
|
||||
typedef std::function<void(NimBLEAdvertising*)> 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<uint8_t> m_svcData16;
|
||||
|
|
Loading…
Reference in a new issue