Add context support and update lrpc

This commit is contained in:
2022-05-01 15:22:28 -07:00
parent b0c4574481
commit 78b5ca1de8
21 changed files with 155 additions and 144 deletions

View File

@@ -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
}