From 96038864f454793b2c7f135dbd1885aa60eba765 Mon Sep 17 00:00:00 2001 From: Kevin Dewald Date: Sun, 28 Jul 2024 23:16:02 -0700 Subject: [PATCH] Updated readme. Added handle for notify and indicate. --- docs/changelog.rst | 3 ++- simpleble/include/simpleble_c/peripheral.h | 4 ++-- simpleble/src/backends/linux/AdapterBase.cpp | 3 +++ simpleble/src_c/peripheral.cpp | 8 ++++---- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 90ff7222..87265017 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -15,7 +15,8 @@ The format is based on `Keep a Changelog`_, and this project adheres to `Semanti **Changed** -- +- Implemented standalone ByteArray class derived from `kvn::bytearray`. *(Thanks tlifschitz!)* +- **API CHANGE**: Notify and Indicate callback in C bindings now receive the peripheral handle as the first argument. **Fixed** diff --git a/simpleble/include/simpleble_c/peripheral.h b/simpleble/include/simpleble_c/peripheral.h index 2209ead5..0b4859f7 100644 --- a/simpleble/include/simpleble_c/peripheral.h +++ b/simpleble/include/simpleble_c/peripheral.h @@ -214,7 +214,7 @@ SIMPLEBLE_EXPORT simpleble_err_t simpleble_peripheral_write_command(simpleble_pe */ SIMPLEBLE_EXPORT simpleble_err_t simpleble_peripheral_notify(simpleble_peripheral_t handle, simpleble_uuid_t service, simpleble_uuid_t characteristic, - void (*callback)(simpleble_uuid_t service, simpleble_uuid_t characteristic, + void (*callback)(simpleble_peripheral_t handle, simpleble_uuid_t service, simpleble_uuid_t characteristic, const uint8_t* data, size_t data_length, void* userdata), void* userdata); @@ -229,7 +229,7 @@ simpleble_peripheral_notify(simpleble_peripheral_t handle, simpleble_uuid_t serv */ SIMPLEBLE_EXPORT simpleble_err_t simpleble_peripheral_indicate(simpleble_peripheral_t handle, simpleble_uuid_t service, simpleble_uuid_t characteristic, - void (*callback)(simpleble_uuid_t service, simpleble_uuid_t characteristic, + void (*callback)(simpleble_peripheral_t handle, simpleble_uuid_t service, simpleble_uuid_t characteristic, const uint8_t* data, size_t data_length, void* userdata), void* userdata); diff --git a/simpleble/src/backends/linux/AdapterBase.cpp b/simpleble/src/backends/linux/AdapterBase.cpp index 3b9bf32a..cba3035b 100644 --- a/simpleble/src/backends/linux/AdapterBase.cpp +++ b/simpleble/src/backends/linux/AdapterBase.cpp @@ -71,6 +71,9 @@ void AdapterBase::scan_start() { // Start scanning and notify the user. adapter_->discovery_start(); + + // TODO: Does a discovery filter need to be set? + SAFE_CALLBACK_CALL(this->callback_on_scan_start_); is_scanning_ = true; } diff --git a/simpleble/src_c/peripheral.cpp b/simpleble/src_c/peripheral.cpp index 8c42956b..4995f3ba 100644 --- a/simpleble/src_c/peripheral.cpp +++ b/simpleble/src_c/peripheral.cpp @@ -318,7 +318,7 @@ simpleble_err_t simpleble_peripheral_write_command(simpleble_peripheral_t handle simpleble_err_t simpleble_peripheral_notify( simpleble_peripheral_t handle, simpleble_uuid_t service, simpleble_uuid_t characteristic, - void (*callback)(simpleble_uuid_t, simpleble_uuid_t, const uint8_t*, size_t, void*), void* userdata) { + void (*callback)(simpleble_peripheral_t,simpleble_uuid_t, simpleble_uuid_t, const uint8_t*, size_t, void*), void* userdata) { if (handle == nullptr || callback == nullptr) { return SIMPLEBLE_FAILURE; } @@ -327,7 +327,7 @@ simpleble_err_t simpleble_peripheral_notify( bool success = peripheral->notify(SimpleBLE::BluetoothUUID(service.value), SimpleBLE::BluetoothUUID(characteristic.value), [=](SimpleBLE::ByteArray data) { - callback(service, characteristic, (const uint8_t*)data.data(), data.size(), + callback(handle, service, characteristic, (const uint8_t*)data.data(), data.size(), userdata); }); @@ -336,7 +336,7 @@ simpleble_err_t simpleble_peripheral_notify( simpleble_err_t simpleble_peripheral_indicate( simpleble_peripheral_t handle, simpleble_uuid_t service, simpleble_uuid_t characteristic, - void (*callback)(simpleble_uuid_t, simpleble_uuid_t, const uint8_t*, size_t, void*), void* userdata) { + void (*callback)(simpleble_peripheral_t,simpleble_uuid_t, simpleble_uuid_t, const uint8_t*, size_t, void*), void* userdata) { if (handle == nullptr || callback == nullptr) { return SIMPLEBLE_FAILURE; } @@ -345,7 +345,7 @@ simpleble_err_t simpleble_peripheral_indicate( bool success = peripheral->indicate(SimpleBLE::BluetoothUUID(service.value), SimpleBLE::BluetoothUUID(characteristic.value), [=](SimpleBLE::ByteArray data) { - callback(service, characteristic, (const uint8_t*)data.data(), data.size(), + callback(handle, service, characteristic, (const uint8_t*)data.data(), data.size(), userdata); });