@@ -12,13 +12,16 @@ const vendorID = 0x0fd9
12
12
13
13
// deviceType represents one of the various types of StreamDeck (mini/orig/orig2/xl)
14
14
type deviceType struct {
15
- name string
16
- imageSize image.Point
17
- usbProductID uint16
18
- resetPacket []byte
19
- numberOfButtons uint
20
- brightnessPacket []byte
21
- buttonReadOffset uint
15
+ name string
16
+ imageSize image.Point
17
+ usbProductID uint16
18
+ resetPacket []byte
19
+ numberOfButtons uint
20
+ brightnessPacket []byte
21
+ buttonReadOffset uint
22
+ imageFormat string
23
+ imagePayloadPerPage uint
24
+ imageHeaderFunc func (bytesRemaining uint , btnIndex uint , pageNumber uint ) []byte
22
25
}
23
26
24
27
var deviceTypes []deviceType
@@ -32,15 +35,21 @@ func RegisterDevicetype(
32
35
numberOfButtons uint ,
33
36
brightnessPacket []byte ,
34
37
buttonReadOffset uint ,
38
+ imageFormat string ,
39
+ imagePayloadPerPage uint ,
40
+ imageHeaderFunc func (bytesRemaining uint , btnIndex uint , pageNumber uint ) []byte ,
35
41
) {
36
42
d := deviceType {
37
- name : name ,
38
- imageSize : imageSize ,
39
- usbProductID : usbProductID ,
40
- resetPacket : resetPacket ,
41
- numberOfButtons : numberOfButtons ,
42
- brightnessPacket : brightnessPacket ,
43
- buttonReadOffset : buttonReadOffset ,
43
+ name : name ,
44
+ imageSize : imageSize ,
45
+ usbProductID : usbProductID ,
46
+ resetPacket : resetPacket ,
47
+ numberOfButtons : numberOfButtons ,
48
+ brightnessPacket : brightnessPacket ,
49
+ buttonReadOffset : buttonReadOffset ,
50
+ imageFormat : imageFormat ,
51
+ imagePayloadPerPage : imagePayloadPerPage ,
52
+ imageHeaderFunc : imageHeaderFunc ,
44
53
}
45
54
deviceTypes = append (deviceTypes , d )
46
55
}
@@ -180,7 +189,7 @@ func (d *Device) ResetComms() {
180
189
181
190
// WriteRawImageToButton takes an `image.Image` and writes it to the given button, after resizing and rotating the image to fit the button (for some reason the StreamDeck screens are all upside down)
182
191
func (d * Device ) WriteRawImageToButton (btnIndex int , rawImg image.Image ) error {
183
- img := resizeAndRotate (rawImg , 96 , 96 )
192
+ img := resizeAndRotate (rawImg , d . deviceType . imageSize . X , d . deviceType . imageSize . Y )
184
193
return d .rawWriteToButton (btnIndex , getImageAsJpeg (img ))
185
194
}
186
195
@@ -189,33 +198,24 @@ func (d *Device) rawWriteToButton(btnIndex int, rawImage []byte) error {
189
198
pageNumber := 0
190
199
bytesRemaining := len (rawImage )
191
200
192
- imageReportLength := 1024
193
- imageReportHeaderLength := 8
194
- imageReportPayloadLength := imageReportLength - imageReportHeaderLength
195
-
196
201
// Surely no image can be more than 20 packets...?
197
202
payloads := make ([][]byte , 20 )
198
203
199
204
for bytesRemaining > 0 {
205
+
206
+ header := d .deviceType .imageHeaderFunc (uint (bytesRemaining ), uint (btnIndex ), uint (pageNumber ))
207
+ imageReportLength := int (d .deviceType .imagePayloadPerPage )
208
+ imageReportHeaderLength := len (header )
209
+ imageReportPayloadLength := imageReportLength - imageReportHeaderLength
210
+
200
211
thisLength := 0
201
212
if imageReportPayloadLength < bytesRemaining {
202
213
thisLength = imageReportPayloadLength
203
214
} else {
204
215
thisLength = bytesRemaining
205
216
}
206
- bytesSent := pageNumber * imageReportPayloadLength
207
- header := []byte {'\x02' , '\x07' , byte (btnIndex )}
208
- if thisLength == bytesRemaining {
209
- header = append (header , '\x01' )
210
- } else {
211
- header = append (header , '\x00' )
212
- }
213
217
214
- header = append (header , byte (thisLength & 0xff ))
215
- header = append (header , byte (thisLength >> 8 ))
216
-
217
- header = append (header , byte (pageNumber & 0xff ))
218
- header = append (header , byte (pageNumber >> 8 ))
218
+ bytesSent := pageNumber * imageReportPayloadLength
219
219
220
220
payload := append (header , rawImage [bytesSent :(bytesSent + thisLength )]... )
221
221
padding := make ([]byte , imageReportLength - len (payload ))
0 commit comments