Skip to content

Commit 67c05a3

Browse files
committed
Add support for streamdeck mini
1 parent 1cabaab commit 67c05a3

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

buttons/imagefile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ImageFileButton struct {
2121
// GetImageForButton is the interface implemention to get the button's image as an image.Image
2222
func (btn *ImageFileButton) GetImageForButton() image.Image {
2323
// TODO base the 96 on the image bounds
24-
newimg := image.NewRGBA(image.Rect(0, 0, 96, 96))
24+
newimg := image.NewRGBA(image.Rect(0, 0, 80, 80))
2525
draw.Draw(newimg, newimg.Bounds(), btn.img, image.Point{0, 0}, draw.Src)
2626
return newimg
2727
}
@@ -59,7 +59,7 @@ func (btn *ImageFileButton) loadImage() error {
5959
newimg, ok := img.(*image.RGBA)
6060
if !ok {
6161
// TODO base the 96 on the button size
62-
newimg = image.NewRGBA(image.Rect(0, 0, 96, 96))
62+
newimg = image.NewRGBA(image.Rect(0, 0, 80, 80))
6363
draw.Draw(newimg, newimg.Bounds(), img, image.Point{0, 0}, draw.Src)
6464
}
6565

devices/mini.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package devices
2+
3+
import (
4+
"image"
5+
6+
streamdeck "github.com/magicmonkey/go-streamdeck"
7+
)
8+
9+
var (
10+
miniName string
11+
miniButtonWidth uint
12+
miniButtonHeight uint
13+
miniImageReportPayloadLength uint
14+
miniImageReportHeaderLength uint
15+
miniImageReportLength uint
16+
)
17+
18+
// GetImageHeaderMini returns the USB comms header for a button image for the XL
19+
func GetImageHeaderMini(bytesRemaining uint, btnIndex uint, pageNumber uint) []byte {
20+
thisLength := uint(0)
21+
if miniImageReportPayloadLength < bytesRemaining {
22+
thisLength = miniImageReportPayloadLength
23+
} else {
24+
thisLength = bytesRemaining
25+
}
26+
header := []byte{'\x02', '\x07', byte(btnIndex)}
27+
if thisLength == bytesRemaining {
28+
header = append(header, '\x01')
29+
} else {
30+
header = append(header, '\x00')
31+
}
32+
33+
header = append(header, byte(thisLength&0xff))
34+
header = append(header, byte(thisLength>>8))
35+
36+
header = append(header, byte(pageNumber&0xff))
37+
header = append(header, byte(pageNumber>>8))
38+
39+
return header
40+
}
41+
42+
func init() {
43+
miniName = "Streamdeck Mini"
44+
miniButtonWidth = 80
45+
miniButtonHeight = 80
46+
miniImageReportLength = 1024
47+
miniImageReportHeaderLength = 16
48+
miniImageReportPayloadLength = miniImageReportLength - miniImageReportHeaderLength
49+
streamdeck.RegisterDevicetype(
50+
miniName, // Name
51+
image.Point{X: int(miniButtonWidth), Y: int(miniButtonHeight)}, // Width/height of a button
52+
0x63, // USB productID
53+
[]byte{'\x03', '\x02'}, // Reset packet
54+
6, // Number of buttons
55+
[]byte{'\x03', '\x08'}, // Set brightness packet preamble
56+
4, // Button read offset
57+
"JPEG", // Image format
58+
miniImageReportPayloadLength, // Amount of image payload allowed per USB packet
59+
GetImageHeaderMini, // Function to get the comms image header
60+
)
61+
}

image.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313

1414
"github.com/disintegration/gift"
15+
"golang.org/x/image/bmp"
1516
)
1617

1718
func resizeAndRotate(img image.Image, width, height int) image.Image {
@@ -30,14 +31,16 @@ func getImageForButton(img image.Image, btnFormat string) ([]byte, error) {
3031
switch btnFormat {
3132
case "JPEG":
3233
jpeg.Encode(&b, img, nil)
34+
case "BMP":
35+
bmp.Encode(&b, img)
3336
default:
3437
return nil, errors.New("Unknown button image format: " + btnFormat)
3538
}
3639
return b.Bytes(), nil
3740
}
3841

3942
func getSolidColourImage(colour color.Color) *image.RGBA {
40-
ButtonSize := 96
43+
ButtonSize := 80
4144
img := image.NewRGBA(image.Rect(0, 0, ButtonSize, ButtonSize))
4245
//colour := color.RGBA{red, green, blue, 0}
4346
draw.Draw(img, img.Bounds(), image.NewUniform(colour), image.Point{0, 0}, draw.Src)

0 commit comments

Comments
 (0)