Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/BLERemoteCharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
m_charProp = charProp;
m_pRemoteService = pRemoteService;
m_notifyCallback = nullptr;
m_notifyContext = nullptr;

retrieveDescriptors(); // Get the descriptors for this characteristic
ESP_LOGD(LOG_TAG, "<< BLERemoteCharacteristic");
Expand Down Expand Up @@ -175,7 +176,8 @@ void BLERemoteCharacteristic::gattClientEventHandler(
this,
evtParam->notify.value,
evtParam->notify.value_len,
evtParam->notify.is_notify
evtParam->notify.is_notify,
m_notifyContext
);
} // End we have a callback function ...
break;
Expand Down Expand Up @@ -468,10 +470,13 @@ void BLERemoteCharacteristic::registerForNotify(
BLERemoteCharacteristic* pBLERemoteCharacteristic,
uint8_t* pData,
size_t length,
bool isNotify)) {
bool isNotify,
void* notifyContext),
void* notifyContext) {
ESP_LOGD(LOG_TAG, ">> registerForNotify(): %s", toString().c_str());

m_notifyCallback = notifyCallback; // Save the notification callback.
m_notifyContext = notifyContext;

m_semaphoreRegForNotifyEvt.take("registerForNotify");

Expand Down
5 changes: 3 additions & 2 deletions src/BLERemoteCharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class BLERemoteCharacteristic {
uint8_t readUInt8(void);
uint16_t readUInt16(void);
uint32_t readUInt32(void);
void registerForNotify(void (*notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify));
void registerForNotify(void (*notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify, void* notifyContext), void* notifyContext = nullptr);
void writeValue(uint8_t* data, size_t length, bool response = false);
void writeValue(std::string newValue, bool response = false);
void writeValue(uint8_t newValue, bool response = false);
Expand Down Expand Up @@ -76,7 +76,8 @@ class BLERemoteCharacteristic {
FreeRTOS::Semaphore m_semaphoreRegForNotifyEvt = FreeRTOS::Semaphore("RegForNotifyEvt");
FreeRTOS::Semaphore m_semaphoreWriteCharEvt = FreeRTOS::Semaphore("WriteCharEvt");
std::string m_value;
void (*m_notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify);
void (*m_notifyCallback)(BLERemoteCharacteristic* pBLERemoteCharacteristic, uint8_t* pData, size_t length, bool isNotify, void* notifyContext);
void *m_notifyContext;

// We maintain a map of descriptors owned by this characteristic keyed by a string representation of the UUID.
std::map<std::string, BLERemoteDescriptor*> m_descriptorMap;
Expand Down