forked from Elara6331/itd
		
	Fix bug where itctl could not be killed
This commit is contained in:
		| @@ -14,19 +14,22 @@ func watchHeart(c *cli.Context) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for heartRate := range heartCh { | 	for { | ||||||
| 		if c.Bool("json") { | 		select { | ||||||
| 			json.NewEncoder(os.Stdout).Encode( | 		case heartRate := <-heartCh: | ||||||
| 				map[string]uint8{"heartRate": heartRate}, | 			if c.Bool("json") { | ||||||
| 			) | 				json.NewEncoder(os.Stdout).Encode( | ||||||
| 		} else if c.Bool("shell") { | 					map[string]uint8{"heartRate": heartRate}, | ||||||
| 			fmt.Printf("HEART_RATE=%d\n", heartRate) | 				) | ||||||
| 		} else { | 			} else if c.Bool("shell") { | ||||||
| 			fmt.Println(heartRate, "BPM") | 				fmt.Printf("HEART_RATE=%d\n", heartRate) | ||||||
|  | 			} else { | ||||||
|  | 				fmt.Println(heartRate, "BPM") | ||||||
|  | 			} | ||||||
|  | 		case <-c.Done(): | ||||||
|  | 			return nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func watchBattLevel(c *cli.Context) error { | func watchBattLevel(c *cli.Context) error { | ||||||
| @@ -35,19 +38,22 @@ func watchBattLevel(c *cli.Context) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for battLevel := range battLevelCh { | 	for { | ||||||
| 		if c.Bool("json") { | 		select { | ||||||
| 			json.NewEncoder(os.Stdout).Encode( | 		case battLevel := <-battLevelCh: | ||||||
| 				map[string]uint8{"battLevel": battLevel}, | 			if c.Bool("json") { | ||||||
| 			) | 				json.NewEncoder(os.Stdout).Encode( | ||||||
| 		} else if c.Bool("shell") { | 					map[string]uint8{"battLevel": battLevel}, | ||||||
| 			fmt.Printf("BATTERY_LEVEL=%d\n", battLevel) | 				) | ||||||
| 		} else { | 			} else if c.Bool("shell") { | ||||||
| 			fmt.Printf("%d%%\n", battLevel) | 				fmt.Printf("BATTERY_LEVEL=%d\n", battLevel) | ||||||
|  | 			} else { | ||||||
|  | 				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,19 +62,22 @@ func watchStepCount(c *cli.Context) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for stepCount := range stepCountCh { | 	for { | ||||||
| 		if c.Bool("json") { | 		select { | ||||||
| 			json.NewEncoder(os.Stdout).Encode( | 		case stepCount := <-stepCountCh: | ||||||
| 				map[string]uint32{"stepCount": stepCount}, | 			if c.Bool("json") { | ||||||
| 			) | 				json.NewEncoder(os.Stdout).Encode( | ||||||
| 		} else if c.Bool("shell") { | 					map[string]uint32{"stepCount": stepCount}, | ||||||
| 			fmt.Printf("STEP_COUNT=%d\n", stepCount) | 				) | ||||||
| 		} else { | 			} else if c.Bool("shell") { | ||||||
| 			fmt.Println(stepCount, "Steps") | 				fmt.Printf("STEP_COUNT=%d\n", stepCount) | ||||||
|  | 			} else { | ||||||
|  | 				fmt.Println(stepCount, "Steps") | ||||||
|  | 			} | ||||||
|  | 		case <-c.Done(): | ||||||
|  | 			return nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil |  | ||||||
| } | } | ||||||
|  |  | ||||||
| func watchMotion(c *cli.Context) error { | func watchMotion(c *cli.Context) error { | ||||||
| @@ -77,20 +86,23 @@ func watchMotion(c *cli.Context) error { | |||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for motionVals := range motionCh { | 	for { | ||||||
| 		if c.Bool("json") { | 		select { | ||||||
| 			json.NewEncoder(os.Stdout).Encode(motionVals) | 		case motionVals := <-motionCh: | ||||||
| 		} else if c.Bool("shell") { | 			if c.Bool("json") { | ||||||
| 			fmt.Printf( | 				json.NewEncoder(os.Stdout).Encode(motionVals) | ||||||
| 				"X=%d\nY=%d\nZ=%d\n", | 			} else if c.Bool("shell") { | ||||||
| 				motionVals.X, | 				fmt.Printf( | ||||||
| 				motionVals.Y, | 					"X=%d\nY=%d\nZ=%d\n", | ||||||
| 				motionVals.Z, | 					motionVals.X, | ||||||
| 			) | 					motionVals.Y, | ||||||
| 		} else { | 					motionVals.Z, | ||||||
| 			fmt.Println(motionVals) | 				) | ||||||
|  | 			} else { | ||||||
|  | 				fmt.Println(motionVals) | ||||||
|  | 			} | ||||||
|  | 		case <-c.Done(): | ||||||
|  | 			return nil | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	return nil |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1 +1 @@ | |||||||
| unknown | r150.78b5ca1 | ||||||
		Reference in New Issue
	
	Block a user