Skip to content

Commit 0cb85a3

Browse files
committed
Started to build a way to separate the device types, to allow for different Streamdecks
1 parent d2d25ee commit 0cb85a3

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

comms.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,41 @@ import (
88
"github.com/karalabe/hid"
99
)
1010

11-
const vendorID = 4057
12-
const productID = 0x6c
11+
const vendorID = 0x0fd9
12+
13+
// deviceType represents one of the various types of StreamDeck (mini/orig/orig2/xl)
14+
type deviceType struct {
15+
name string
16+
imageSize image.Point
17+
usbProductID uint16
18+
resetPacket []byte
19+
numberOfButtons uint
20+
}
21+
22+
var deviceTypes []deviceType
23+
24+
// RegisterDevicetype allows the declaration of a new type of device, intended for use by subpackage "devices"
25+
func RegisterDevicetype(
26+
name string,
27+
imageSize image.Point,
28+
usbProductID uint16,
29+
resetPacket []byte,
30+
numberOfButtons uint,
31+
) {
32+
d := deviceType{
33+
name: name,
34+
imageSize: imageSize,
35+
usbProductID: usbProductID,
36+
resetPacket: resetPacket,
37+
numberOfButtons: numberOfButtons,
38+
}
39+
deviceTypes = append(deviceTypes, d)
40+
}
1341

1442
// Device is a struct which represents an actual Streamdeck device, and holds its reference to the USB HID device
1543
type Device struct {
1644
fd *hid.Device
45+
deviceType deviceType
1746
buttonPressListeners []func(int, *Device, error)
1847
}
1948

@@ -29,16 +58,23 @@ func OpenWithoutReset() (*Device, error) {
2958

3059
// Opens a new StreamdeckXL device, and returns a handle
3160
func rawOpen(reset bool) (*Device, error) {
32-
devices := hid.Enumerate(vendorID, productID)
61+
devices := hid.Enumerate(vendorID, 0)
3362
if len(devices) == 0 {
34-
return nil, errors.New("no stream deck device found")
63+
return nil, errors.New("No elgato devices found")
3564
}
65+
66+
retval := &Device{}
3667
id := 0
68+
// Iterate over the known device types, matching to product ID
69+
for _, devType := range deviceTypes {
70+
if devices[id].ProductID == devType.usbProductID {
71+
retval.deviceType = devType
72+
}
73+
}
3774
dev, err := devices[id].Open()
3875
if err != nil {
3976
return nil, err
4077
}
41-
retval := &Device{}
4278
retval.fd = dev
4379
if reset {
4480
retval.ResetComms()

devices/xl.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package devices
2+
3+
import (
4+
"image"
5+
6+
streamdeck "github.com/magicmonkey/go-streamdeck"
7+
)
8+
9+
func init() {
10+
streamdeck.RegisterDevicetype(
11+
"Streamdeck XL",
12+
image.Point{X: 96, Y: 96},
13+
0x6c, // productID
14+
[]byte{'\x03', '\x02'}, // reset packet
15+
32,
16+
)
17+
}

examples/client/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/magicmonkey/go-streamdeck/actionhandlers"
99
"github.com/magicmonkey/go-streamdeck/buttons"
1010
"github.com/magicmonkey/go-streamdeck/decorators"
11+
_ "github.com/magicmonkey/go-streamdeck/devices"
1112
)
1213

1314
func main() {

0 commit comments

Comments
 (0)