speed.go 860 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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 NewSpeedCmd() *cobra.Command {
  10. return &cobra.Command{
  11. Use: "speed <val>",
  12. Short: "Set effect speed",
  13. Long: "Set the RGB effect speed value (0-255).",
  14. Args: cobra.ExactArgs(1),
  15. Run: func(cmd *cobra.Command, args []string) {
  16. val, err := ParseUint8(args[0])
  17. if err != nil {
  18. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  19. os.Exit(1)
  20. }
  21. proto, _, err := OpenDevice()
  22. if err != nil {
  23. fmt.Fprintf(os.Stderr, "Error: %v\n", err)
  24. os.Exit(1)
  25. }
  26. defer proto.Close()
  27. if err := proto.SetValue(via.RGBLight, uint8(rgb.Speed), val); err != nil {
  28. fmt.Fprintf(os.Stderr, "Error setting speed: %v\n", err)
  29. os.Exit(1)
  30. }
  31. fmt.Printf("Speed set to %d\n", val)
  32. },
  33. }
  34. }