|
| 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 | +} |
0 commit comments