@@ -8,7 +8,7 @@ constexpr ble_uuid16_t HeartRateService::heartRateServiceUuid;
88constexpr ble_uuid16_t HeartRateService::heartRateMeasurementUuid;
99
1010namespace {
11- int HeartRateServiceServiceCallback (uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt * ctxt, void * arg) {
11+ int HeartRateServiceCallback (uint16_t conn_handle, uint16_t attr_handle, struct ble_gatt_access_ctxt * ctxt, void * arg) {
1212 auto * heartRateService = static_cast <HeartRateService*>(arg);
1313 return heartRateService->OnHeartRateRequested (conn_handle, attr_handle, ctxt);
1414 }
@@ -19,7 +19,7 @@ HeartRateService::HeartRateService(Pinetime::System::SystemTask& system, Control
1919 : system {system},
2020 heartRateController {heartRateController},
2121 characteristicDefinition {{.uuid = &heartRateMeasurementUuid.u ,
22- .access_cb = HeartRateServiceServiceCallback ,
22+ .access_cb = HeartRateServiceCallback ,
2323 .arg = this ,
2424 .flags = BLE_GATT_CHR_F_READ | BLE_GATT_CHR_F_NOTIFY,
2525 .val_handle = &heartRateMeasurementHandle},
@@ -56,6 +56,8 @@ int HeartRateService::OnHeartRateRequested(uint16_t connectionHandle, uint16_t a
5656}
5757
5858void HeartRateService::OnNewHeartRateValue (uint8_t heartRateValue) {
59+ if (!heartRateMeasurementNotificationEnable) return ;
60+
5961 uint8_t buffer[2 ] = {0 , heartRateController.HeartRate ()}; // [0] = flags, [1] = hr value
6062 auto * om = ble_hs_mbuf_from_flat (buffer, 2 );
6163
@@ -67,3 +69,13 @@ void HeartRateService::OnNewHeartRateValue(uint8_t heartRateValue) {
6769
6870 ble_gattc_notify_custom (connectionHandle, heartRateMeasurementHandle, om);
6971}
72+
73+ void HeartRateService::SubscribeNotification (uint16_t connectionHandle, uint16_t attributeHandle) {
74+ if (attributeHandle == heartRateMeasurementHandle)
75+ heartRateMeasurementNotificationEnable = true ;
76+ }
77+
78+ void HeartRateService::UnsubscribeNotification (uint16_t connectionHandle, uint16_t attributeHandle) {
79+ if (attributeHandle == heartRateMeasurementHandle)
80+ heartRateMeasurementNotificationEnable = false ;
81+ }
0 commit comments