summaryrefslogtreecommitdiff
path: root/src/components/ble/HeartRateService.cpp
diff options
context:
space:
mode:
authorJean-François Milants <jf@codingfield.com>2021-11-11 09:08:20 (GMT)
committerJean-François Milants <jf@codingfield.com>2021-11-11 09:08:20 (GMT)
commitf6d0ec49e6f2669c64729b081eb3342f02151f4a (patch)
tree7e21c83726bd3e0d18ec4ebe871274b1dbe2eb38 /src/components/ble/HeartRateService.cpp
parentf41aaad6836ae348d1b5b084b4533b636f516b93 (diff)
parenta57fda6ba4a29866083a1254ffdf92939d00e182 (diff)
Merge branch 'develop'
# Conflicts: # doc/buildAndProgram.md
Diffstat (limited to 'src/components/ble/HeartRateService.cpp')
-rw-r--r--src/components/ble/HeartRateService.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/components/ble/HeartRateService.cpp b/src/components/ble/HeartRateService.cpp
index c556566..75a038a 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);
}
@@ -18,8 +18,8 @@ namespace {
HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Controllers::HeartRateController& heartRateController)
: system {system},
heartRateController {heartRateController},
- characteristicDefinition {{.uuid = (ble_uuid_t*) &heartRateMeasurementUuid,
- .access_cb = HeartRateServiceServiceCallback,
+ characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u,
+ .access_cb = HeartRateServiceCallback,
.arg = this,
.flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
.val_handle = &heartRateMeasurementHandle},
@@ -27,7 +27,7 @@ HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Control
serviceDefinition {
{/* Device Information Service */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
- .uuid = (ble_uuid_t*) &heartRateServiceUuid,
+ .uuid = &heartRateServiceUuid.u,
.characteristics = characteristicDefinition},
{0},
} {
@@ -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