From 796b54facbf54b72cf43542a29ef88d52c95cd6e Mon Sep 17 00:00:00 2001 From: Simon Remberg Date: Wed, 3 Jan 2018 15:45:31 +0100 Subject: [PATCH] context added to BLERemoteCharacteristics notify function --- src/BLERemoteCharacteristic.cpp | 9 +++++++-- src/BLERemoteCharacteristic.h | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/BLERemoteCharacteristic.cpp b/src/BLERemoteCharacteristic.cpp index 64b0a92..6ac519e 100644 --- a/src/BLERemoteCharacteristic.cpp +++ b/src/BLERemoteCharacteristic.cpp @@ -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"); @@ -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; @@ -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"); diff --git a/src/BLERemoteCharacteristic.h b/src/BLERemoteCharacteristic.h index 6f23f49..0f21f45 100644 --- a/src/BLERemoteCharacteristic.h +++ b/src/BLERemoteCharacteristic.h @@ -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); @@ -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 m_descriptorMap;