forked from Elara6331/itd
Add context support and update lrpc
This commit is contained in:
46
api/watch.go
46
api/watch.go
@@ -1,81 +1,71 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.arsenm.dev/infinitime"
|
||||
)
|
||||
|
||||
func (c *Client) WatchHeartRate() (<-chan uint8, func(), error) {
|
||||
func (c *Client) WatchHeartRate(ctx context.Context) (<-chan uint8, error) {
|
||||
outCh := make(chan uint8, 2)
|
||||
err := c.client.Call(
|
||||
ctx,
|
||||
"ITD",
|
||||
"WatchHeartRate",
|
||||
nil,
|
||||
outCh,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doneFn := func() {
|
||||
close(outCh)
|
||||
}
|
||||
|
||||
return outCh, doneFn, nil
|
||||
return outCh, nil
|
||||
}
|
||||
|
||||
func (c *Client) WatchBatteryLevel() (<-chan uint8, func(), error) {
|
||||
func (c *Client) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) {
|
||||
outCh := make(chan uint8, 2)
|
||||
err := c.client.Call(
|
||||
ctx,
|
||||
"ITD",
|
||||
"WatchBatteryLevel",
|
||||
nil,
|
||||
outCh,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doneFn := func() {
|
||||
close(outCh)
|
||||
}
|
||||
|
||||
return outCh, doneFn, nil
|
||||
return outCh, nil
|
||||
}
|
||||
|
||||
func (c *Client) WatchStepCount() (<-chan uint32, func(), error) {
|
||||
func (c *Client) WatchStepCount(ctx context.Context) (<-chan uint32, error) {
|
||||
outCh := make(chan uint32, 2)
|
||||
err := c.client.Call(
|
||||
ctx,
|
||||
"ITD",
|
||||
"WatchStepCount",
|
||||
nil,
|
||||
outCh,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doneFn := func() {
|
||||
close(outCh)
|
||||
}
|
||||
|
||||
return outCh, doneFn, nil
|
||||
return outCh, nil
|
||||
}
|
||||
|
||||
func (c *Client) WatchMotion() (<-chan infinitime.MotionValues, func(), error) {
|
||||
func (c *Client) WatchMotion(ctx context.Context) (<-chan infinitime.MotionValues, error) {
|
||||
outCh := make(chan infinitime.MotionValues, 2)
|
||||
err := c.client.Call(
|
||||
ctx,
|
||||
"ITD",
|
||||
"WatchMotion",
|
||||
nil,
|
||||
outCh,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doneFn := func() {
|
||||
close(outCh)
|
||||
}
|
||||
|
||||
return outCh, doneFn, nil
|
||||
return outCh, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user