| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package rgb
- import (
- "fmt"
- "os"
- "github.com/spf13/cobra"
- "github.com/wobkey/rgb/internal/rgb"
- "github.com/wobkey/rgb/internal/via"
- )
- func NewColorCmd() *cobra.Command {
- return &cobra.Command{
- Use: "color <hex>",
- Short: "Set solid color",
- Long: "Set the RGB color using a 6-digit hex code (e.g. \"ff0000\" for red).",
- Args: cobra.ExactArgs(1),
- Run: func(cmd *cobra.Command, args []string) {
- c, err := rgb.ParseHexColor(args[0])
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
- os.Exit(1)
- }
- proto, _, err := OpenDevice()
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
- os.Exit(1)
- }
- defer proto.Close()
- if err := proto.EnableHandshake(); err != nil {
- fmt.Fprintf(os.Stderr, "Handshake failed: %v\n", err)
- os.Exit(1)
- }
- if err := proto.SetValue(via.RGBLight, uint8(rgb.Mode), uint8(rgb.Static)); err != nil {
- fmt.Fprintf(os.Stderr, "Error setting mode to static: %v\n", err)
- os.Exit(1)
- }
- h, s, _ := c.HSV()
- if err := proto.SetValue(via.RGBLight, uint8(rgb.Hue), h); err != nil {
- fmt.Fprintf(os.Stderr, "Error setting hue: %v\n", err)
- os.Exit(1)
- }
- if err := proto.SetValue(via.RGBLight, uint8(rgb.Saturation), s); err != nil {
- fmt.Fprintf(os.Stderr, "Error setting saturation: %v\n", err)
- os.Exit(1)
- }
- fmt.Printf("Color set to %s (static mode)\n", args[0])
- },
- }
- }
|