2022-02-25 05:26:40 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func getAddress(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
address, err := client.Address(c.Context)
|
2022-02-25 05:26:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(address)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getBattery(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
battLevel, err := client.BatteryLevel(c.Context)
|
2022-02-25 05:26:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print returned percentage
|
|
|
|
fmt.Printf("%d%%\n", battLevel)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getHeart(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
heartRate, err := client.HeartRate(c.Context)
|
2022-02-25 05:26:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print returned BPM
|
|
|
|
fmt.Printf("%d BPM\n", heartRate)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getMotion(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
motionVals, err := client.Motion(c.Context)
|
2022-02-25 05:26:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Bool("shell") {
|
|
|
|
fmt.Printf(
|
|
|
|
"X=%d\nY=%d\nZ=%d\n",
|
|
|
|
motionVals.X,
|
|
|
|
motionVals.Y,
|
|
|
|
motionVals.Z,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return json.NewEncoder(os.Stdout).Encode(motionVals)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getSteps(c *cli.Context) error {
|
2022-05-01 22:22:28 +00:00
|
|
|
stepCount, err := client.StepCount(c.Context)
|
2022-02-25 05:26:40 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print returned BPM
|
|
|
|
fmt.Printf("%d Steps\n", stepCount)
|
|
|
|
return nil
|
|
|
|
}
|