Skip to content

Commit 6828f63

Browse files
committed
Update devices with more details and dynamic code
* Each device now also reports the number of rows and colums for each button. This could be used by GUI applications to easily display the layout. * New devices.go file containing functions shared by each device's go file. * Dynamically determine the Reset and Brightness packets
1 parent ea3d7d7 commit 6828f63

File tree

5 files changed

+100
-7
lines changed

5 files changed

+100
-7
lines changed

comms.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type deviceType struct {
1818
usbProductID uint16
1919
resetPacket []byte
2020
numberOfButtons uint
21+
buttonRows uint
22+
buttonCols uint
2123
brightnessPacket []byte
2224
buttonReadOffset uint
2325
imageFormat string
@@ -34,6 +36,8 @@ func RegisterDevicetype(
3436
usbProductID uint16,
3537
resetPacket []byte,
3638
numberOfButtons uint,
39+
buttonRows uint,
40+
buttonCols uint,
3741
brightnessPacket []byte,
3842
buttonReadOffset uint,
3943
imageFormat string,
@@ -46,6 +50,8 @@ func RegisterDevicetype(
4650
usbProductID: usbProductID,
4751
resetPacket: resetPacket,
4852
numberOfButtons: numberOfButtons,
53+
buttonRows: buttonRows,
54+
buttonCols: buttonCols,
4955
brightnessPacket: brightnessPacket,
5056
buttonReadOffset: buttonReadOffset,
5157
imageFormat: imageFormat,

devices/mini.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,26 @@ func init() {
5858
miniButtonWidth = 80
5959
miniButtonHeight = 80
6060
miniImageReportPayloadLength = 1024
61+
// Get reset packet from device name
62+
reset, err := resetPacket(miniName)
63+
if err != nil {
64+
panic(err)
65+
}
66+
// Get brightness packet from device name
67+
brightness, err := brightnessPacket(miniName)
68+
if err != nil {
69+
panic(err)
70+
}
6171
streamdeck.RegisterDevicetype(
6272
miniName, // Name
6373
image.Point{X: int(miniButtonWidth), Y: int(miniButtonHeight)}, // Width/height of a button
6474
0x63, // USB productID
65-
[]byte{0x0B, 0x63}, // Reset packet
75+
reset, // Reset packet
6676
6, // Number of buttons
67-
[]byte{0x05, 0x55, 0xaa, 0xd1, 0x01}, // Reset packet
68-
0, // Button read offset
77+
2, // Number of rows
78+
3, // Number of cols
79+
brightness, // Reset packet
80+
1, // Button read offset
6981
"BMP", // Image format
7082
miniImageReportPayloadLength, // Amount of image payload allowed per USB packet
7183
GetImageHeaderMini, // Function to get the comms image header

devices/origv2.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,25 @@ func init() {
4242
ov2ButtonWidth = 72
4343
ov2ButtonHeight = 72
4444
ov2ImageReportPayloadLength = 1024
45+
// Get reset packet based on device
46+
reset, err := resetPacket(ov2Name)
47+
if err != nil {
48+
panic(err)
49+
}
50+
// Get brightness packet based on device
51+
brightness, err := brightnessPacket(ov2Name)
52+
if err != nil {
53+
panic(err)
54+
}
4555
streamdeck.RegisterDevicetype(
4656
ov2Name, // Name
4757
image.Point{X: int(ov2ButtonWidth), Y: int(ov2ButtonHeight)}, // Width/height of a button
4858
0x6d, // USB productID
49-
[]byte{'\x03', '\x02'}, // Reset packet
59+
reset, // Reset packet
5060
15, // Number of buttons
51-
[]byte{'\x03', '\x08'}, // Set brightness packet preamble
61+
3, // Number of rows
62+
5, // Number of columns
63+
brightness, // Set brightness packet preamble
5264
4, // Button read offset
5365
"JPEG", // Image format
5466
ov2ImageReportPayloadLength, // Amount of image payload allowed per USB packet

devices/shared.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package devices
2+
3+
import "errors"
4+
5+
func resetPacket(device string) ([]byte, error) {
6+
var size int
7+
var header []byte
8+
9+
switch device {
10+
case "Streamdeck XL", "Streamdeck (original v2)":
11+
size = 32
12+
header = []byte{0x03, 0x02}
13+
case "Streamdeck Mini":
14+
size = 17
15+
header = []byte{0x0b, 0x63}
16+
default:
17+
return nil, errors.New("Device not supported!")
18+
}
19+
20+
b := make([]byte, size)
21+
b[0] = header[0]
22+
b[1] = header[1]
23+
return b, nil
24+
}
25+
26+
func brightnessPacket(device string) ([]byte, error) {
27+
var size int
28+
var header []byte
29+
30+
switch device {
31+
case "Streamdeck XL", "Streamdeck (original v2)":
32+
size = 32
33+
header = []byte{0x03, 0x08}
34+
case "Streamdeck Mini":
35+
size = 17
36+
header = []byte{0x05, 0x55, 0xaa, 0xd1, 0x01}
37+
default:
38+
return nil, errors.New("Device is not supported!")
39+
}
40+
41+
b := make([]byte, size)
42+
b[0] = header[0]
43+
b[1] = header[1]
44+
if device == "Streamdeck Mini" {
45+
b[2] = header[2]
46+
b[3] = header[3]
47+
b[4] = header[4]
48+
}
49+
return b, nil
50+
}
51+

devices/xl.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,25 @@ func init() {
4242
xlButtonWidth = 96
4343
xlButtonHeight = 96
4444
xlImageReportPayloadLength = 1024
45+
// Get reset packet from device name
46+
reset, err := resetPacket(xlName)
47+
if err != nil {
48+
panic(err)
49+
}
50+
// Get brightness packet from device name
51+
brightness, err := brightnessPacket(xlName)
52+
if err != nil {
53+
panic(err)
54+
}
4555
streamdeck.RegisterDevicetype(
4656
xlName, // Name
4757
image.Point{X: int(xlButtonWidth), Y: int(xlButtonHeight)}, // Width/height of a button
4858
0x6c, // USB productID
49-
[]byte{'\x03', '\x02'}, // Reset packet
59+
reset, // Reset packet
5060
32, // Number of buttons
51-
[]byte{'\x03', '\x08'}, // Set brightness packet preamble
61+
4, // Number of rows
62+
8, // Number of cols
63+
brightness, // Set brightness packet preamble
5264
4, // Button read offset
5365
"JPEG", // Image format
5466
xlImageReportPayloadLength, // Amount of image payload allowed per USB packet

0 commit comments

Comments
 (0)