Add watch function for battery level
This commit is contained in:
parent
18dec0d2b5
commit
367032ec7e
@ -351,6 +351,34 @@ func (i *Device) WatchHeartRate() (<-chan uint8, error) {
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (i *Device) WatchBatteryLevel() (<-chan uint8, error) {
|
||||
if !i.device.Properties.Connected {
|
||||
return make(<-chan uint8), nil
|
||||
}
|
||||
// Start notifications on heart rate characteristic
|
||||
err := i.battLevelChar.StartNotify()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Watch characteristics of heart rate characteristic
|
||||
ch, err := i.battLevelChar.WatchProperties()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make(chan uint8, 2)
|
||||
go func() {
|
||||
// For every event
|
||||
for event := range ch {
|
||||
// If value changed
|
||||
if event.Name == "Value" {
|
||||
// Send heart rate to channel
|
||||
out <- uint8(event.Value.([]byte)[0])
|
||||
}
|
||||
}
|
||||
}()
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// SetTime sets the watch's time using the Current Time Service
|
||||
func (i *Device) SetTime(t time.Time) error {
|
||||
if !i.device.Properties.Connected {
|
||||
|
Reference in New Issue
Block a user