Skip to content

[2.0.0] Add BLE characteristic callbacks overloads #4832

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 15, 2021
Merged
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
49 changes: 20 additions & 29 deletions libraries/BLE/src/BLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ void BLECharacteristic::handleGATTServerEvent(
m_writeEvt = false;
if (param->exec_write.exec_write_flag == ESP_GATT_PREP_WRITE_EXEC) {
m_value.commit();
m_pCallbacks->onWrite(this); // Invoke the onWrite callback handler.
// Invoke the onWrite callback handler.
m_pCallbacks->onWrite(this, param);
} else {
m_value.cancel();
}
Expand Down Expand Up @@ -311,7 +312,8 @@ void BLECharacteristic::handleGATTServerEvent(
} // Response needed

if (param->write.is_prep != true) {
m_pCallbacks->onWrite(this); // Invoke the onWrite callback handler.
// Invoke the onWrite callback handler.
m_pCallbacks->onWrite(this, param);
}
} // Match on handles.
break;
Expand Down Expand Up @@ -383,7 +385,7 @@ void BLECharacteristic::handleGATTServerEvent(

// If is.long is false then this is the first (or only) request to read data, so invoke the callback
// Invoke the read callback.
m_pCallbacks->onRead(this);
m_pCallbacks->onRead(this, param);

std::string value = m_value.getValue();

Expand Down Expand Up @@ -757,46 +759,35 @@ std::string BLECharacteristic::toString() {

BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {}

void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param) {
onRead(pCharacteristic);
} // onRead

/**
* @brief Callback function to support a read request.
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic) {
log_d("BLECharacteristicCallbacks", ">> onRead: default");
log_d("BLECharacteristicCallbacks", "<< onRead");
log_d(">> onRead: default");
log_d("<< onRead");
} // onRead


/**
* @brief Callback function to support a write request.
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
void BLECharacteristicCallbacks::onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param) {
onWrite(pCharacteristic);
} // onWrite

void BLECharacteristicCallbacks::onWrite(BLECharacteristic* pCharacteristic) {
log_d("BLECharacteristicCallbacks", ">> onWrite: default");
log_d("BLECharacteristicCallbacks", "<< onWrite");
log_d(">> onWrite: default");
log_d("<< onWrite");
} // onWrite


/**
* @brief Callback function to support a Notify request.
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
void BLECharacteristicCallbacks::onNotify(BLECharacteristic* pCharacteristic) {
log_d("BLECharacteristicCallbacks", ">> onNotify: default");
log_d("BLECharacteristicCallbacks", "<< onNotify");
log_d(">> onNotify: default");
log_d("<< onNotify");
} // onNotify


/**
* @brief Callback function to support a Notify/Indicate Status report.
* @param [in] pCharacteristic The characteristic that is the source of the event.
* @param [in] s Status of the notification/indication
* @param [in] code Additional code of underlying errors
*/
void BLECharacteristicCallbacks::onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code) {
log_d("BLECharacteristicCallbacks", ">> onStatus: default");
log_d("BLECharacteristicCallbacks", "<< onStatus");
log_d(">> onStatus: default");
log_d("<< onStatus");
} // onStatus


Expand Down
34 changes: 34 additions & 0 deletions libraries/BLE/src/BLECharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,43 @@ class BLECharacteristicCallbacks {
}Status;

virtual ~BLECharacteristicCallbacks();

/**
* @brief Callback function to support a read request.
* @param [in] pCharacteristic The characteristic that is the source of the event.
* @param [in] param The BLE GATTS param. Use param->read.
*/
virtual void onRead(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param);
/**
* @brief DEPRECATED! Callback function to support a read request. Called only if onRead(,) not overrided.
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
virtual void onRead(BLECharacteristic* pCharacteristic);

/**
* @brief Callback function to support a write request.
* @param [in] pCharacteristic The characteristic that is the source of the event.
* @param [in] param The BLE GATTS param. Use param->write.
*/
virtual void onWrite(BLECharacteristic* pCharacteristic, esp_ble_gatts_cb_param_t* param);
/**
* @brief DEPRECATED! Callback function to support a write request. Called only if onWrite(,) not overrided.
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
virtual void onWrite(BLECharacteristic* pCharacteristic);

/**
* @brief Callback function to support a Notify request.
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
virtual void onNotify(BLECharacteristic* pCharacteristic);

/**
* @brief Callback function to support a Notify/Indicate Status report.
* @param [in] pCharacteristic The characteristic that is the source of the event.
* @param [in] s Status of the notification/indication
* @param [in] code Additional code of underlying errors
*/
virtual void onStatus(BLECharacteristic* pCharacteristic, Status s, uint32_t code);
};
#endif /* CONFIG_BLUEDROID_ENABLED */
Expand Down