Skip to content
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
4 changes: 2 additions & 2 deletions examples/Bluetooth_5/NimBLE_extended_client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ bool connectToServer() {
NimBLEClient* pClient = nullptr;

pClient = NimBLEDevice::createClient();
pClient->setClientCallbacks(&clientCallbacks, false);
pClient->setCallbacks(clientCallbacks);

/**
* Set the PHY's to use for this connection. This is a bitmask that represents the PHY's:
Expand Down Expand Up @@ -107,7 +107,7 @@ extern "C" void app_main(void) {

/** Create aNimBLE Scan instance and set the callbacks for scan events */
NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setScanCallbacks(&scanCallbacks);
pScan->setCallbacks(scanCallbacks);

/** Set scan interval (how often) and window (how long) in milliseconds */
pScan->setInterval(97);
Expand Down
2 changes: 1 addition & 1 deletion examples/Bluetooth_5/NimBLE_extended_scan/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extern "C" void app_main(void) {
NimBLEScan* pScan = NimBLEDevice::getScan();

/** Set the callbacks that the scanner will call on events. */
pScan->setScanCallbacks(&scanCallbacks);
pScan->setCallbacks(scanCallbacks);

/** Use active scanning to obtain scan response data from advertisers */
pScan->setActiveScan(true);
Expand Down
4 changes: 2 additions & 2 deletions examples/Bluetooth_5/NimBLE_extended_server/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern "C" void app_main(void) {

/** Create the server and add the services/characteristics/descriptors */
NimBLEServer* pServer = NimBLEDevice::createServer();
pServer->setCallbacks(&serverCallbacks);
pServer->setCallbacks(serverCallbacks);

NimBLEService* pService = pServer->createService(SERVICE_UUID);
NimBLECharacteristic* pCharacteristic =
Expand Down Expand Up @@ -107,7 +107,7 @@ extern "C" void app_main(void) {
NimBLEExtAdvertising* pAdvertising = NimBLEDevice::getAdvertising();

/** Set the callbacks for advertising events */
pAdvertising->setCallbacks(&advertisingCallbacks);
pAdvertising->setCallbacks(advertisingCallbacks);

/**
* NimBLEExtAdvertising::setInstanceData takes the instance ID and
Expand Down
4 changes: 2 additions & 2 deletions examples/Bluetooth_5/NimBLE_multi_advertiser/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extern "C" void app_main(void) {

/** Create a server for our legacy advertiser */
NimBLEServer* pServer = NimBLEDevice::createServer();
pServer->setCallbacks(&serverCallbacks);
pServer->setCallbacks(serverCallbacks);

NimBLEService* pService = pServer->createService(SERVICE_UUID);
NimBLECharacteristic* pCharacteristic =
Expand Down Expand Up @@ -137,7 +137,7 @@ extern "C" void app_main(void) {
NimBLEExtAdvertising* pAdvertising = NimBLEDevice::getAdvertising();

/** Set the callbacks to handle advertising events */
pAdvertising->setCallbacks(&advCallbacks);
pAdvertising->setCallbacks(advCallbacks);

/**
* Set instance data.
Expand Down
2 changes: 1 addition & 1 deletion examples/Continuous_scan/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class scanCallbacks : public NimBLEScanCallbacks {
extern "C" void app_main() {
NimBLEDevice::init(""); // Initialize the device, you can specify a device name if you want.
NimBLEScan* pBLEScan = NimBLEDevice::getScan(); // Create the scan object.
pBLEScan->setScanCallbacks(&scanCallbacks, false); // Set the callback for when devices are discovered, no duplicates.
pBLEScan->setCallbacks(scanCallbacks, false); // Set the callback for when devices are discovered, no duplicates.
pBLEScan->setActiveScan(true); // Set active scanning, this will get more data from the advertiser.
pBLEScan->setMaxResults(0); // Do not store the scan results, use callback only.
pBLEScan->start(scanTime, false, true); // duration, not a continuation of last scan, restart to get all devices again.
Expand Down
12 changes: 4 additions & 8 deletions examples/L2CAP/L2CAP_Client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class MyClientCallbacks: public BLEClientCallbacks {
void onConnect(BLEClient* pClient) {
printf("GAP connected\n");
pClient->setDataLen(251);

theChannel = BLEL2CAPChannel::connect(pClient, L2CAP_PSM, L2CAP_MTU, new L2CAPChannelCallbacks());
}

Expand All @@ -59,7 +58,7 @@ class MyClientCallbacks: public BLEClientCallbacks {
vTaskDelay(1000 / portTICK_PERIOD_MS);
BLEDevice::getScan()->start(5 * 1000, true);
}
};
} myClientCallbacks;

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {

Expand All @@ -74,7 +73,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
theDevice = advertisedDevice;
}
}
};
} myAdvertisedDeviceCallbacks;

void statusTask(void *pvParameters) {
while (true) {
Expand Down Expand Up @@ -141,9 +140,7 @@ void connectTask(void *pvParameters) {
if (!theClient) {
theClient = BLEDevice::createClient();
theClient->setConnectionParams(6, 6, 0, 42);

auto callbacks = new MyClientCallbacks();
theClient->setClientCallbacks(callbacks);
theClient->setCallbacks(myClientCallbacks);

auto success = theClient->connect(theDevice);
if (!success) {
Expand Down Expand Up @@ -239,8 +236,7 @@ void app_main(void) {
BLEDevice::setMTU(BLE_ATT_MTU_MAX);

auto scan = BLEDevice::getScan();
auto callbacks = new MyAdvertisedDeviceCallbacks();
scan->setScanCallbacks(callbacks);
scan->setCallbacks(myAdvertisedDeviceCallbacks);
scan->setInterval(1349);
scan->setWindow(449);
scan->setActiveScan(true);
Expand Down
4 changes: 2 additions & 2 deletions examples/NimBLE_Async_Client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ScanCallbacks : public NimBLEScanCallbacks {
}
}

pClient->setClientCallbacks(&clientCallbacks, false);
pClient->setCallbacks(clientCallbacks);
if (!pClient->connect(true, true, false)) { // delete attributes, async connect, no MTU exchange
NimBLEDevice::deleteClient(pClient);
printf("Failed to connect\n");
Expand All @@ -60,7 +60,7 @@ extern "C" void app_main(void) {
NimBLEDevice::setPower(3); /** +3db */

NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setScanCallbacks(&scanCallbacks);
pScan->setCallbacks(scanCallbacks);
pScan->setInterval(45);
pScan->setWindow(15);
pScan->setActiveScan(true);
Expand Down
4 changes: 2 additions & 2 deletions examples/NimBLE_Client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ bool connectToServer() {

printf("New client created\n");

pClient->setClientCallbacks(&clientCallbacks, false);
pClient->setCallbacks(clientCallbacks);
/**
* Set initial connection parameters:
* These settings are safe for 3 clients to connect reliably, can go faster if you have less
Expand Down Expand Up @@ -268,7 +268,7 @@ extern "C" void app_main(void) {
NimBLEScan* pScan = NimBLEDevice::getScan();

/** Set the callbacks to call when scan events occur, no duplicates */
pScan->setScanCallbacks(&scanCallbacks, false);
pScan->setCallbacks(scanCallbacks, false);

/** Set scan interval (how often) and window (how long) in milliseconds */
pScan->setInterval(100);
Expand Down
10 changes: 5 additions & 5 deletions examples/NimBLE_Server/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ extern "C" void app_main(void) {
// NimBLEDevice::setSecurityAuth(BLE_SM_PAIR_AUTHREQ_BOND | BLE_SM_PAIR_AUTHREQ_MITM | BLE_SM_PAIR_AUTHREQ_SC);

pServer = NimBLEDevice::createServer();
pServer->setCallbacks(&serverCallbacks);
pServer->setCallbacks(serverCallbacks);

NimBLEService* pDeadService = pServer->createService("DEAD");
NimBLECharacteristic* pBeefCharacteristic =
Expand All @@ -157,7 +157,7 @@ extern "C" void app_main(void) {
);

pBeefCharacteristic->setValue("Burger");
pBeefCharacteristic->setCallbacks(&chrCallbacks);
pBeefCharacteristic->setCallbacks(chrCallbacks);

/**
* 2902 and 2904 descriptors are a special case, when createDescriptor is called with
Expand All @@ -167,22 +167,22 @@ extern "C" void app_main(void) {
*/
NimBLE2904* pBeef2904 = pBeefCharacteristic->create2904();
pBeef2904->setFormat(NimBLE2904::FORMAT_UTF8);
pBeef2904->setCallbacks(&dscCallbacks);
pBeef2904->setCallbacks(dscCallbacks);

NimBLEService* pBaadService = pServer->createService("BAAD");
NimBLECharacteristic* pFoodCharacteristic =
pBaadService->createCharacteristic("F00D", NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::NOTIFY);

pFoodCharacteristic->setValue("Fries");
pFoodCharacteristic->setCallbacks(&chrCallbacks);
pFoodCharacteristic->setCallbacks(chrCallbacks);

/** Custom descriptor: Arguments are UUID, Properties, max length of the value in bytes */
NimBLEDescriptor* pC01Ddsc =
pFoodCharacteristic->createDescriptor("C01D",
NIMBLE_PROPERTY::READ | NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_ENC,
20);
pC01Ddsc->setValue("Send it back!");
pC01Ddsc->setCallbacks(&dscCallbacks);
pC01Ddsc->setCallbacks(dscCallbacks);

/** Create an advertising instance and add the services to the advertised data */
NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
Expand Down
4 changes: 2 additions & 2 deletions examples/NimBLE_Stream_Client/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bool connectToServer() {
printf("Failed to create client\n");
return false;
}
pClient->setClientCallbacks(&clientCallbacks, false);
pClient->setCallbacks(clientCallbacks);
pClient->setConnectionParams(12, 24, 0, 200);
pClient->setConnectTimeout(5000);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ extern "C" void app_main(void) {

// Create the BLE scan instance and set callbacks.
NimBLEScan* pScan = NimBLEDevice::getScan();
pScan->setScanCallbacks(&scanCallbacks, false);
pScan->setCallbacks(scanCallbacks, false);
pScan->setActiveScan(true);

// Start scanning for the server.
Expand Down
2 changes: 1 addition & 1 deletion src/NimBLEAdvertising.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "syscfg/syscfg.h"
#if (CONFIG_BT_NIMBLE_ENABLED && MYNEWT_VAL(BLE_ROLE_BROADCASTER) && !MYNEWT_VAL(BLE_EXT_ADV)) || defined(_DOXYGEN_)

#ifdef USING_NIMBLE_ARDUINO_HEADERS
# ifdef USING_NIMBLE_ARDUINO_HEADERS
# include "nimble/nimble/host/include/host/ble_gap.h"
# else
# include "host/ble_gap.h"
Expand Down
21 changes: 12 additions & 9 deletions src/NimBLECharacteristic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,18 +438,21 @@ void NimBLECharacteristic::writeEvent(const uint8_t* val, uint16_t len, NimBLECo
} // writeEvent

/**
* @brief Set the callback handlers for this characteristic.
* @param [in] pCallbacks An instance of a NimBLECharacteristicCallbacks class\n
* used to define any callbacks for the characteristic.
* @brief Set the callbacks for this characteristic.
* @param [in] callbacks Callback handler instance.
* @details The callback handler must outlive this characteristic or until resetCallbacks() is called.
*/
void NimBLECharacteristic::setCallbacks(NimBLECharacteristicCallbacks* pCallbacks) {
if (pCallbacks != nullptr) {
m_pCallbacks = pCallbacks;
} else {
m_pCallbacks = &defaultCallback;
}
void NimBLECharacteristic::setCallbacks(NimBLECharacteristicCallbacks& callbacks) {
m_pCallbacks = &callbacks;
} // setCallbacks

/**
* @brief Restore default callback handlers.
*/
void NimBLECharacteristic::resetCallbacks() {
m_pCallbacks = &defaultCallback;
} // resetCallbacks

/**
* @brief Get the callback handlers for this characteristic.
*/
Expand Down
4 changes: 3 additions & 1 deletion src/NimBLECharacteristic.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ class NimBLECharacteristic : public NimBLELocalValueAttribute {
void addDescriptor(NimBLEDescriptor* pDescriptor);
void removeDescriptor(NimBLEDescriptor* pDescriptor, bool deleteDsc = false);
uint16_t getProperties() const;
void setCallbacks(NimBLECharacteristicCallbacks* pCallbacks);
void setCallbacks(NimBLECharacteristicCallbacks& callbacks);
void setCallbacks(NimBLECharacteristicCallbacks&&) = delete; // Block rvalues
void resetCallbacks();
bool indicate(uint16_t connHandle = BLE_HS_CONN_HANDLE_NONE) const;
bool indicate(const uint8_t* value, size_t length, uint16_t connHandle = BLE_HS_CONN_HANDLE_NONE) const;
bool notify(uint16_t connHandle = BLE_HS_CONN_HANDLE_NONE) const;
Expand Down
Loading
Loading