Skip to content

Commit afda22f

Browse files
committed
Added brightness packet to the device type definition
1 parent de283e1 commit afda22f

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

comms.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@ const vendorID = 0x0fd9
1212

1313
// deviceType represents one of the various types of StreamDeck (mini/orig/orig2/xl)
1414
type deviceType struct {
15-
name string
16-
imageSize image.Point
17-
usbProductID uint16
18-
resetPacket []byte
19-
numberOfButtons uint
15+
name string
16+
imageSize image.Point
17+
usbProductID uint16
18+
resetPacket []byte
19+
numberOfButtons uint
20+
brightnessPacket []byte
2021
}
2122

2223
var deviceTypes []deviceType
@@ -28,13 +29,15 @@ func RegisterDevicetype(
2829
usbProductID uint16,
2930
resetPacket []byte,
3031
numberOfButtons uint,
32+
brightnessPacket []byte,
3133
) {
3234
d := deviceType{
33-
name: name,
34-
imageSize: imageSize,
35-
usbProductID: usbProductID,
36-
resetPacket: resetPacket,
37-
numberOfButtons: numberOfButtons,
35+
name: name,
36+
imageSize: imageSize,
37+
usbProductID: usbProductID,
38+
resetPacket: resetPacket,
39+
numberOfButtons: numberOfButtons,
40+
brightnessPacket: brightnessPacket,
3841
}
3942
deviceTypes = append(deviceTypes, d)
4043
}
@@ -103,13 +106,15 @@ func (d *Device) SetBrightness(pct int) {
103106
pct = 100
104107
}
105108

106-
payload := []byte{'\x03', '\x08', byte(pct)}
109+
preamble := d.deviceType.brightnessPacket
110+
payload := append(preamble, byte(pct))
107111
d.fd.SendFeatureReport(payload)
108112
}
109113

110114
// ClearButtons writes a black square to all buttons
111115
func (d *Device) ClearButtons() {
112-
for i := 0; i < 32; i++ {
116+
numButtons := int(d.deviceType.numberOfButtons)
117+
for i := 0; i < numButtons; i++ {
113118
d.WriteColorToButton(i, color.Black)
114119
}
115120
}

devices/xl.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88

99
func init() {
1010
streamdeck.RegisterDevicetype(
11-
"Streamdeck XL",
12-
image.Point{X: 96, Y: 96},
13-
0x6c, // productID
14-
[]byte{'\x03', '\x02'}, // reset packet
15-
32,
11+
"Streamdeck XL", // Name
12+
image.Point{X: 96, Y: 96}, // Width/height of a button
13+
0x6c, // USB productID
14+
[]byte{'\x03', '\x02'}, // Reset packet
15+
32, // Number of buttons
16+
[]byte{'\x03', '\x08'}, // Set brightness packet preamble
1617
)
1718
}

0 commit comments

Comments
 (0)