Documentation
¶
Overview ¶
Package streamdeck controls Elgato Stream Deck hardware directly over USB HID without requiring CGO or the Elgato desktop software.
It supports the Original, Mini, Classic/MK.2, XL, Neo, Pedal, Plus, Plus XL, Studio, and known module variants. Call Devices to discover hardware, then Open, OpenBySerial, or OpenDevice to obtain an exclusively locked Deck.
A Deck starts its input reader when opened. Drain the event channels while it is in use, inspect Errors for a terminal USB read failure, and call Close to release the device. Done closes when the input reader has stopped. Display and settings methods serialize their USB writes, so independent goroutines may update different controls.
Key and dial indexes are zero based. Key zero is the top-left key and indexes proceed from left to right, then top to bottom. Model fields describe which optional controls and displays are available. Unsupported model-specific operations return an error.
Only one process can own a device at a time. The Elgato desktop application must release a Stream Deck before this package can open it.
Index ¶
- Constants
- Variables
- func Reconnect(ctx context.Context, serial string, interval time.Duration) <-chan Connection
- func WatchDevices(ctx context.Context, interval time.Duration) <-chan DeviceChange
- type Animation
- type Connection
- type Deck
- func (d *Deck) Clear() error
- func (d *Deck) ClearKey(key int) error
- func (d *Deck) Close() error
- func (d *Deck) DialEvents() <-chan DialEvent
- func (d *Deck) Done() <-chan struct{}
- func (d *Deck) Errors() <-chan error
- func (d *Deck) Events() <-chan KeyEvent
- func (d *Deck) FirmwareVersion() (string, error)
- func (d *Deck) Info() DeviceInfo
- func (d *Deck) PlayAnimation(ctx context.Context, key int, animation *Animation) error
- func (d *Deck) PlayGIF(ctx context.Context, key int, value *gif.GIF) error
- func (d *Deck) PrepareGIF(value *gif.GIF) (*Animation, error)
- func (d *Deck) Reset() error
- func (d *Deck) SerialNumber() (string, error)
- func (d *Deck) SetBrightness(percent int) error
- func (d *Deck) SetEncoderColor(encoder int, value color.Color) error
- func (d *Deck) SetEncoderRing(encoder int, colors []color.Color) error
- func (d *Deck) SetKeyColor(key int, value color.Color) error
- func (d *Deck) SetKeyImage(key int, img image.Image) error
- func (d *Deck) SetKeyImageData(key int, encoded []byte) error
- func (d *Deck) SetLCDColor(value color.Color) error
- func (d *Deck) SetLCDImage(img image.Image) error
- func (d *Deck) SetPanelImage(src image.Image) error
- func (d *Deck) SetScreenImage(img image.Image) error
- func (d *Deck) SetSleepTimeout(duration time.Duration) error
- func (d *Deck) SetTouchscreenImage(x, y int, img image.Image) error
- func (d *Deck) SetWindowImage(img image.Image) error
- func (d *Deck) ShowBackground(index byte) error
- func (d *Deck) SleepTimeout() (time.Duration, error)
- func (d *Deck) StoreBackground(index byte, img image.Image) error
- func (d *Deck) TouchEvents() <-chan TouchEvent
- func (d *Deck) UnitInfo() (UnitInfo, error)
- type DeviceChange
- type DeviceChangeKind
- type DeviceInfo
- type DialEvent
- type ImageFormat
- type KeyEvent
- type Model
- type TouchEvent
- type TouchType
- type UnitInfo
Constants ¶
const VendorID uint16 = 0x0fd9
VendorID is Elgato's USB vendor ID.
Variables ¶
var ( // ErrNoDevice is returned when no supported Stream Deck matches a request. ErrNoDevice = errors.New("streamdeck: no matching device found") // ErrClosed is returned when an operation is attempted on a closed deck. ErrClosed = errors.New("streamdeck: device is closed") )
var ( StreamDeckOriginal = gen1Model("Stream Deck Original", 0x0060, 3, 5, 72, 72) StreamDeckOriginalV2 = gen2Model("Stream Deck Original (2019)", 0x006d, 3, 5, 72, 72) StreamDeckMK2 = gen2Model("Stream Deck MK.2", 0x0080, 3, 5, 72, 72) StreamDeckMK2Module = gen2Model("Stream Deck MK.2 Module", 0x00b9, 3, 5, 72, 72) StreamDeckScissor = gen2Model("Stream Deck Scissor Keys", 0x00a5, 3, 5, 72, 72) StreamDeckMini = miniModel("Stream Deck Mini", 0x0063) StreamDeckMiniMK2 = miniModel("Stream Deck Mini MK.2", 0x0090) StreamDeckMiniModule = miniModel("Stream Deck Mini Module", 0x00b8) StreamDeckMiniDiscord = miniModel("Stream Deck Mini Discord", 0x00b3) StreamDeckXL = xlModel("Stream Deck XL", 0x006c) StreamDeckXLMK2 = xlModel("Stream Deck XL (2022)", 0x008f) StreamDeckXLModule = xlModel("Stream Deck XL Module", 0x00ba) StreamDeckNeo = Model{Name: "Stream Deck Neo", ProductID: 0x009a, Rows: 2, Columns: 4, KeyWidth: 96, KeyHeight: 96, KeyFormat: ImageFormatJPEG, TouchKeyCount: 2, ScreenWidth: 248, ScreenHeight: 58, LCDWidth: 480, LCDHeight: 320, /* contains filtered or unexported fields */} StreamDeckPedal = Model{Name: "Stream Deck Pedal", ProductID: 0x0086, Rows: 1, Columns: 3, /* contains filtered or unexported fields */} StreamDeckPlus = plusModel("Stream Deck +", 0x0084, 2, 4, 120, 120, 4, 800, 100, 0) StreamDeckPlusXL = plusModel("Stream Deck + XL", 0x00c6, 4, 9, 112, 112, 6, 1200, 100, 90) StreamDeckStudio = Model{Name: "Stream Deck Studio", ProductID: 0x00aa, Rows: 2, Columns: 16, KeyWidth: 80, KeyHeight: 120, KeyFormat: ImageFormatJPEG, DialCount: 2, /* contains filtered or unexported fields */} )
Functions ¶
func Reconnect ¶
Reconnect keeps opening a device after disconnects. An empty serial selects the first supported deck. Callers use each emitted Deck until its Errors channel closes, then wait for the next Connection.
func WatchDevices ¶
func WatchDevices(ctx context.Context, interval time.Duration) <-chan DeviceChange
WatchDevices polls HID discovery and reports hot-plug changes until ctx ends.
Types ¶
type Animation ¶
type Animation struct {
Frames [][]byte
Delays []time.Duration
Loops int // zero loops forever; positive values are total play counts
}
Animation contains device-native encoded frames that can be replayed without repeatedly resizing and encoding them.
type Connection ¶
Connection is emitted by Reconnect whenever a matching device is opened or an open attempt fails. A non-nil Deck replaces the previous connection.
type Deck ¶
type Deck struct {
// contains filtered or unexported fields
}
Deck is an exclusively opened Stream Deck.
func OpenBySerial ¶
OpenBySerial opens the supported Stream Deck with the requested serial.
func OpenDevice ¶
func OpenDevice(info DeviceInfo) (*Deck, error)
OpenDevice opens a device returned by Devices with an exclusive lock.
func (*Deck) DialEvents ¶
DialEvents returns dial push, release, and rotation events. Events may be dropped when its buffer is full so unused control types cannot block keys.
func (*Deck) Done ¶
func (d *Deck) Done() <-chan struct{}
Done closes after the input reader stops. It does not consume Errors and is useful for connection supervisors.
func (*Deck) Errors ¶
Errors reports a terminal background read error. The channel closes with Deck.
func (*Deck) Events ¶
Events returns key press and release events until the deck is closed. Events may be dropped when its buffer is full; callers should drain it continuously.
func (*Deck) FirmwareVersion ¶
FirmwareVersion returns the firmware version reported by the device.
func (*Deck) Info ¶
func (d *Deck) Info() DeviceInfo
Info returns the identity and model of the opened device.
func (*Deck) PlayAnimation ¶
PlayAnimation displays pre-encoded animation frames.
func (*Deck) PrepareGIF ¶
PrepareGIF composites GIF disposal frames and encodes them for this deck.
func (*Deck) SerialNumber ¶
SerialNumber reads the serial number from the device firmware.
func (*Deck) SetBrightness ¶
SetBrightness changes display brightness, clamped to the range 0..100.
func (*Deck) SetEncoderColor ¶
SetEncoderColor sets a Stream Deck Studio encoder knob LED.
func (*Deck) SetEncoderRing ¶
SetEncoderRing sets all 24 segments around a Stream Deck Studio encoder. Missing colors are treated as black; extra colors are ignored.
func (*Deck) SetKeyColor ¶
SetKeyColor fills one key with a solid color.
func (*Deck) SetKeyImage ¶
SetKeyImage scales an image to the key, applies the model transform, encodes it as the native JPEG or BMP format, and displays it. Key zero is top-left.
func (*Deck) SetKeyImageData ¶
SetKeyImageData writes a pre-encoded JPEG or BMP in the model's native format. This avoids re-encoding frames in animation loops.
func (*Deck) SetLCDColor ¶
SetLCDColor fills the complete LCD with a color using a feature command.
func (*Deck) SetLCDImage ¶
SetLCDImage uploads one JPEG across the physical LCD beneath all keys.
func (*Deck) SetPanelImage ¶
SetPanelImage displays one image across the complete key grid. The image is scaled to the logical key area; the physical gaps between keys remain visible.
func (*Deck) SetScreenImage ¶
SetScreenImage sets the Neo status-bar display.
func (*Deck) SetSleepTimeout ¶
SetSleepTimeout configures idle sleep. A zero duration disables sleep.
func (*Deck) SetTouchscreenImage ¶
SetTouchscreenImage displays an image in a rectangular region of a Plus touchscreen. Width and height are inferred from the source image bounds.
func (*Deck) SetWindowImage ¶
SetWindowImage sets the complete Neo status window or Plus touch window.
func (*Deck) ShowBackground ¶
ShowBackground displays a background previously uploaded with StoreBackground.
func (*Deck) SleepTimeout ¶
SleepTimeout returns the configured idle sleep duration.
func (*Deck) StoreBackground ¶
StoreBackground uploads a reusable full-LCD background on Classic and XL family devices. The available index count depends on device firmware.
func (*Deck) TouchEvents ¶
func (d *Deck) TouchEvents() <-chan TouchEvent
TouchEvents returns touchscreen tap, long-press, and drag events. Events may be dropped when its buffer is full so unused control types cannot block keys.
type DeviceChange ¶
type DeviceChange struct {
Kind DeviceChangeKind
Info DeviceInfo
Err error
}
DeviceChange is emitted by WatchDevices. Existing devices are reported as connected when the watcher starts.
type DeviceChangeKind ¶
type DeviceChangeKind uint8
DeviceChangeKind identifies a connected or disconnected device.
const ( DeviceConnected DeviceChangeKind = iota + 1 DeviceDisconnected )
type DeviceInfo ¶
DeviceInfo identifies a supported attached Stream Deck.
func Devices ¶
func Devices() ([]DeviceInfo, error)
Devices returns all attached Stream Decks supported by this package.
type DialEvent ¶
DialEvent reports a dial press transition or rotation. Ticks is signed and nonzero for rotations; Pressed is used for push/release events.
type ImageFormat ¶
type ImageFormat string
ImageFormat is the image encoding accepted by a device display.
const ( ImageFormatNone ImageFormat = "" ImageFormatJPEG ImageFormat = "JPEG" ImageFormatBMP ImageFormat = "BMP" )
type Model ¶
type Model struct {
Name string
ProductID uint16
Rows int
Columns int
KeyWidth int
KeyHeight int
KeyFormat ImageFormat
DialCount int
TouchKeyCount int
TouchscreenWidth int
TouchscreenHeight int
ScreenWidth int
ScreenHeight int
LCDWidth int
LCDHeight int
// contains filtered or unexported fields
}
Model describes the physical layout and capabilities of a Stream Deck.
func (Model) HasDisplay ¶
HasDisplay reports whether the model has images behind its keys.
func (Model) InputCount ¶
InputCount includes Neo touch buttons in addition to its LCD keys.
type TouchEvent ¶
TouchEvent reports touchscreen coordinates. EndX and EndY are set for drags.
type TouchType ¶
type TouchType uint8
TouchType identifies a tap, long press, or drag on a touchscreen.
type UnitInfo ¶
type UnitInfo struct {
Rows, Columns int
KeyWidth, KeyHeight int
LCDWidth, LCDHeight int
BitsPerPixel int
ColorScheme int
KeyGalleryImages int
LCDGalleryImages int
DemoFrames int
}
UnitInfo is the geometry and image-gallery capacity reported by main-protocol firmware. Some firmware versions omit the trailing fields.