light.go 759 B

1234567891011121314151617181920212223242526272829
  1. package cmd
  2. import (
  3. "github.com/spf13/cobra"
  4. "lianlinux/core"
  5. )
  6. // lightCmd represents the light command
  7. var lightCmd = &cobra.Command{
  8. Use: "light",
  9. Short: "Control RGB lights",
  10. Run: func(cmd *cobra.Command, args []string) {
  11. mode, _ := cmd.Flags().GetString("mode")
  12. r, _ := cmd.Flags().GetInt("red")
  13. g, _ := cmd.Flags().GetInt("green")
  14. b, _ := cmd.Flags().GetInt("blue")
  15. core.SetLightMode(*core.Devs[0], mode, []byte{byte(r), byte(b), byte(g)}...)
  16. },
  17. }
  18. func init() {
  19. rootCmd.AddCommand(lightCmd)
  20. lightCmd.PersistentFlags().String("mode", "", "RGB light mode")
  21. lightCmd.PersistentFlags().Int("red", 0, "Red color")
  22. lightCmd.PersistentFlags().Int("green", 0, "Green color")
  23. lightCmd.PersistentFlags().Int("blue", 0, "Blue color")
  24. }