| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package rgb
- import (
- "fmt"
- "strings"
- "github.com/spf13/cobra"
- intrgb "github.com/wobkey/rgb/internal/rgb"
- "github.com/wobkey/rgb/internal/via"
- )
- func resolveEffectTargets(name string, zones []intrgb.Zone) ([]intrgb.EffectTarget, []intrgb.Zone, error) {
- if name == "static" {
- name = "solid"
- }
- return intrgb.ResolveEffect(name, zones)
- }
- func NewEffectCmd() *cobra.Command {
- return &cobra.Command{
- Use: "effect <name>",
- Short: "Set RGB effect",
- Long: "Set the RGB lighting effect on the connected keyboard.",
- Args: cobra.ExactArgs(1),
- RunE: func(cmd *cobra.Command, args []string) error {
- zones, err := selectedZones()
- if err != nil {
- return err
- }
- targets, skipped, err := resolveEffectTargets(args[0], zones)
- if err != nil {
- return err
- }
- if len(skipped) > 0 {
- skippedNames := make([]string, len(skipped))
- for i, zone := range skipped {
- skippedNames[i] = string(zone)
- }
- fmt.Fprintf(cmd.ErrOrStderr(), "Warning: effect not supported on zone(s): %s\n", strings.Join(skippedNames, ", "))
- }
- proto, err := openRGBProtocol()
- if err != nil {
- return err
- }
- defer proto.Close()
- for _, target := range targets {
- if err := proto.SetValue(via.LEDType(target.Zone.Channel()), uint8(intrgb.EffectID), target.ID); err != nil {
- return fmt.Errorf("set effect on %s: %w", target.Zone, err)
- }
- }
- fmt.Fprintf(cmd.OutOrStdout(), "Effect set to %q\n", args[0])
- return nil
- },
- }
- }
|