forked from Elara6331/itd
Add context support and update lrpc
This commit is contained in:
parent
b0c4574481
commit
78b5ca1de8
@ -1,12 +1,15 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"go.arsenm.dev/infinitime"
|
"go.arsenm.dev/infinitime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) FirmwareUpgrade(upgType UpgradeType, files ...string) (chan infinitime.DFUProgress, error) {
|
func (c *Client) FirmwareUpgrade(ctx context.Context, upgType UpgradeType, files ...string) (chan infinitime.DFUProgress, error) {
|
||||||
progressCh := make(chan infinitime.DFUProgress, 5)
|
progressCh := make(chan infinitime.DFUProgress, 5)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"FirmwareUpgrade",
|
"FirmwareUpgrade",
|
||||||
FwUpgradeData{
|
FwUpgradeData{
|
||||||
|
20
api/fs.go
20
api/fs.go
@ -1,7 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
func (c *Client) Remove(paths ...string) error {
|
import "context"
|
||||||
|
|
||||||
|
func (c *Client) Remove(ctx context.Context, paths ...string) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
|
ctx,
|
||||||
"FS",
|
"FS",
|
||||||
"Remove",
|
"Remove",
|
||||||
paths,
|
paths,
|
||||||
@ -9,8 +12,9 @@ func (c *Client) Remove(paths ...string) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Rename(old, new string) error {
|
func (c *Client) Rename(ctx context.Context, old, new string) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
|
ctx,
|
||||||
"FS",
|
"FS",
|
||||||
"Rename",
|
"Rename",
|
||||||
[2]string{old, new},
|
[2]string{old, new},
|
||||||
@ -18,8 +22,9 @@ func (c *Client) Rename(old, new string) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Mkdir(paths ...string) error {
|
func (c *Client) Mkdir(ctx context.Context, paths ...string) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
|
ctx,
|
||||||
"FS",
|
"FS",
|
||||||
"Mkdir",
|
"Mkdir",
|
||||||
paths,
|
paths,
|
||||||
@ -27,8 +32,9 @@ func (c *Client) Mkdir(paths ...string) error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) ReadDir(dir string) (out []FileInfo, err error) {
|
func (c *Client) ReadDir(ctx context.Context, dir string) (out []FileInfo, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"FS",
|
"FS",
|
||||||
"ReadDir",
|
"ReadDir",
|
||||||
dir,
|
dir,
|
||||||
@ -37,9 +43,10 @@ func (c *Client) ReadDir(dir string) (out []FileInfo, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Upload(dst, src string) (chan FSTransferProgress, error) {
|
func (c *Client) Upload(ctx context.Context, dst, src string) (chan FSTransferProgress, error) {
|
||||||
progressCh := make(chan FSTransferProgress, 5)
|
progressCh := make(chan FSTransferProgress, 5)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"FS",
|
"FS",
|
||||||
"Upload",
|
"Upload",
|
||||||
[2]string{dst, src},
|
[2]string{dst, src},
|
||||||
@ -52,9 +59,10 @@ func (c *Client) Upload(dst, src string) (chan FSTransferProgress, error) {
|
|||||||
return progressCh, nil
|
return progressCh, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Download(dst, src string) (chan FSTransferProgress, error) {
|
func (c *Client) Download(ctx context.Context, dst, src string) (chan FSTransferProgress, error) {
|
||||||
progressCh := make(chan FSTransferProgress, 5)
|
progressCh := make(chan FSTransferProgress, 5)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"FS",
|
"FS",
|
||||||
"Download",
|
"Download",
|
||||||
[2]string{dst, src},
|
[2]string{dst, src},
|
||||||
|
20
api/get.go
20
api/get.go
@ -1,11 +1,14 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"go.arsenm.dev/infinitime"
|
"go.arsenm.dev/infinitime"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) HeartRate() (out uint8, err error) {
|
func (c *Client) HeartRate(ctx context.Context) (out uint8, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"HeartRate",
|
"HeartRate",
|
||||||
nil,
|
nil,
|
||||||
@ -14,8 +17,9 @@ func (c *Client) HeartRate() (out uint8, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) BatteryLevel() (out uint8, err error) {
|
func (c *Client) BatteryLevel(ctx context.Context) (out uint8, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"BatteryLevel",
|
"BatteryLevel",
|
||||||
nil,
|
nil,
|
||||||
@ -24,8 +28,9 @@ func (c *Client) BatteryLevel() (out uint8, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Motion() (out infinitime.MotionValues, err error) {
|
func (c *Client) Motion(ctx context.Context) (out infinitime.MotionValues, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"Motion",
|
"Motion",
|
||||||
nil,
|
nil,
|
||||||
@ -34,8 +39,9 @@ func (c *Client) Motion() (out infinitime.MotionValues, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) StepCount() (out uint32, err error) {
|
func (c *Client) StepCount(ctx context.Context) (out uint32, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"StepCount",
|
"StepCount",
|
||||||
nil,
|
nil,
|
||||||
@ -44,8 +50,9 @@ func (c *Client) StepCount() (out uint32, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Version() (out string, err error) {
|
func (c *Client) Version(ctx context.Context) (out string, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"Version",
|
"Version",
|
||||||
nil,
|
nil,
|
||||||
@ -54,8 +61,9 @@ func (c *Client) Version() (out string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Address() (out string, err error) {
|
func (c *Client) Address(ctx context.Context) (out string, err error) {
|
||||||
err = c.client.Call(
|
err = c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"Address",
|
"Address",
|
||||||
nil,
|
nil,
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
func (c *Client) Notify(title, body string) error {
|
import "context"
|
||||||
|
|
||||||
|
func (c *Client) Notify(ctx context.Context, title, body string) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"Notify",
|
"Notify",
|
||||||
NotifyData{
|
NotifyData{
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c *Client) SetTime(t time.Time) error {
|
func (c *Client) SetTime(ctx context.Context, t time.Time) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"SetTime",
|
"SetTime",
|
||||||
t,
|
t,
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
func (c *Client) WeatherUpdate() error {
|
import "context"
|
||||||
|
|
||||||
|
func (c *Client) WeatherUpdate(ctx context.Context) error {
|
||||||
return c.client.Call(
|
return c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"WeatherUpdate",
|
"WeatherUpdate",
|
||||||
nil,
|
nil,
|
||||||
|
46
api/watch.go
46
api/watch.go
@ -1,81 +1,71 @@
|
|||||||
package api
|
package api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"go.arsenm.dev/infinitime"
|
"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)
|
outCh := make(chan uint8, 2)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"WatchHeartRate",
|
"WatchHeartRate",
|
||||||
nil,
|
nil,
|
||||||
outCh,
|
outCh,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doneFn := func() {
|
return outCh, nil
|
||||||
close(outCh)
|
|
||||||
}
|
|
||||||
|
|
||||||
return outCh, doneFn, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) WatchBatteryLevel() (<-chan uint8, func(), error) {
|
func (c *Client) WatchBatteryLevel(ctx context.Context) (<-chan uint8, error) {
|
||||||
outCh := make(chan uint8, 2)
|
outCh := make(chan uint8, 2)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"WatchBatteryLevel",
|
"WatchBatteryLevel",
|
||||||
nil,
|
nil,
|
||||||
outCh,
|
outCh,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doneFn := func() {
|
return outCh, nil
|
||||||
close(outCh)
|
|
||||||
}
|
|
||||||
|
|
||||||
return outCh, doneFn, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) WatchStepCount() (<-chan uint32, func(), error) {
|
func (c *Client) WatchStepCount(ctx context.Context) (<-chan uint32, error) {
|
||||||
outCh := make(chan uint32, 2)
|
outCh := make(chan uint32, 2)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"WatchStepCount",
|
"WatchStepCount",
|
||||||
nil,
|
nil,
|
||||||
outCh,
|
outCh,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doneFn := func() {
|
return outCh, nil
|
||||||
close(outCh)
|
|
||||||
}
|
|
||||||
|
|
||||||
return outCh, doneFn, 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)
|
outCh := make(chan infinitime.MotionValues, 2)
|
||||||
err := c.client.Call(
|
err := c.client.Call(
|
||||||
|
ctx,
|
||||||
"ITD",
|
"ITD",
|
||||||
"WatchMotion",
|
"WatchMotion",
|
||||||
nil,
|
nil,
|
||||||
outCh,
|
outCh,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
doneFn := func() {
|
return outCh, nil
|
||||||
close(outCh)
|
|
||||||
}
|
|
||||||
|
|
||||||
return outCh, doneFn, nil
|
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func fwUpgrade(c *cli.Context) error {
|
|||||||
return cli.Exit("Upgrade command requires either archive or init packet and firmware.", 1)
|
return cli.Exit("Upgrade command requires either archive or init packet and firmware.", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
progress, err := client.FirmwareUpgrade(upgType, abs(files)...)
|
progress, err := client.FirmwareUpgrade(c.Context, upgType, abs(files)...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func fwUpgrade(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func fwVersion(c *cli.Context) error {
|
func fwVersion(c *cli.Context) error {
|
||||||
version, err := client.Version()
|
version, err := client.Version(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ func fsList(c *cli.Context) error {
|
|||||||
dirPath = c.Args().Get(0)
|
dirPath = c.Args().Get(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
listing, err := client.ReadDir(dirPath)
|
listing, err := client.ReadDir(c.Context, dirPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func fsMkdir(c *cli.Context) error {
|
|||||||
return cli.Exit("Command mkdir requires one or more arguments", 1)
|
return cli.Exit("Command mkdir requires one or more arguments", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Mkdir(c.Args().Slice()...)
|
err := client.Mkdir(c.Context, c.Args().Slice()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func fsMove(c *cli.Context) error {
|
|||||||
return cli.Exit("Command move requires two arguments", 1)
|
return cli.Exit("Command move requires two arguments", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Rename(c.Args().Get(0), c.Args().Get(1))
|
err := client.Rename(c.Context, c.Args().Get(0), c.Args().Get(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ func fsRead(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
progress, err := client.Download(path, c.Args().Get(0))
|
progress, err := client.Download(c.Context, path, c.Args().Get(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -109,7 +109,7 @@ func fsRemove(c *cli.Context) error {
|
|||||||
return cli.Exit("Command remove requires one or more arguments", 1)
|
return cli.Exit("Command remove requires one or more arguments", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Remove(c.Args().Slice()...)
|
err := client.Remove(c.Context, c.Args().Slice()...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -144,7 +144,7 @@ func fsWrite(c *cli.Context) error {
|
|||||||
defer os.Remove(path)
|
defer os.Remove(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
progress, err := client.Upload(c.Args().Get(1), path)
|
progress, err := client.Upload(c.Context, c.Args().Get(1), path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func getAddress(c *cli.Context) error {
|
func getAddress(c *cli.Context) error {
|
||||||
address, err := client.Address()
|
address, err := client.Address(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@ func getAddress(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getBattery(c *cli.Context) error {
|
func getBattery(c *cli.Context) error {
|
||||||
battLevel, err := client.BatteryLevel()
|
battLevel, err := client.BatteryLevel(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ func getBattery(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getHeart(c *cli.Context) error {
|
func getHeart(c *cli.Context) error {
|
||||||
heartRate, err := client.HeartRate()
|
heartRate, err := client.HeartRate(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ func getHeart(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getMotion(c *cli.Context) error {
|
func getMotion(c *cli.Context) error {
|
||||||
motionVals, err := client.Motion()
|
motionVals, err := client.Motion(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -60,7 +60,7 @@ func getMotion(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getSteps(c *cli.Context) error {
|
func getSteps(c *cli.Context) error {
|
||||||
stepCount, err := client.StepCount()
|
stepCount, err := client.StepCount(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ func notify(c *cli.Context) error {
|
|||||||
return cli.Exit("Command notify requires two arguments", 1)
|
return cli.Exit("Command notify requires two arguments", 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.Notify(c.Args().Get(0), c.Args().Get(1))
|
err := client.Notify(c.Context, c.Args().Get(0), c.Args().Get(1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -13,12 +13,12 @@ func setTime(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if c.Args().Get(0) == "now" {
|
if c.Args().Get(0) == "now" {
|
||||||
return client.SetTime(time.Now())
|
return client.SetTime(c.Context, time.Now())
|
||||||
} else {
|
} else {
|
||||||
parsed, err := time.Parse(time.RFC3339, c.Args().Get(0))
|
parsed, err := time.Parse(time.RFC3339, c.Args().Get(0))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return client.SetTime(parsed)
|
return client.SetTime(c.Context, parsed)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,5 +3,5 @@ package main
|
|||||||
import "github.com/urfave/cli/v2"
|
import "github.com/urfave/cli/v2"
|
||||||
|
|
||||||
func updateWeather(c *cli.Context) error {
|
func updateWeather(c *cli.Context) error {
|
||||||
return client.WeatherUpdate()
|
return client.WeatherUpdate(c.Context)
|
||||||
}
|
}
|
||||||
|
@ -9,14 +9,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func watchHeart(c *cli.Context) error {
|
func watchHeart(c *cli.Context) error {
|
||||||
heartCh, cancel, err := client.WatchHeartRate()
|
heartCh, err := client.WatchHeartRate(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for heartRate := range heartCh {
|
||||||
select {
|
|
||||||
case heartRate := <-heartCh:
|
|
||||||
if c.Bool("json") {
|
if c.Bool("json") {
|
||||||
json.NewEncoder(os.Stdout).Encode(
|
json.NewEncoder(os.Stdout).Encode(
|
||||||
map[string]uint8{"heartRate": heartRate},
|
map[string]uint8{"heartRate": heartRate},
|
||||||
@ -26,22 +24,18 @@ func watchHeart(c *cli.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println(heartRate, "BPM")
|
fmt.Println(heartRate, "BPM")
|
||||||
}
|
}
|
||||||
case <-c.Done():
|
}
|
||||||
cancel()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchBattLevel(c *cli.Context) error {
|
func watchBattLevel(c *cli.Context) error {
|
||||||
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
battLevelCh, err := client.WatchBatteryLevel(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for battLevel := range battLevelCh {
|
||||||
select {
|
|
||||||
case battLevel := <-battLevelCh:
|
|
||||||
if c.Bool("json") {
|
if c.Bool("json") {
|
||||||
json.NewEncoder(os.Stdout).Encode(
|
json.NewEncoder(os.Stdout).Encode(
|
||||||
map[string]uint8{"battLevel": battLevel},
|
map[string]uint8{"battLevel": battLevel},
|
||||||
@ -51,22 +45,18 @@ func watchBattLevel(c *cli.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Printf("%d%%\n", battLevel)
|
fmt.Printf("%d%%\n", battLevel)
|
||||||
}
|
}
|
||||||
case <-c.Done():
|
}
|
||||||
cancel()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchStepCount(c *cli.Context) error {
|
func watchStepCount(c *cli.Context) error {
|
||||||
stepCountCh, cancel, err := client.WatchStepCount()
|
stepCountCh, err := client.WatchStepCount(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for stepCount := range stepCountCh {
|
||||||
select {
|
|
||||||
case stepCount := <-stepCountCh:
|
|
||||||
if c.Bool("json") {
|
if c.Bool("json") {
|
||||||
json.NewEncoder(os.Stdout).Encode(
|
json.NewEncoder(os.Stdout).Encode(
|
||||||
map[string]uint32{"stepCount": stepCount},
|
map[string]uint32{"stepCount": stepCount},
|
||||||
@ -76,22 +66,18 @@ func watchStepCount(c *cli.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println(stepCount, "Steps")
|
fmt.Println(stepCount, "Steps")
|
||||||
}
|
}
|
||||||
case <-c.Done():
|
}
|
||||||
cancel()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func watchMotion(c *cli.Context) error {
|
func watchMotion(c *cli.Context) error {
|
||||||
motionCh, cancel, err := client.WatchMotion()
|
motionCh, err := client.WatchMotion(c.Context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for motionVals := range motionCh {
|
||||||
select {
|
|
||||||
case motionVals := <-motionCh:
|
|
||||||
if c.Bool("json") {
|
if c.Bool("json") {
|
||||||
json.NewEncoder(os.Stdout).Encode(motionVals)
|
json.NewEncoder(os.Stdout).Encode(motionVals)
|
||||||
} else if c.Bool("shell") {
|
} else if c.Bool("shell") {
|
||||||
@ -104,9 +90,7 @@ func watchMotion(c *cli.Context) error {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println(motionVals)
|
fmt.Println(motionVals)
|
||||||
}
|
}
|
||||||
case <-c.Done():
|
}
|
||||||
cancel()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image/color"
|
"image/color"
|
||||||
|
|
||||||
@ -27,11 +28,13 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
)
|
)
|
||||||
infoLayout.Add(heartRateSect)
|
infoLayout.Add(heartRateSect)
|
||||||
|
|
||||||
heartRateCh, cancel, err := client.WatchHeartRate()
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
onClose = append(onClose, cancel)
|
||||||
|
|
||||||
|
heartRateCh, err := client.WatchHeartRate(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting heart rate channel", true, parent)
|
guiErr(err, "Error getting heart rate channel", true, parent)
|
||||||
}
|
}
|
||||||
onClose = append(onClose, cancel)
|
|
||||||
go func() {
|
go func() {
|
||||||
for heartRate := range heartRateCh {
|
for heartRate := range heartRateCh {
|
||||||
// Change text of heart rate label
|
// Change text of heart rate label
|
||||||
@ -51,11 +54,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
)
|
)
|
||||||
infoLayout.Add(stepCountSect)
|
infoLayout.Add(stepCountSect)
|
||||||
|
|
||||||
stepCountCh, cancel, err := client.WatchStepCount()
|
stepCountCh, err := client.WatchStepCount(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting step count channel", true, parent)
|
guiErr(err, "Error getting step count channel", true, parent)
|
||||||
}
|
}
|
||||||
onClose = append(onClose, cancel)
|
|
||||||
go func() {
|
go func() {
|
||||||
for stepCount := range stepCountCh {
|
for stepCount := range stepCountCh {
|
||||||
// Change text of heart rate label
|
// Change text of heart rate label
|
||||||
@ -75,11 +77,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
)
|
)
|
||||||
infoLayout.Add(battLevel)
|
infoLayout.Add(battLevel)
|
||||||
|
|
||||||
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
battLevelCh, err := client.WatchBatteryLevel(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting battery level channel", true, parent)
|
guiErr(err, "Error getting battery level channel", true, parent)
|
||||||
}
|
}
|
||||||
onClose = append(onClose, cancel)
|
|
||||||
go func() {
|
go func() {
|
||||||
for battLevel := range battLevelCh {
|
for battLevel := range battLevelCh {
|
||||||
// Change text of battery level label
|
// Change text of battery level label
|
||||||
@ -89,7 +90,7 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
fwVerString, err := client.Version()
|
fwVerString, err := client.Version(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting firmware string", true, parent)
|
guiErr(err, "Error getting firmware string", true, parent)
|
||||||
}
|
}
|
||||||
@ -101,7 +102,7 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
)
|
)
|
||||||
infoLayout.Add(fwVer)
|
infoLayout.Add(fwVer)
|
||||||
|
|
||||||
btAddrString, err := client.Address()
|
btAddrString, err := client.Address(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"image/color"
|
"image/color"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
@ -44,6 +45,10 @@ func motionTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
|
|
||||||
// Create button to stop motion
|
// Create button to stop motion
|
||||||
stopBtn := widget.NewButton("Stop", nil)
|
stopBtn := widget.NewButton("Stop", nil)
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
onClose = append(onClose, cancel)
|
||||||
|
|
||||||
// Create button to start motion
|
// Create button to start motion
|
||||||
startBtn := widget.NewButton("Start", func() {
|
startBtn := widget.NewButton("Start", func() {
|
||||||
// if motion is started
|
// if motion is started
|
||||||
@ -54,7 +59,7 @@ func motionTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
// Set motion started
|
// Set motion started
|
||||||
started = true
|
started = true
|
||||||
// Watch motion values
|
// Watch motion values
|
||||||
motionCh, cancel, err := client.WatchMotion()
|
motionCh, err := client.WatchMotion(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error getting heart rate channel", true, parent)
|
guiErr(err, "Error getting heart rate channel", true, parent)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
"fyne.io/fyne/v2/container"
|
"fyne.io/fyne/v2/container"
|
||||||
"fyne.io/fyne/v2/layout"
|
"fyne.io/fyne/v2/layout"
|
||||||
@ -19,7 +21,7 @@ func notifyTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
|
|
||||||
// Create new button to send notification
|
// Create new button to send notification
|
||||||
sendBtn := widget.NewButton("Send", func() {
|
sendBtn := widget.NewButton("Send", func() {
|
||||||
err := client.Notify(titleEntry.Text, bodyEntry.Text)
|
err := client.Notify(context.Background(), titleEntry.Text, bodyEntry.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error sending notification", false, parent)
|
guiErr(err, "Error sending notification", false, parent)
|
||||||
return
|
return
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"fyne.io/fyne/v2"
|
"fyne.io/fyne/v2"
|
||||||
@ -49,9 +50,9 @@ func timeTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
func setTime(client *api.Client, current bool, t ...time.Time) error {
|
func setTime(client *api.Client, current bool, t ...time.Time) error {
|
||||||
var err error
|
var err error
|
||||||
if current {
|
if current {
|
||||||
err = client.SetTime(time.Now())
|
err = client.SetTime(context.Background(), time.Now())
|
||||||
} else {
|
} else {
|
||||||
err = client.SetTime(t[0])
|
err = client.SetTime(context.Background(), t[0])
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -125,7 +126,7 @@ func upgradeTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
|||||||
files = append(files, initPktPath, firmwarePath)
|
files = append(files, initPktPath, firmwarePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
progress, err := client.FirmwareUpgrade(fwUpgType, files...)
|
progress, err := client.FirmwareUpgrade(context.Background(), fwUpgType, files...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
guiErr(err, "Error initiating DFU", false, parent)
|
guiErr(err, "Error initiating DFU", false, parent)
|
||||||
return
|
return
|
||||||
|
4
go.mod
4
go.mod
@ -2,6 +2,8 @@ module go.arsenm.dev/itd
|
|||||||
|
|
||||||
go 1.17
|
go 1.17
|
||||||
|
|
||||||
|
replace go.arsenm.dev/lrpc => /home/arsen/Code/lrpc
|
||||||
|
|
||||||
require (
|
require (
|
||||||
fyne.io/fyne/v2 v2.1.2
|
fyne.io/fyne/v2 v2.1.2
|
||||||
github.com/cheggaaa/pb/v3 v3.0.8
|
github.com/cheggaaa/pb/v3 v3.0.8
|
||||||
@ -13,7 +15,7 @@ require (
|
|||||||
github.com/rs/zerolog v1.26.1
|
github.com/rs/zerolog v1.26.1
|
||||||
github.com/urfave/cli/v2 v2.3.0
|
github.com/urfave/cli/v2 v2.3.0
|
||||||
go.arsenm.dev/infinitime v0.0.0-20220424030849-6c3f1b14c948
|
go.arsenm.dev/infinitime v0.0.0-20220424030849-6c3f1b14c948
|
||||||
go.arsenm.dev/lrpc v0.0.0-20220501205436-6df8cf53c6e6
|
go.arsenm.dev/lrpc v0.0.0-20220501221746-f1aa0f5c4f8f
|
||||||
golang.org/x/text v0.3.7
|
golang.org/x/text v0.3.7
|
||||||
)
|
)
|
||||||
|
|
||||||
|
2
go.sum
2
go.sum
@ -200,8 +200,6 @@ github.com/yuin/goldmark v1.4.1 h1:/vn0k+RBvwlxEmP5E7SZMqNxPhfMVFEJiykr15/0XKM=
|
|||||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||||
go.arsenm.dev/infinitime v0.0.0-20220424030849-6c3f1b14c948 h1:OX1SyEIFz4ae2z468lBQvRTNRvqLEwjfJ8lcssUH5+w=
|
go.arsenm.dev/infinitime v0.0.0-20220424030849-6c3f1b14c948 h1:OX1SyEIFz4ae2z468lBQvRTNRvqLEwjfJ8lcssUH5+w=
|
||||||
go.arsenm.dev/infinitime v0.0.0-20220424030849-6c3f1b14c948/go.mod h1:1cBQ3fp6QlRbSqu9kEBAHsVThINj31FtqHIYVsQ7wgg=
|
go.arsenm.dev/infinitime v0.0.0-20220424030849-6c3f1b14c948/go.mod h1:1cBQ3fp6QlRbSqu9kEBAHsVThINj31FtqHIYVsQ7wgg=
|
||||||
go.arsenm.dev/lrpc v0.0.0-20220501205436-6df8cf53c6e6 h1:5Sd7fqK3ng/xSI3XNgIVEKfFl+6p2jv+zVo2Ag07V/M=
|
|
||||||
go.arsenm.dev/lrpc v0.0.0-20220501205436-6df8cf53c6e6/go.mod h1:KtIqSuK4mMzHm9OIO2oRtMxSZTooPCnMgtP3Q88N7hw=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
Loading…
Reference in New Issue
Block a user