@@ -78,6 +78,51 @@ func OpenWithoutReset() (*Device, error) {
78
78
return rawOpen (false )
79
79
}
80
80
81
+ // Open a Streamdeck device with a specific ProductID
82
+ func OpenWithID (productID uint16 ) (* Device , error ) {
83
+ return rawOpenWithID (true , productID )
84
+ }
85
+
86
+ // Opens a new Streamdeck device, and returns a handle
87
+ func rawOpenWithID (reset bool , productID uint16 ) (* Device , error ) {
88
+ devices := hid .Enumerate (vendorID , 0 )
89
+ if len (devices ) == 0 {
90
+ return nil , errors .New ("No elgato devices found" )
91
+ }
92
+
93
+ retval := & Device {}
94
+ deviceConnected := false
95
+ for _ , device := range devices {
96
+ if device .ProductID != productID {
97
+ continue
98
+ }
99
+
100
+ for _ , devType := range deviceTypes {
101
+ if device .ProductID == devType .usbProductID {
102
+ retval .deviceType = devType
103
+ dev , err := device .Open ()
104
+ if err != nil {
105
+ return nil , err
106
+ }
107
+ retval .fd = dev
108
+ if reset {
109
+ retval .ResetComms ()
110
+ }
111
+ go retval .buttonPressListener ()
112
+ return retval , nil
113
+ }
114
+ }
115
+
116
+ deviceConnected = true
117
+ break
118
+ }
119
+ if ! deviceConnected {
120
+ return nil , errors .New ("No device connected with given product ID." )
121
+ }
122
+
123
+ return nil , errors .New ("No device registered for requested product ID." )
124
+ }
125
+
81
126
// Opens a new StreamdeckXL device, and returns a handle
82
127
func rawOpen (reset bool ) (* Device , error ) {
83
128
devices := hid .Enumerate (vendorID , 0 )
@@ -137,12 +182,12 @@ func (d *Device) SetBrightness(pct int) error {
137
182
}
138
183
139
184
// GetButtonImageSize returns the size of the images to uploaded to the buttons
140
- func (d * Device ) GetButtonImageSize () image.Point {
185
+ func (d * Device ) GetButtonImageSize () image.Point {
141
186
return d .deviceType .imageSize
142
187
}
143
188
144
189
// GetNumButtonsOnDevice returns the number of button this device has
145
- func (d * Device ) GetNumButtonsOnDevice () uint {
190
+ func (d * Device ) GetNumButtonsOnDevice () uint {
146
191
return d .deviceType .numberOfButtons
147
192
}
148
193
0 commit comments