disable.go 779 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package rgb
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/spf13/cobra"
  6. "github.com/wobkey/rgb/internal/rgb"
  7. "github.com/wobkey/rgb/internal/via"
  8. )
  9. func NewDisableCmd() *cobra.Command {
  10. return &cobra.Command{
  11. Use: "disable",
  12. Short: "Disable RGB lighting",
  13. Run: func(cmd *cobra.Command, args []string) {
  14. proto, _, err := OpenDevice()
  15. if err != nil {
  16. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  17. os.Exit(1)
  18. }
  19. defer proto.Close()
  20. if err := proto.EnableHandshake(); err != nil {
  21. fmt.Fprintf(os.Stderr, "Handshake failed: %v\n", err)
  22. os.Exit(1)
  23. }
  24. if err := proto.SetValue(via.RGBLight, uint8(rgb.Enable), 0); err != nil {
  25. fmt.Fprintf(os.Stderr, "Error disabling RGB: %v\n", err)
  26. os.Exit(1)
  27. }
  28. fmt.Println("RGB disabled")
  29. },
  30. }
  31. }