Skip to content

Commit

Permalink
examples: improve heartrate examples by adding all of the required ch…
Browse files Browse the repository at this point in the history
…aracteristics

for it to fulfill the complete heart rate profile in the spec.

Signed-off-by: deadprogram <[email protected]>
  • Loading branch information
deadprogram committed Jan 9, 2025
1 parent 5623054 commit 71e737c
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions examples/heartrate/main.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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")
Expand All @@ -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{
Expand All @@ -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,
},
},
}))

Expand Down

0 comments on commit 71e737c

Please sign in to comment.