mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-21 20:50:55 +01:00
Refactor NimBLERemoteCharacteristic::subscribe
* Rearrange subscribe parameters to remove requirement of specifying write response to register a callback.
This commit is contained in:
parent
2af26fad1f
commit
6df7b1331a
2 changed files with 12 additions and 12 deletions
|
@ -503,12 +503,12 @@ int NimBLERemoteCharacteristic::onReadCB(uint16_t conn_handle,
|
|||
/**
|
||||
* @brief Subscribe or unsubscribe for notifications or indications.
|
||||
* @param [in] val 0x00 to unsubscribe, 0x01 for notifications, 0x02 for indications.
|
||||
* @param [in] response If write response required set this to true.
|
||||
* @param [in] notifyCallback A callback to be invoked for a notification.
|
||||
* @param [in] response If write response required set this to true.
|
||||
* If NULL is provided then no callback is performed.
|
||||
* @return true if successful.
|
||||
*/
|
||||
bool NimBLERemoteCharacteristic::setNotify(uint16_t val, bool response, notify_callback notifyCallback) {
|
||||
bool NimBLERemoteCharacteristic::setNotify(uint16_t val, notify_callback notifyCallback, bool response) {
|
||||
NIMBLE_LOGD(LOG_TAG, ">> setNotify(): %s, %02x", toString().c_str(), val);
|
||||
|
||||
NimBLERemoteDescriptor* desc = getDescriptor(NimBLEUUID((uint16_t)0x2902));
|
||||
|
@ -528,16 +528,16 @@ bool NimBLERemoteCharacteristic::setNotify(uint16_t val, bool response, notify_c
|
|||
/**
|
||||
* @brief Subscribe for notifications or indications.
|
||||
* @param [in] notifications If true, subscribe for notifications, false subscribe for indications.
|
||||
* @param [in] response If true, require a write response from the descriptor write operation.
|
||||
* @param [in] notifyCallback A callback to be invoked for a notification.
|
||||
* @param [in] response If true, require a write response from the descriptor write operation.
|
||||
* If NULL is provided then no callback is performed.
|
||||
* @return true if successful.
|
||||
*/
|
||||
bool NimBLERemoteCharacteristic::subscribe(bool notifications, bool response, notify_callback notifyCallback) {
|
||||
bool NimBLERemoteCharacteristic::subscribe(bool notifications, notify_callback notifyCallback, bool response) {
|
||||
if(notifications) {
|
||||
return setNotify(0x01, response, notifyCallback);
|
||||
return setNotify(0x01, notifyCallback, response);
|
||||
} else {
|
||||
return setNotify(0x02, response, notifyCallback);
|
||||
return setNotify(0x02, notifyCallback, response);
|
||||
}
|
||||
} // subscribe
|
||||
|
||||
|
@ -548,7 +548,7 @@ bool NimBLERemoteCharacteristic::subscribe(bool notifications, bool response, no
|
|||
* @return true if successful.
|
||||
*/
|
||||
bool NimBLERemoteCharacteristic::unsubscribe(bool response) {
|
||||
return setNotify(0x00, response);
|
||||
return setNotify(0x00, nullptr, response);
|
||||
} // unsubscribe
|
||||
|
||||
|
||||
|
@ -564,7 +564,7 @@ bool NimBLERemoteCharacteristic::unsubscribe(bool response) {
|
|||
bool NimBLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications, bool response) {
|
||||
bool success;
|
||||
if(notifyCallback != nullptr) {
|
||||
success = subscribe(notifications, response, notifyCallback);
|
||||
success = subscribe(notifications, notifyCallback, response);
|
||||
} else {
|
||||
success = unsubscribe(response);
|
||||
}
|
||||
|
|
|
@ -104,9 +104,9 @@ public:
|
|||
}
|
||||
|
||||
bool subscribe(bool notifications = true,
|
||||
bool response = true,
|
||||
notify_callback notifyCallback = nullptr);
|
||||
bool unsubscribe(bool response = true);
|
||||
notify_callback notifyCallback = nullptr,
|
||||
bool response = false);
|
||||
bool unsubscribe(bool response = false);
|
||||
bool registerForNotify(notify_callback notifyCallback,
|
||||
bool notifications = true,
|
||||
bool response = true)
|
||||
|
@ -138,7 +138,7 @@ private:
|
|||
friend class NimBLERemoteDescriptor;
|
||||
|
||||
// Private member functions
|
||||
bool setNotify(uint16_t val, bool response = true, notify_callback notifyCallback = nullptr);
|
||||
bool setNotify(uint16_t val, notify_callback notifyCallback = nullptr, bool response = true);
|
||||
bool retrieveDescriptors(const NimBLEUUID *uuid_filter = nullptr);
|
||||
static int onReadCB(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
struct ble_gatt_attr *attr, void *arg);
|
||||
|
|
Loading…
Reference in a new issue