Browse Source

Apply RGB color to all Impact 80 zones

Paul Klumpp 2 weeks ago
parent
commit
ef04b6e1ea
3 changed files with 30 additions and 2 deletions
  1. 1 2
      cmd/wobkey/rgb/color.go
  2. 9 0
      internal/via/protocol.go
  3. 20 0
      internal/via/protocol_test.go

+ 1 - 2
cmd/wobkey/rgb/color.go

@@ -6,7 +6,6 @@ import (
 
 	"github.com/spf13/cobra"
 	"github.com/wobkey/rgb/internal/rgb"
-	"github.com/wobkey/rgb/internal/via"
 )
 
 func NewColorCmd() *cobra.Command {
@@ -30,7 +29,7 @@ func NewColorCmd() *cobra.Command {
 			defer proto.Close()
 
 			h, s, _ := c.HSV()
-			if err := proto.SetColor(via.RGBLight, h, s); err != nil {
+			if err := proto.SetLightingColor(h, s); err != nil {
 				fmt.Fprintf(os.Stderr, "Error setting color: %v\n", err)
 				os.Exit(1)
 			}

+ 9 - 0
internal/via/protocol.go

@@ -105,6 +105,15 @@ func (p *Protocol) EnableLighting() error {
 	return nil
 }
 
+func (p *Protocol) SetLightingColor(hue uint8, saturation uint8) error {
+	for _, channel := range []LEDType{RGBLight, RGBMatrix, SideLight} {
+		if err := p.SetColor(channel, hue, saturation); err != nil {
+			return err
+		}
+	}
+	return nil
+}
+
 func (p *Protocol) SetColor(ledType LEDType, hue uint8, saturation uint8) error {
 	report := make([]byte, 32)
 	report[0] = byte(CustomSet)

+ 20 - 0
internal/via/protocol_test.go

@@ -73,6 +73,26 @@ func TestSetValueConsumesQMKResponse(t *testing.T) {
 	}
 }
 
+func TestSetLightingColorUsesAllImpact80Channels(t *testing.T) {
+	transport := &fakeTransport{}
+	protocol := Protocol{handle: transport}
+
+	if err := protocol.SetLightingColor(0x55, 0xff); err != nil {
+		t.Fatalf("SetLightingColor() error = %v", err)
+	}
+
+	wantChannels := []byte{0x02, 0x03, 0x04}
+	if len(transport.reports) != len(wantChannels) {
+		t.Fatalf("SendReport() calls = %d, want %d", len(transport.reports), len(wantChannels))
+	}
+	for i, channel := range wantChannels {
+		report := transport.reports[i]
+		if report[0] != 0x07 || report[1] != channel || report[2] != 0x04 || report[3] != 0x55 || report[4] != 0xff {
+			t.Errorf("color report %d = %v, want channel 0x%02x hue 0x55 saturation 0xff", i, report, channel)
+		}
+	}
+}
+
 func TestSetColorUsesQMKColorValue(t *testing.T) {
 	transport := &fakeTransport{}
 	protocol := Protocol{handle: transport}