From 71e737c5732098d8a9f37ae34e10bcf045a77711 Mon Sep 17 00:00:00 2001 From: deadprogram Date: Sat, 4 Jan 2025 19:29:10 +0100 Subject: [PATCH] examples: improve heartrate examples by adding all of the required characteristics for it to fulfill the complete heart rate profile in the spec. Signed-off-by: deadprogram --- examples/heartrate/main.go | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/examples/heartrate/main.go b/examples/heartrate/main.go index 061e89f8..724bf823 100644 --- a/examples/heartrate/main.go +++ b/examples/heartrate/main.go @@ -1,3 +1,5 @@ +// this example implements a BLE heart rate sensor. +// see https://www.bluetooth.com/specifications/specs/heart-rate-profile-1-0/ for the full spec. package main import ( @@ -7,10 +9,15 @@ import ( "tinygo.org/x/bluetooth" ) -var adapter = bluetooth.DefaultAdapter +var ( + adapter = bluetooth.DefaultAdapter -// TODO: use atomics to access this value. -var heartRate uint8 = 75 // 75bpm + heartRateMeasurement bluetooth.Characteristic + bodyLocation bluetooth.Characteristic + controlPoint bluetooth.Characteristic + + heartRate uint8 = 75 // 75bpm +) func main() { println("starting") @@ -22,7 +29,6 @@ func main() { })) must("start adv", adv.Start()) - var heartRateMeasurement bluetooth.Characteristic must("add service", adapter.AddService(&bluetooth.Service{ UUID: bluetooth.ServiceUUIDHeartRate, Characteristics: []bluetooth.CharacteristicConfig{ @@ -32,6 +38,18 @@ func main() { Value: []byte{0, heartRate}, Flags: bluetooth.CharacteristicNotifyPermission, }, + { + Handle: &bodyLocation, + UUID: bluetooth.CharacteristicUUIDBodySensorLocation, + Value: []byte{1}, // "Chest" + Flags: bluetooth.CharacteristicReadPermission, + }, + { + Handle: &controlPoint, + UUID: bluetooth.CharacteristicUUIDHeartRateControlPoint, + Value: []byte{0}, + Flags: bluetooth.CharacteristicWritePermission, + }, }, }))