Skip to content

Commit 434d02c

Browse files
BLERemoteCharacteristic::registerForNotify: Permit event registration without updating descriptor. (#4659)
1 parent 15db297 commit 434d02c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: libraries/BLE/src/BLERemoteCharacteristic.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ std::string BLERemoteCharacteristic::readValue() {
453453
* unregistering a notification.
454454
* @return N/A.
455455
*/
456-
void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications) {
456+
void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications, bool descriptorRequiresRegistration) {
457457
log_v(">> registerForNotify(): %s", toString().c_str());
458458

459459
m_notifyCallback = notifyCallback; // Save the notification callback.
@@ -474,7 +474,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
474474
uint8_t val[] = {0x01, 0x00};
475475
if(!notifications) val[0] = 0x02;
476476
BLERemoteDescriptor* desc = getDescriptor(BLEUUID((uint16_t)0x2902));
477-
if (desc != nullptr)
477+
if (desc != nullptr && descriptorRequiresRegistration)
478478
desc->writeValue(val, 2, true);
479479
} // End Register
480480
else { // If we weren't passed a callback function, then this is an unregistration.
@@ -490,7 +490,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
490490

491491
uint8_t val[] = {0x00, 0x00};
492492
BLERemoteDescriptor* desc = getDescriptor((uint16_t)0x2902);
493-
if (desc != nullptr)
493+
if (desc != nullptr && descriptorRequiresRegistration)
494494
desc->writeValue(val, 2, true);
495495
} // End Unregister
496496

Diff for: libraries/BLE/src/BLERemoteCharacteristic.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BLERemoteCharacteristic {
4646
uint16_t readUInt16();
4747
uint32_t readUInt32();
4848
float readFloat();
49-
void registerForNotify(notify_callback _callback, bool notifications = true);
49+
void registerForNotify(notify_callback _callback, bool notifications = true, bool descriptorRequiresRegistration = true);
5050
void writeValue(uint8_t* data, size_t length, bool response = false);
5151
void writeValue(std::string newValue, bool response = false);
5252
void writeValue(uint8_t newValue, bool response = false);

0 commit comments

Comments
 (0)