Add context support and update lrpc
This commit is contained in:
@@ -28,7 +28,7 @@ func fwUpgrade(c *cli.Context) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -58,7 +58,7 @@ func fwUpgrade(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func fwVersion(c *cli.Context) error {
|
||||
version, err := client.Version()
|
||||
version, err := client.Version(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ func fsList(c *cli.Context) error {
|
||||
dirPath = c.Args().Get(0)
|
||||
}
|
||||
|
||||
listing, err := client.ReadDir(dirPath)
|
||||
listing, err := client.ReadDir(c.Context, dirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -34,7 +34,7 @@ func fsMkdir(c *cli.Context) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -47,7 +47,7 @@ func fsMove(c *cli.Context) error {
|
||||
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 {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func fsRemove(c *cli.Context) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -144,7 +144,7 @@ func fsWrite(c *cli.Context) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func getAddress(c *cli.Context) error {
|
||||
address, err := client.Address()
|
||||
address, err := client.Address(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -19,7 +19,7 @@ func getAddress(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func getBattery(c *cli.Context) error {
|
||||
battLevel, err := client.BatteryLevel()
|
||||
battLevel, err := client.BatteryLevel(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -30,7 +30,7 @@ func getBattery(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func getHeart(c *cli.Context) error {
|
||||
heartRate, err := client.HeartRate()
|
||||
heartRate, err := client.HeartRate(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func getHeart(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func getMotion(c *cli.Context) error {
|
||||
motionVals, err := client.Motion()
|
||||
motionVals, err := client.Motion(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -60,7 +60,7 @@ func getMotion(c *cli.Context) error {
|
||||
}
|
||||
|
||||
func getSteps(c *cli.Context) error {
|
||||
stepCount, err := client.StepCount()
|
||||
stepCount, err := client.StepCount(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ func notify(c *cli.Context) error {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ func setTime(c *cli.Context) error {
|
||||
}
|
||||
|
||||
if c.Args().Get(0) == "now" {
|
||||
return client.SetTime(time.Now())
|
||||
return client.SetTime(c.Context, time.Now())
|
||||
} else {
|
||||
parsed, err := time.Parse(time.RFC3339, c.Args().Get(0))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.SetTime(parsed)
|
||||
return client.SetTime(c.Context, parsed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package main
|
||||
import "github.com/urfave/cli/v2"
|
||||
|
||||
func updateWeather(c *cli.Context) error {
|
||||
return client.WeatherUpdate()
|
||||
return client.WeatherUpdate(c.Context)
|
||||
}
|
||||
|
||||
@@ -9,104 +9,88 @@ import (
|
||||
)
|
||||
|
||||
func watchHeart(c *cli.Context) error {
|
||||
heartCh, cancel, err := client.WatchHeartRate()
|
||||
heartCh, err := client.WatchHeartRate(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case heartRate := <-heartCh:
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(
|
||||
map[string]uint8{"heartRate": heartRate},
|
||||
)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf("HEART_RATE=%d\n", heartRate)
|
||||
} else {
|
||||
fmt.Println(heartRate, "BPM")
|
||||
}
|
||||
case <-c.Done():
|
||||
cancel()
|
||||
return nil
|
||||
for heartRate := range heartCh {
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(
|
||||
map[string]uint8{"heartRate": heartRate},
|
||||
)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf("HEART_RATE=%d\n", heartRate)
|
||||
} else {
|
||||
fmt.Println(heartRate, "BPM")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func watchBattLevel(c *cli.Context) error {
|
||||
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
||||
battLevelCh, err := client.WatchBatteryLevel(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case battLevel := <-battLevelCh:
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(
|
||||
map[string]uint8{"battLevel": battLevel},
|
||||
)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf("BATTERY_LEVEL=%d\n", battLevel)
|
||||
} else {
|
||||
fmt.Printf("%d%%\n", battLevel)
|
||||
}
|
||||
case <-c.Done():
|
||||
cancel()
|
||||
return nil
|
||||
for battLevel := range battLevelCh {
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(
|
||||
map[string]uint8{"battLevel": battLevel},
|
||||
)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf("BATTERY_LEVEL=%d\n", battLevel)
|
||||
} else {
|
||||
fmt.Printf("%d%%\n", battLevel)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func watchStepCount(c *cli.Context) error {
|
||||
stepCountCh, cancel, err := client.WatchStepCount()
|
||||
stepCountCh, err := client.WatchStepCount(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case stepCount := <-stepCountCh:
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(
|
||||
map[string]uint32{"stepCount": stepCount},
|
||||
)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf("STEP_COUNT=%d\n", stepCount)
|
||||
} else {
|
||||
fmt.Println(stepCount, "Steps")
|
||||
}
|
||||
case <-c.Done():
|
||||
cancel()
|
||||
return nil
|
||||
for stepCount := range stepCountCh {
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(
|
||||
map[string]uint32{"stepCount": stepCount},
|
||||
)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf("STEP_COUNT=%d\n", stepCount)
|
||||
} else {
|
||||
fmt.Println(stepCount, "Steps")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func watchMotion(c *cli.Context) error {
|
||||
motionCh, cancel, err := client.WatchMotion()
|
||||
motionCh, err := client.WatchMotion(c.Context)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case motionVals := <-motionCh:
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(motionVals)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf(
|
||||
"X=%d\nY=%d\nZ=%d\n",
|
||||
motionVals.X,
|
||||
motionVals.Y,
|
||||
motionVals.Z,
|
||||
)
|
||||
} else {
|
||||
fmt.Println(motionVals)
|
||||
}
|
||||
case <-c.Done():
|
||||
cancel()
|
||||
return nil
|
||||
for motionVals := range motionCh {
|
||||
if c.Bool("json") {
|
||||
json.NewEncoder(os.Stdout).Encode(motionVals)
|
||||
} else if c.Bool("shell") {
|
||||
fmt.Printf(
|
||||
"X=%d\nY=%d\nZ=%d\n",
|
||||
motionVals.X,
|
||||
motionVals.Y,
|
||||
motionVals.Z,
|
||||
)
|
||||
} else {
|
||||
fmt.Println(motionVals)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"image/color"
|
||||
|
||||
@@ -27,11 +28,13 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||
)
|
||||
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 {
|
||||
guiErr(err, "Error getting heart rate channel", true, parent)
|
||||
}
|
||||
onClose = append(onClose, cancel)
|
||||
go func() {
|
||||
for heartRate := range heartRateCh {
|
||||
// Change text of heart rate label
|
||||
@@ -51,11 +54,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||
)
|
||||
infoLayout.Add(stepCountSect)
|
||||
|
||||
stepCountCh, cancel, err := client.WatchStepCount()
|
||||
stepCountCh, err := client.WatchStepCount(ctx)
|
||||
if err != nil {
|
||||
guiErr(err, "Error getting step count channel", true, parent)
|
||||
}
|
||||
onClose = append(onClose, cancel)
|
||||
go func() {
|
||||
for stepCount := range stepCountCh {
|
||||
// Change text of heart rate label
|
||||
@@ -75,11 +77,10 @@ func infoTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||
)
|
||||
infoLayout.Add(battLevel)
|
||||
|
||||
battLevelCh, cancel, err := client.WatchBatteryLevel()
|
||||
battLevelCh, err := client.WatchBatteryLevel(ctx)
|
||||
if err != nil {
|
||||
guiErr(err, "Error getting battery level channel", true, parent)
|
||||
}
|
||||
onClose = append(onClose, cancel)
|
||||
go func() {
|
||||
for battLevel := range battLevelCh {
|
||||
// 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 {
|
||||
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)
|
||||
|
||||
btAddrString, err := client.Address()
|
||||
btAddrString, err := client.Address(context.Background())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"image/color"
|
||||
"strconv"
|
||||
|
||||
@@ -44,6 +45,10 @@ func motionTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||
|
||||
// Create button to stop motion
|
||||
stopBtn := widget.NewButton("Stop", nil)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
onClose = append(onClose, cancel)
|
||||
|
||||
// Create button to start motion
|
||||
startBtn := widget.NewButton("Start", func() {
|
||||
// if motion is started
|
||||
@@ -54,7 +59,7 @@ func motionTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||
// Set motion started
|
||||
started = true
|
||||
// Watch motion values
|
||||
motionCh, cancel, err := client.WatchMotion()
|
||||
motionCh, err := client.WatchMotion(ctx)
|
||||
if err != nil {
|
||||
guiErr(err, "Error getting heart rate channel", true, parent)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fyne.io/fyne/v2"
|
||||
"fyne.io/fyne/v2/container"
|
||||
"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
|
||||
sendBtn := widget.NewButton("Send", func() {
|
||||
err := client.Notify(titleEntry.Text, bodyEntry.Text)
|
||||
err := client.Notify(context.Background(), titleEntry.Text, bodyEntry.Text)
|
||||
if err != nil {
|
||||
guiErr(err, "Error sending notification", false, parent)
|
||||
return
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"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 {
|
||||
var err error
|
||||
if current {
|
||||
err = client.SetTime(time.Now())
|
||||
err = client.SetTime(context.Background(), time.Now())
|
||||
} else {
|
||||
err = client.SetTime(t[0])
|
||||
err = client.SetTime(context.Background(), t[0])
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
|
||||
@@ -125,7 +126,7 @@ func upgradeTab(parent fyne.Window, client *api.Client) *fyne.Container {
|
||||
files = append(files, initPktPath, firmwarePath)
|
||||
}
|
||||
|
||||
progress, err := client.FirmwareUpgrade(fwUpgType, files...)
|
||||
progress, err := client.FirmwareUpgrade(context.Background(), fwUpgType, files...)
|
||||
if err != nil {
|
||||
guiErr(err, "Error initiating DFU", false, parent)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user