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.
13package main
24
35import (
@@ -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
1522func 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