speed.go 971 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package main
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. func NewSpeedCmd() *cobra.Command {
  7. return &cobra.Command{
  8. Use: "speed <val>",
  9. Short: "Set effect speed",
  10. Long: "Set the effect speed (0-255) and read it back, so a value the keyboard\n" +
  11. "rescales is reported instead of silently applied.",
  12. Args: cobra.ExactArgs(1),
  13. RunE: func(cmd *cobra.Command, args []string) error {
  14. val, err := ParseUint8(args[0])
  15. if err != nil {
  16. return err
  17. }
  18. zones, err := selectedZones()
  19. if err != nil {
  20. return err
  21. }
  22. proto, err := openRGBProtocol()
  23. if err != nil {
  24. return err
  25. }
  26. defer proto.Close()
  27. results, err := setSpeedVerified(proto, zones, val)
  28. if err != nil {
  29. return fmt.Errorf("set speed: %w", err)
  30. }
  31. if anyMismatch(results) {
  32. fmt.Fprintln(cmd.OutOrStdout(), formatResults("Speed", results))
  33. return nil
  34. }
  35. fmt.Fprintf(cmd.OutOrStdout(), "Speed set to %d\n", val)
  36. return nil
  37. },
  38. }
  39. }