diff options
author | Jean-François Milants <jf@codingfield.com> | 2021-10-17 08:23:01 +0200 |
---|---|---|
committer | Jean-François Milants <jf@codingfield.com> | 2021-10-17 08:23:01 +0200 |
commit | d1f50157c7e0c471ae0e260fdca82fc472635079 (patch) | |
tree | 5ff50524ec689b5472d04405fd54a983161ff04d /src/components/ble/HeartRateService.cpp | |
parent | bf83493c8db1ef8afab34a10d0253c0208304484 (diff) |
MotionService : fix typo and characteristic array size + send notification only if the host subscribed to them.
Diffstat (limited to 'src/components/ble/HeartRateService.cpp')
-rw-r--r-- | src/components/ble/HeartRateService.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp index 5b00f492..75a038a2 100644 --- a/src/components/ble/HeartRateService.cpp +++ b/src/components/ble/HeartRateService.cpp @@ -8,7 +8,7 @@ constexpr ble_uuid16_t HeartRateService::heartRateServiceUuid; constexpr ble_uuid16_t HeartRateService::heartRateMeasurementUuid; namespace { - int HeartRateServiceServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { + int HeartRateServiceCallback(uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt* ctxt, void* arg) { auto* heartRateService = static_cast<HeartRateService*>(arg); return heartRateService->OnHeartRateRequested(conn_handle, attr_handle, ctxt); } @@ -19,7 +19,7 @@ HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Control : system {system}, heartRateController {heartRateController}, characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u, - .access_cb = HeartRateServiceServiceCallback, + .access_cb = HeartRateServiceCallback, .arg = this, .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY, .val_handle = &heartRateMeasurementHandle}, @@ -56,6 +56,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a } void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { + if(!heartRateMeasurementNotificationEnable) return; + uint8_t buffer[2] = {0, heartRateController.HeartRate()}; // [0] = flags, [1] = hr value auto* om = ble_hs_mbuf_from_flat(buffer, 2); @@ -67,3 +69,13 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) { ble_gattc_notify_custom(connectionHandle, heartRateMeasurementHandle, om); } + +void HeartRateService::SubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { + if(attributeHandle == heartRateMeasurementHandle) + heartRateMeasurementNotificationEnable = true; +} + +void HeartRateService::UnsubscribeNotification(uint16_t connectionHandle, uint16_t attributeHandle) { + if(attributeHandle == heartRateMeasurementHandle) + heartRateMeasurementNotificationEnable = false; +}
\ No newline at end of file |