2022-04-24 01:46:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func watchHeart(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
heartCh, err := client.WatchHeartRate(c.Context)
|
2022-04-24 01:46:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-02 03:32:59 +00:00
|
|
|
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():
|
|
|
|
return nil
|
2022-04-24 01:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func watchBattLevel(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
battLevelCh, err := client.WatchBatteryLevel(c.Context)
|
2022-04-24 01:46:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-02 03:32:59 +00:00
|
|
|
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():
|
|
|
|
return nil
|
2022-04-24 01:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func watchStepCount(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
stepCountCh, err := client.WatchStepCount(c.Context)
|
2022-04-24 01:46:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-02 03:32:59 +00:00
|
|
|
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():
|
|
|
|
return nil
|
2022-04-24 01:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func watchMotion(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
motionCh, err := client.WatchMotion(c.Context)
|
2022-04-24 01:46:49 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-05-02 03:32:59 +00:00
|
|
|
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():
|
|
|
|
return nil
|
2022-04-24 01:46:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|