Skip to content

Commit 71e737c

Browse files
committed
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 <ron@hybridgroup.com>
1 parent 5623054 commit 71e737c

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

examples/heartrate/main.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// this example implements a BLE heart rate sensor.
2+
// see https://www.bluetooth.com/specifications/specs/heart-rate-profile-1-0/ for the full spec.
13
package main
24

35
import (
@@ -7,10 +9,15 @@ import (
79
"tinygo.org/x/bluetooth"
810
)
911

10-
var adapter = bluetooth.DefaultAdapter
12+
var (
13+
adapter = bluetooth.DefaultAdapter
1114

12-
// TODO: use atomics to access this value.
13-
var heartRate uint8 = 75 // 75bpm
15+
heartRateMeasurement bluetooth.Characteristic
16+
bodyLocation bluetooth.Characteristic
17+
controlPoint bluetooth.Characteristic
18+
19+
heartRate uint8 = 75 // 75bpm
20+
)
1421

1522
func main() {
1623
println("starting")
@@ -22,7 +29,6 @@ func main() {
2229
}))
2330
must("start adv", adv.Start())
2431

25-
var heartRateMeasurement bluetooth.Characteristic
2632
must("add service", adapter.AddService(&bluetooth.Service{
2733
UUID: bluetooth.ServiceUUIDHeartRate,
2834
Characteristics: []bluetooth.CharacteristicConfig{
@@ -32,6 +38,18 @@ func main() {
3238
Value: []byte{0, heartRate},
3339
Flags: bluetooth.CharacteristicNotifyPermission,
3440
},
41+
{
42+
Handle: &bodyLocation,
43+
UUID: bluetooth.CharacteristicUUIDBodySensorLocation,
44+
Value: []byte{1}, // "Chest"
45+
Flags: bluetooth.CharacteristicReadPermission,
46+
},
47+
{
48+
Handle: &controlPoint,
49+
UUID: bluetooth.CharacteristicUUIDHeartRateControlPoint,
50+
Value: []byte{0},
51+
Flags: bluetooth.CharacteristicWritePermission,
52+
},
3553
},
3654
}))
3755

0 commit comments

Comments
 (0)