Fix bug where itctl could not be killed

This commit is contained in:
Elara 2022-05-01 20:32:59 -07:00
parent 78b5ca1de8
commit 1e0f1c5b76
2 changed files with 60 additions and 48 deletions

View File

@ -14,7 +14,9 @@ func watchHeart(c *cli.Context) error {
return err return err
} }
for heartRate := range heartCh { for {
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},
@ -24,9 +26,10 @@ func watchHeart(c *cli.Context) error {
} else { } else {
fmt.Println(heartRate, "BPM") fmt.Println(heartRate, "BPM")
} }
} case <-c.Done():
return nil return nil
}
}
} }
func watchBattLevel(c *cli.Context) error { func watchBattLevel(c *cli.Context) error {
@ -35,7 +38,9 @@ func watchBattLevel(c *cli.Context) error {
return err return err
} }
for battLevel := range battLevelCh { for {
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},
@ -45,9 +50,10 @@ func watchBattLevel(c *cli.Context) error {
} else { } else {
fmt.Printf("%d%%\n", battLevel) fmt.Printf("%d%%\n", battLevel)
} }
} case <-c.Done():
return nil return nil
}
}
} }
func watchStepCount(c *cli.Context) error { func watchStepCount(c *cli.Context) error {
@ -56,7 +62,9 @@ func watchStepCount(c *cli.Context) error {
return err return err
} }
for stepCount := range stepCountCh { for {
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},
@ -66,9 +74,10 @@ func watchStepCount(c *cli.Context) error {
} else { } else {
fmt.Println(stepCount, "Steps") fmt.Println(stepCount, "Steps")
} }
} case <-c.Done():
return nil return nil
}
}
} }
func watchMotion(c *cli.Context) error { func watchMotion(c *cli.Context) error {
@ -77,7 +86,9 @@ func watchMotion(c *cli.Context) error {
return err return err
} }
for motionVals := range motionCh { for {
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") {
@ -90,7 +101,8 @@ func watchMotion(c *cli.Context) error {
} else { } else {
fmt.Println(motionVals) fmt.Println(motionVals)
} }
} case <-c.Done():
return nil return nil
}
}
} }

View File

@ -1 +1 @@
unknown r150.78b5ca1