@@ -8,12 +8,41 @@ import (
8
8
"github.com/karalabe/hid"
9
9
)
10
10
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
+ }
13
41
14
42
// Device is a struct which represents an actual Streamdeck device, and holds its reference to the USB HID device
15
43
type Device struct {
16
44
fd * hid.Device
45
+ deviceType deviceType
17
46
buttonPressListeners []func (int , * Device , error )
18
47
}
19
48
@@ -29,16 +58,23 @@ func OpenWithoutReset() (*Device, error) {
29
58
30
59
// Opens a new StreamdeckXL device, and returns a handle
31
60
func rawOpen (reset bool ) (* Device , error ) {
32
- devices := hid .Enumerate (vendorID , productID )
61
+ devices := hid .Enumerate (vendorID , 0 )
33
62
if len (devices ) == 0 {
34
- return nil , errors .New ("no stream deck device found" )
63
+ return nil , errors .New ("No elgato devices found" )
35
64
}
65
+
66
+ retval := & Device {}
36
67
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
+ }
37
74
dev , err := devices [id ].Open ()
38
75
if err != nil {
39
76
return nil , err
40
77
}
41
- retval := & Device {}
42
78
retval .fd = dev
43
79
if reset {
44
80
retval .ResetComms ()
0 commit comments