zig-streamdeck #
A Zig library for driving Elgato Stream Deck devices: enumerating the decks attached to a machine, setting the image on each key, changing the brightness, and reading the events the device sends when a key is pressed, an encoder is turned, or the touchscreen is touched.
What this library knows about the hardware comes from Elgato's own HID documentation where that covers a model, from two independent reverse-engineered implementations where it does not, and from running real devices wherever one was to hand. Each row of the table below says which.
Most models plug into USB and are driven over HID. The Stream Deck Studio and
the Stream Deck Network Dock do not: they take Ethernet, and are driven over
TCP. Both are the same StreamDeck here — the network carries the very same
HID reports, so the key tables, the image paging and the event decoding are
written once and do not know which they are talking to. See
Networked devices.
It talks to the hardware through zig-hidapi,
which is pure Zig with backends for Linux, FreeBSD, Windows and macOS, so there
is no C hidapi to link against. Every blocking operation takes a std.Io and is dispatched
through the caller's I/O implementation rather than blocking a thread outright.
This is a work in progress. The tree builds and its tests pass, and the device tables, key image encoding and event decoding are largely in place, but the API is not settled and almost none of it has been exercised against real hardware. Expect it to move under you.
Images are drawn on a z2d Surface and
written out by z2dimg, which encodes a
surface straight to BMP or JPEG. image.transform applies the rotation and
flips a particular display needs, and bmp.zig or jpeg.zig encodes the
result — nothing has to be converted into a second library's image type on the
way, so there is one representation from the drawing to the wire.
That the encoder understands this hardware is not incidental. The models that
take BMP parse a fixed header rather than a format, so bmp.zig asks for
z2dimg's .rgb24 depth, which is the twenty-four bit BI_RGB under a plain
BITMAPINFOHEADER that those devices accept and nothing else. Its JPEG
encoder writes a JFIF APP0 segment of its own accord, which matters because
every implementation known to drive a Stream Deck emits one and none has ever
been shown to work without.
Requirements #
- Zig 0.16
- Linux with the
hidrawdriver (CONFIG_HIDRAW), i.e./dev/hidraw*present
Only Linux is supported, and the reason is the image encoder rather than the
HID layer: z2dimg builds for Linux only at present. zig-hidapi has backends
for FreeBSD, Windows and macOS as well, and nothing in the network transport is
Linux-specific either, so the rest of this would follow whenever the encoder
does.
Supported devices #
Each model is described by its own module under src/devices/, which declares
the USB vendor and product ids, the shape of the key grid, and what the keys
can display. StreamDeck.Type identifies a device from the vendor and product
id pair it reports.
| Model | Product id | Keys | Key image | Encoders | Rests on |
|---|---|---|---|---|---|
| Stream Deck Original | 0x0060 |
5 × 3 | 72×72 BMP | — | two references |
| Stream Deck Original V2 | 0x006d |
5 × 3 | 72×72 JPEG | — | hardware |
| Stream Deck Mini | 0x0063 |
3 × 2 | 80×80 BMP | — | hardware |
| Stream Deck Mini (Discord) | 0x00b3 |
3 × 2 | 80×80 BMP | — | hardware |
| Stream Deck Mini MK.2 | 0x0090 |
3 × 2 | 80×80 BMP | — | hardware |
| Stream Deck MK.2 | 0x0080 |
5 × 3 | 72×72 JPEG | — | two references |
| Stream Deck MK.2 (Scissor) | 0x00a5 |
5 × 3 | 72×72 JPEG | — | two references |
| Stream Deck Neo | 0x009a |
4 × 2, plus 2 touch keys | 96×96 JPEG | — | hardware |
| Stream Deck XL | 0x006c |
8 × 4 | 96×96 JPEG | — | two references |
| Stream Deck XL V2 | 0x008f |
8 × 4 | 96×96 JPEG | — | two references |
| Stream Deck Plus | 0x0084 |
4 × 2 | 120×120 JPEG | 4 | hardware |
| Stream Deck Plus XL | 0x00c6 |
9 × 4 | 112×112 JPEG | 6 | hardware |
| Stream Deck Studio | 0x00aa |
16 × 2 | 144×112 JPEG | 2 | hardware |
| Stream Deck Pedal | 0x0086 |
3 pedals, no displays | — | — | two references |
| Stream Deck 6 Module | 0x00b8 |
3 × 2 | 80×80 BMP | — | three references |
| Stream Deck 15 Module | 0x00b9 |
5 × 3 | 72×72 JPEG | — | three references |
| Stream Deck 32 Module | 0x00ba |
8 × 4 | 96×96 JPEG | — | three references |
| Corsair Galleon K100 | 0x2b18 |
3 × 4 | 160×160 JPEG | 2 | hardware |
"Rests on" is what each row's numbers are actually good for. Hardware means
the model was run against a real device and did what this says; Elgato's docs
means its HID documentation states it and nothing has run it; two references
means python-elgato-streamdeck and node-elgato-stream-deck agree and nothing
has run it; three adds the module tables in DDRBoxman/gadgetdeck's protocol
notes; one reference means a single implementation says so and nothing else
mentions it at all, which is the weakest thing here. The
distinction is not academic: the Plus was the first device here whose controls
are not all the same width, and running it turned up a bug two references had
happily agreed through — Events.decode gave every parser the body sized for
the largest control, so a turn of one dial reported nine of them on a device
with four.
The vendor id is 0x0fd9 throughout except for the Galleon, which is a Corsair
keyboard with a Stream Deck panel built into it and reports Corsair's 0x1b1c.
Corsair owns Elgato and Elgato's own SDK counts it among the Stream Decks, so
it belongs here. Its numbers rested on a single implementation until one was
plugged in and asked — a second, rust-elgato-streamdeck, has since been found to
carry it in an unmerged pull request, and agrees. It is also the only device
here that is composite, presenting the panel as one HID interface of three,
the only one that arrives with its sleep timeout already set, and the only one
that stops being a Stream Deck when the host goes quiet — see what the hardware
settled. Touchscreen describes the screens: the
Plus and the Plus XL carry one that reports where it was touched, 800×100 and
1200×100 respectively, while the Neo carries a 248×58 info strip that only
displays — its two touch keys report through the key control, as keys 8 and 9 —
and the Galleon's 720×384 strip likewise only displays, which was measured
rather than read: both implementations call it a touchscreen and it was dragged
across on hardware without sending a byte. TouchScreenFeature.touch is what
separates the two. A screen is driven the
way the keys are: blankImage for a surface of the right size, encodeImage
to see the bytes, and setImage to send a surface. The Neo's strip takes no
rectangle, so writing part of it is error.PartialWriteUnsupported rather
than a strip that ends up half drawn.
Adding another model is a new file
in src/devices/, an entry in src/devices.zig, and a tag in
StreamDeck.Type — and the exhaustive switches in StreamDeck.Type.generation,
Encoders.count and Touchscreen.readSize then refuse to compile until the new
model has been accounted for in each.
The Module entries are the bare panels Elgato sells for building into a panel of your own, and the two named editions are ordinary devices with a product id of their own; each is electrically the model it is derived from, so they share its key table rather than repeating it.
Elgato's HID documentation gives a key image size for six of these families, and every one of them matches what was already in the table. What it does not cover is the Studio, the Pedal, the Original and the Galleon.
- The Studio's key resolution was the one question the references could
not settle between them: python-elgato-streamdeck says 80×120 and
node-elgato-stream-deck says 144×112. A Studio settled it itself. Asked host
command
0x80over the network, it answers with its key and panel dimensions — 144×112 keys on a 1424×280 panel — and 144×112 images drawn from that table land on its keys the right way up. - The Plus XL's rotation is settled twice over. Both references agreed on a quarter turn and disagreed about which way; Elgato's documentation says 90° counterclockwise, for the keys, the panel and the touchscreen alike, and this library was changed to match. Hardware has now confirmed it — see below.
- The Galleon rested on one implementation until one was plugged in, and the single source turned out to be right about everything it could be checked on. See below.
What the hardware settled #
Five models have been run against a real device, and each one answered something the references could not.
The Original V2 was the first: keys, events, the serial number and firmware version at the offsets the audit corrected, and both the BMP and JPEG paths.
The Neo settled what its own table used to get wrong. It reports ten key
states, not the eleven the entry here once described, and the key labelled 6
arrives as index 6 — so the grid is keys 0 through 7 and the two touch keys are
8 and 9, which the audit had argued from the table contradicting itself rather
than from a measurement. Those touch keys light when setTouchKeyColor is given
a colour, and pressing one arrives as .down at index 8 or 9 of an ordinary key
report and puts the backlight out: they report through the key control, and no
touchscreen report is ever sent, which is what Touchscreen.readSize assumes for
this model and had no way to check. Its 248×58 info strip takes an image through
the 0x02 0x0b header and shows it the right way up — the one thing byte-level
checking could not reach, since a strip written upside down is written just as
successfully, and a seven segment 6 turned over is a convincing 9.
The Studio was the first device run over the network rather than USB, and
it settled its own key size. Its answer to host command 0x80 has the layout of
the USB unit information report, shifted one byte to make room for the command
byte, and reads 2 rows of 16 keys at 144×112 on a 1424×280 panel. probe --orient then put the same figure on four keys under four corrections, and the
one drawn as the table has it — no rotation, no flip — was the one the right way
up. It also found three bugs in the network transport, which are described
under how far to trust it, and that its panel is two
screens rather than one — see the Studio's panel is two
screens.
Its two encoders are lit as well, in two ways. Each knob has a light of its own
on top, set with Encoders.setColor — 02 10 <encoder> r g b, which no other
model here has, so Encoders.hasLed says whether there is one. And each sits
in a ring of twenty-four LEDs, written whole in one output report,
02 0f <encoder> and a colour per LED, where the Galleon takes a feature report
per LED. Lighting LED 0 white and 1 to 3 green on the device's own numbering
showed both rings counting clockwise, from the top on the left knob and
from the bottom on the right: the right ring is mounted a half turn round,
which is the offset of twelve node-elgato-stream-deck gives it. Neither starts
quite where it looks to, though. With the marker sent through this library's
own numbering, white landed one LED clockwise of twelve o'clock on both knobs:
there is an LED dead at the top, and the device's LED 0 is the one after it.
This library numbers every ring from that top LED, clockwise, which is the
device's 23 on the left ring and its 11 on the right. Unlike the Galleon's, the Studio's rings keep their
colour: drawn once, they stayed lit for as long as the connection was held.
The Mini settled its own image transform, which two references had agreed
on and got wrong. Putting the same figure on four keys under the four
corrections a table can be wrong by, and looking at which read correctly, found
that every key image on a Mini had been coming out upside down — the table
carried a quarter turn with a top/bottom flip where it wants that turn with a
left/right one. Elgato's documentation says to rotate ninety degrees clockwise
and mentions no flip at all, so the Mini does what the documentation says and
one thing more; the likeliest reason is that bmp.zig writes its rows
bottom-up and the documentation does not say which row order these devices
expect.
The Neo also settled what the panel behind the keys actually is. A
checkerboard painted over its whole 480×320 screen appears through every key
and through the info strip, with the pattern running continuously from one key
to the next rather than restarting in each. The keys are windows onto one sheet
of glass, which is what Panel is built on, and a marker in the image's
top-left corner came out under the top-left key. fillScreen and fillKey were
confirmed on it too, along with getUnitInfo, which answered with exactly the
sizes Elgato documents.
The Original V2 came back for a second look and confirmed the panel. It
reports its own LCD as 480 × 272 through getUnitInfo, which is exactly what
Elgato documents for the Classic family and what Panel had been carrying on
documentation alone. Its grid, key size and all three firmware versions check
out too, and its two application slots report identically as the Plus's do.
It also settled the background, though not the way it was meant to. The HID command for storing one did nothing observable, five different ways — but painting the panel and then drawing over only some of the keys produced exactly the effect Elgato's software calls a background, on this model and on the Neo and the Plus. See Backgrounds.
The Plus exercised the two riskiest repairs from the audit and found a third
fault nobody had looked for. Its 800×100 touchscreen takes an image through the
v3 header, which the audit had found wrong three ways at once — a first byte
of 0x2c where the protocol wants 0x02, length and page_number the wrong
way round, and extern struct padding making the whole thing 18 bytes rather
than 16. A drag across that screen arrives with the coordinates it was made at,
which is the other repair working: the Plus used to claim a touchscreen read
size of zero, so its report body was eight bytes and Touchscreen.Event.init
refuses anything under ten — no touch event could ever have been decoded on this
model. Its four dials turn in both directions, with the detents signed as they
should be. And turning one of them reported nine dials, which is the bug
described above.
The Galleon was the weakest row in the table and is now one of the
strongest. getUnitInfo answered 3 × 4, twelve keys, 160 × 160 pixels —
exactly what the single source said, digit for digit, on the one model where
nothing could corroborate it. Its serial number and all three firmware versions
read out of the gen2 string reports without any Corsair special case, so the
panel really does speak the protocol of an Elgato deck of its generation.
Getting that far took a fix the other models could never have prompted. The
Galleon is the first composite device here: its 1b1c:2b18 function is
enumerated three times, once per HID interface, all under the same ids, and only
interface 0 is the panel — interfaces 1 and 2 are an ordinary keyboard and a
consumer control. Matching on ids alone, which had been enough for eleven
single-interface Elgato devices, reported one keyboard as three Stream Decks and
then talked the panel protocol at two of them. Enumerator.next now passes over
any interface but 0, and lets a null interface number through untouched, since
every transport but USB reports none.
Its key transform is settled, and the single source had it right: the same figure put on four keys under the four corrections a table can be wrong by read correctly under no correction at all. The mirror, the vertical flip and the half turn were all visibly wrong beside it, with the rule under the figure migrating to the top where it should. No rotation, no flips — unlike the Mini, where this test found the table wrong. Numbering every key with its own index then showed 0 through 11 running left to right and top to bottom, all twelve upright and in the places the table puts them, so the grid is row-major from the top-left and there is no off-by-one of the kind the Neo turned out to have.
Its panel takes a whole-panel image, which was the open question when it was given one. A 720 × 1280 checkerboard reached the display strip above the keys and all twelve keys, with the marker in the image's top-left corner landing at the top-left of the strip — so the panel's transform is the keys' transform, as everywhere else here, and the strip is part of the same sheet the keys are windows onto, exactly as a Neo's info strip is.
And the sheet is continuous. Adjacent keys in the checkerboard do not show the same phase — one begins with a full light square at its left edge where its neighbour begins part way through a dark one — which is only possible if all twelve are looking at one image rather than each being drawn its own copy. The key pitch is what makes that legible: node-elgato-stream-deck's layout puts the keys at 160 pixels with 64-pixel gaps, a pitch of 224, which is not a multiple of the 40-pixel checker period and so shifts the pattern by 24 pixels from one key to the next. Those numbers also check out against the panel the device reports: 56 + 3×160 + 2×64 leaves a 56-pixel margin at each side of 720, and the keys starting 443 down run to 1275 of 1280.
Each encoder carries a ring of four LEDs, and they are addressable:
Encoders.setRingColor lights a whole ring and setRingColors lights each
segment separately, through feature report 0x03 0x24 with an index and three
colour bytes — six bytes unpadded, which is what both implementations send. Two
things about the numbering would light the wrong LED if either were missed, and
both come from those implementations rather than from here: the rings run from
the right-hand encoder, so encoder 1 owns indices 0–3 and encoder 0 owns
4–7, and each ring's own segment zero sits at a different angle, three quarter
turns round for the left and one for the right. node carries that as a
ledRingOffset and the rust pull request as a pair of rotations; they agree.
ledRingSteps is zero for every model here but this and the Studio, including
the Plus — having encoders and having encoder LEDs are different questions.
All of it is confirmed on hardware, and getting there took three goes at the experiment rather than three goes at the code.
Lighting one ring showed that the base is right: encoder 0 is the left knob and encoder 1 the right, which is what indices running from the right-hand encoder predicts. But where a segment sits resisted two attempts. The ring is a diffused light pipe rather than four separate lamps, so a lit segment is a bright arc rather than a dot; the knob is polished metal and throws a highlight that moves with the camera; and the far side of a ring is hidden by the knob from any lens not directly overhead. Walking the segments, steadily and then flashing, produced recordings whose ring brightness by angle recovers the glare and not the segment — measured, not guessed at.
Colour settled it in one photograph. All four segments lit at once in red, green, blue and white can be read from a still, with no timing to align and nothing moving, and a red arc stays red under a highlight that washes a bright one out. The answer:
Segment 0 is at the top of the ring and they advance anticlockwise — 1 at nine o'clock, 2 at six, 3 at three.
And both rings show that same arrangement, which is the thing the two rotations exist to do and the reason to believe them: a wrong rotation would have left one ring turned against the other.
That was the numbering the two references produce, and it is not the one this
library now offers. Segments are numbered clockwise from the top on every
model with a ring, which is the way a level is read round a dial, so a Galleon's
segment 1 is at three o'clock and 3 at nine; Encoders reverses the ring before
applying the rotations above. That was then looked at on the keyboard: segments
0 to 3 lit red, green, blue and white came out red at the top, green on the
right, blue toward the user and white on the left, on both knobs.
One more thing the experiment turned up, which neither implementation mentions
and which matters to anyone driving these. A ring does not keep its colour.
The keyboard's own lighting engine owns those LEDs and paints back over
whatever the host writes, within about a second — set once and left alone, a
ring is dark again too soon to photograph, which is how this was noticed.
Holding a colour means re-sending it, and ten times a second is comfortably
enough. keepAlive does not cover it: that keeps the device in Stream Deck
mode, where the panel and the input reports live, and the rings are a separate
argument with the firmware.
reset on this model does something no Elgato deck does: it gives the panel
back to Corsair's own firmware interface — the keyboard's wallpaper on the
strip, its own icons on the keys, a polling-rate readout, an Elgato logo on the
bottom-right key. An Elgato deck shows the manufacturer's logo and stays
otherwise blank.
And it does that on its own, about two seconds after a whole-panel image is
written. This is what "the Galleon stops listening if it is left alone"
actually means, and it was filmed rather than inferred: a painted checkerboard
held for roughly two seconds and then reverted to Corsair's interface with
nothing sent in between and no reset involved.
It is specifically the image. probe --keepalive was built to find what
holds a panel, and its control phase answered a question it was not asked: a
fillScreen is not reclaimed at all. Five colours were filled in turn and held
for five seconds each — one of them the control, which sends nothing whatsoever
— and every phase survived intact, after which the last colour stayed up for
about 180 seconds before the device reverted. So there are two different
behaviours here and the 180 seconds is the sleep timeout doing exactly what it
says:
| written | how long it survives |
|---|---|
fillScreen, a feature report |
until the sleep timeout — 180 s as shipped, and setSleepTimeout(0) disables it |
Panel.setImage, a whole-panel image |
about two seconds, then Corsair's firmware takes the panel back |
The likeliest reading of that difference, though nothing has tested it: an image
write puts the device into Stream Deck mode and the firmware pulls it back out
after two seconds, where fillScreen is a paint command the firmware honours
without ever handing over. That would explain why a fill survives for three
minutes and an image for two seconds, and it matches what the input reports do
— see the events below, which change shape at the same moment the panel does.
Why a fill should be kept and an image dropped is not known. What does hold an
image is now known, and it is the blunt answer: keep writing. probe --keepalive put four candidates against a control, each holding a flat-coloured
panel image for five seconds, and the result was clean —
| held with | what happened |
|---|---|
| nothing (control) | reverted after ~2 s |
a read of feature report 0x05 |
reverted after ~2 s |
a read of 0x14 — declared by this device and no Elgato model |
reverted after ~2 s |
a read of 0x15 — likewise |
reverted after ~2 s |
| re-sending the panel image every 500 ms | held, for as long as it kept being sent |
A second round then asked which writes, and the answer is not "any of them":
| held with | what happened |
|---|---|
| nothing (control) | reverted after ~2 s |
setBrightness, a feature report write |
reverted after ~3 s |
resetKeyStream, one output report |
held |
| one key image | held |
| the whole panel image | held |
Which looked like a clean rule — everything that held the device was a write on
the image output report 0x02, everything that did not was a feature report —
and it was the wrong rule. Reading the two implementations that already drive
this device settled it, and neither the rule nor any amount of further
experiment would have found the answer:
The device is listening for feature report
0x03with command0x27.
node-elgato-stream-deck sends exactly those two bytes every 500 ms from the moment it opens the device until it closes it, and calls it a ping. An open — not yet merged — pull request against rust-elgato-streamdeck sends the same command padded to thirty-two bytes, calls it refreshing software mode, and sends it before every operation rather than from a timer. Two implementations arrived at independently, the same command, the same interval; one of them shipped and one of them proposed.
So the experiment was right about the interval and about what happens without
one, and wrong about the mechanism: it is not that the device counts traffic on
the image channel, it is that this one command is what it wants, and the image
writes evidently refresh the same state as a side effect. setBrightness is
0x03 0x08 and does nothing for it, which is why "a feature report write" came
out negative — the wrong feature report was being written.
StreamDeck.keepAlive sends 0x03 0x27, padded to thirty-two bytes as every
other gen2 feature report here is. It does nothing at all on every other model,
so it is safe to call on whatever is attached, and it is still the caller's job
to call it — there is no timer in this library.
Confirmed on the hardware, which is the point of having put it in a
probe phase rather than taking two implementations' word for it. Five
candidates, five seconds each: the control failed after about two seconds,
keepAlive held its whole phase, setBrightness failed after about two
seconds, and resetKeyStream and the panel image both held. So 0x03 0x27 is
right, and so is the reading that 0x03 0x08 being useless is about which
feature report rather than about feature reports.
fillKey works on it too, which is how an embarrassing non-finding got
written down and then taken out again. A painted panel came out with every key
showing the checkerboard except key 0, which was flat amber — recorded here as
something the device was doing with that key's region of a whole-panel write,
since amber appears nowhere in an image made of black, grey and one red corner.
It was probe --paint itself, whose last step fills a key with a colour to
exercise fillKey, and which said so in its own output. It fills the last key
now: filling the first covered the corner marker that says which way up the
panel went on, which is the one thing that test exists to show.
Three more things it said are its own, and worth knowing before driving one:
- Its panel is 720 × 1280 — the only one here in portrait, and the only one
whose keys do not tile it: twelve 160-pixel keys on a 720 × 1280 sheet leave
far more glass between them than a Neo's do.
Panelused to offer no panel for this model because no documentation gave a size; it now carries that one, which is the only entry in the file taken from a device rather than from Elgato's documentation. The keys sit on it at a pitch of 224 in both axes — 160-pixel keys with 64-pixel gaps, 56 in from each side — which is node-elgato-stream-deck's layout and agrees with the size the device reports. - It reports an image bpp of 2 where a Neo, a Plus and an Original V2 all report 4. That looked like a Corsair peculiarity until a Stream Deck + XL was asked and answered 2 as well, so it tracks something about the newer models rather than about the vendor. Nothing in this library reads the field and what it means is not documented, so it is recorded rather than acted on.
- Its sleep timeout comes back as 180 seconds, where a Neo, a Plus and an
Original V2 all report 0. It was then watched doing it: a filled panel stayed
up for about three minutes and reverted.
setSleepTimeout(0)is what turns that off, and it is a separate thing from the two-second reclaim below.
Its keys decode, and they decode correctly — twelve states in one report,
presses arriving at the indices the grid puts them at, each a clean .down
followed by a .up. No key table change was needed and nothing was off by one.
But only while the panel is the host's. This is the sharpest thing running this
model has shown, and it is not visible from one report: the device reports in
two different modes, and it is the same switch as the panel. While the
library's key images are on the keys, presses arrive as ordinary Stream Deck key
reports and decode. Once the firmware has taken the panel back, the reports keep
coming and Events.decode answers error.UnknownControlType for every one of
them — its second byte, which says whether a report is keys (0), touchscreen
(2) or encoders (3), is none of those.
So "the Galleon stops listening if it is left alone" is not a figure of speech
and not only about the display. The device leaves Stream Deck mode and goes back
to being a Corsair keyboard, and the host loses the panel and the events
together. Events.decode is right to refuse those reports; they are not Stream
Deck reports. What that other mode's reports say has not been looked at;
probe --events prints them raw.
Its encoders decode too, once keepAlive holds the device long enough to
press anything. They are ordinary gen2 encoder reports and needed no change at
all: the header declares a body of 0x03, which is an event type and one byte
per encoder, and the keys declare 0x0c, which is twelve. Both turn in both
directions with signed detents — 02 and fd for two clockwise and three
anticlockwise — and both press in, arriving as a push event with that
encoder down and then one with nothing down. Nothing had said they were
pressable. The captured reports are now regression tests in Events.zig, which
is the first time this library has had a test written from bytes this model
actually sent.
Its strip is not a touchscreen, which is the second thing running this model
found wrong rather than confirmed. Across a run that caught both encoders
turning, both encoders pressed and eight key presses, the strip was touched and
dragged across repeatedly and sent nothing whatever. Both implementations call
it a touchscreen and this library did too: getFeature claimed touch = true
and readSize reserved ten bytes for a report that never comes. Both are now
false and zero, with the measurement written beside them. It is a display, as a
Neo's strip is.
The strip does take a direct write. greendeck draws a four-quarter dashboard
onto it with setImage at 0,0 and 720×384 — a v3 write of its own, not part
of a whole-panel one — and it arrives where it was put, filling the sheet with
nothing clipped at any edge. Photographed on firmware 3.05.005.
What is still only a claim is a partial write. The one rectangle ever sent
covers the whole strip, so whether a smaller one lands where its header says —
the interesting thing a v3 header buys, and something a Neo's strip does not
do — remains untested.
The Plus XL was the last row resting on documentation alone, and running it confirmed the documentation and then produced a second, independent confirmation of the same thing.
Its rotation was the open question. Both reference implementations agreed the keys take a quarter turn and disagreed about which way; Elgato's documentation says 90° counterclockwise and this library was changed to match it on that authority alone. Putting the same figure on four keys under the four corrections a table can be wrong by, key 0 — the table as it stands — is the one that reads correctly. So the documentation is right and so is the table. That mattered more than it sounds: the Mini is the precedent, where two references agreed on a transform and were both wrong, and this same test caught it.
getUnitInfo then confirmed the rest of the row outright — 9 × 4, thirty-six
keys, 112 × 112, a 1280 × 800 panel — which is every number Elgato publishes
for this model, none of which anything had checked. Numbering every key with its
own index then put 0 through 35 in place, row-major from the top-left, all
thirty-six upright: the turn is right across the whole grid rather than on the
four keys the orientation test uses, and the numbering has no gap or transposition
of the kind the Neo turned out to have.
Its panel was written too, and it is the largest and the only turned one here: a 1280 × 800 checkerboard reached all thirty-six keys and the 1200 × 100 touchscreen below them, running continuously from one key to the next and on across the strip. So the rotation is right for the panel as well as the keys, and the touchscreen is part of the same sheet the keys are windows onto — which is now four models where that holds, the Neo, the Original V2, the Galleon and this.
Its six encoders and its touchscreen both report correctly, and the encoders are the case worth having had: the Plus's four are what turned up the bug where a turn of one dial reported nine of them. The Plus XL declares a body of seven — an event type and one byte per encoder — and all six turn and press at indices 0 through 5, with no sign of a recurrence.
The touchscreen answered the question nobody had thought to ask. A drag arrives
as an event type 3 with two positions, and the coordinates are in the
1200 × 100 the screen is looked at, not the 100 × 1200 the device reports it
as. Eleven drags all had x within 0–1199 and y within 0–99. So on this model
an image handed to setImage is rotated on the way out and a touch that comes
back needs no correction at all — the rotation applies to one direction and not
the other, which is exactly the sort of thing that is obvious once seen and
invisible until then.
One difference from the table, which turns out not to matter: the device
declares fourteen bytes of touchscreen body where Touchscreen.report_size
reserves ten. The four past the second position are zero in every report seen
and ten is what the two positions need, so it is room this library does not use
rather than something it is missing.
Both, and the unit info answers, are kept as tests in Events.zig and
StreamDeck.zig.
The touchscreen showed nothing, and had never been able to #
The documentation gives the Plus XL a quarter turn for the keys, the panel and
the touchscreen. Keys and Panel carried it; Touchscreen.getFeature did not.
Asking the device to draw on that screen settled it in the least ambiguous way
available: nothing appeared at all. No error, no partial image, no image the
wrong way round — the write was accepted and the strip stayed dark, through
press after press.
Two things were wrong at once and each would have hidden the other. Without the
turn the pixels went out the wrong way round; and the rectangle in the v3
header, which says where the image lands, claimed 1200 columns of a screen the
device thinks is 100 wide. That is out of bounds, and this device's answer to
out of bounds is to accept the write and display nothing. So the failure was
silent, and it had been silent for as long as anything had been writing this
screen.
Touchscreen.setImage now turns the rectangle the same way encodeImage turns
the pixels, through deviceRect. Its mapping is the inverse of the one
image.transform applies, and rather than restate that inverse and hope, a test
puts a single pixel through transform and asks deviceRect where that pixel
went — so the two cannot drift apart without something noticing. The screen's
dimensions stay as it is looked at, 1200 × 100, because that is what a caller
draws and what a touch reports; the device's own 100 × 1200 is what the write
path turns it into.
Every other model is unaffected: they carry no rotation, so the mapping is the identity, and the Neo's strip takes no rectangle at all.
Fixed and confirmed. The same screen that had shown nothing through press after press now draws the pressed key's index across the full 1200 × 100, the right way up. That settles the last of Elgato's documentation for this model on hardware — the quarter turn applies to the keys, the panel and the touchscreen, exactly as written, and every one of the three has now been seen doing it.
It is worth noticing what the bug was made of. Neither half of it was visible on its own: a turned image in a correctly placed rectangle would have shown something sideways, and an unturned image in a wrongly placed rectangle would have shown nothing — which is what happened, so the rectangle hid the rotation completely. Two references and a documentation page had all been read, and the only thing that found it was asking the device to draw.
The screen size is in the unit info report, past where the documentation stops #
Elgato's layout for Get Unit Information ends at the demo frame count. Reading
the bytes after it across four devices, two fields fall out, and they were not
guessed at — they match what this library already claimed from other sources,
four times independently:
| model | +0x11 |
+0x13 |
what the tables say |
|---|---|---|---|
| Stream Deck Neo | 248 | 58 | 248 × 58 info strip |
| Stream Deck Plus | 800 | 100 | 800 × 100 touchscreen |
| Corsair Galleon | 720 | 384 | 720 × 384 strip |
| Stream Deck + XL | 100 | 1200 | 1200 × 100 touchscreen |
UnitInfo now carries them as touch_width and touch_height, null on a device
whose answer stops earlier, since this is past what is documented and a shorter
report is not a failure.
The Plus XL is the one that makes the point. It reports its screen transposed, on the one model whose glass is mounted a quarter turn round — so the device is describing the panel as it is built rather than as it is looked at, and the rotation that rested on a documentation page now shows up a second time in the geometry the device reports about itself. The probe prints the two side by side and says which case it is looking at.
Byte +0x10, between the demo frames and the screen width, is left unread: the
four devices answer 0x95, 0x42, 0x06 and 0x00, and nothing has made sense
of that.
All four answers are kept as tests in StreamDeck.zig, so the reading is checked
against real bytes rather than against itself.
Installation #
Fetch the package into your build.zig.zon:
zig fetch --save git+https://git.jcollie.dev/jeff/zig-streamdeck.git
Then wire the module up in build.zig:
const streamdeck = b.dependency("streamdeck", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("streamdeck", streamdeck.module("streamdeck"));
Usage #
src/main.zig is a complete example: it enumerates every attached deck, spawns
a task per device, puts each key's own number on it, and logs the events that
come back.
Note the shape of the loop. It reads with a timeout and sends a keepAlive
each time round, rather than parking in a blocking read, because a Galleon
leaves Stream Deck mode about two seconds after the last write and a program
sitting in read never gets the chance to stop it. That costs every other model
nothing but a trip round the loop when nothing happened, and keepAlive does
nothing at all on them — so there is no need to ask which model is attached.
Without it the example enumerated a Galleon, drew on it, and then logged
ignoring report: UnknownControlType for every key press, which is what losing
the device looks like: the reports keep coming and all of them stop parsing.
const std = @import("std");
const streamdeck = @import("streamdeck");
pub fn main(init: std.process.Init) !void {
const io = init.io;
const alloc = init.gpa;
var decks: streamdeck.Enumerator = undefined;
try decks.init(io, alloc);
defer decks.deinit(io, alloc);
while (try decks.next(io, alloc)) |found| {
const sd = found.deck;
defer found.deinit(io, alloc);
var serial_buf: [32]u8 = undefined;
var version_buf: [32]u8 = undefined;
std.debug.print("{s} running firmware {s}\n", .{
try sd.getSerialNumber(io, &serial_buf),
try sd.getFirmwareVersion(io, &version_buf),
});
try sd.reset(io);
try sd.setBrightness(io, 50);
while (true) {
// Does nothing on every model but the Galleon, which
// stops being a Stream Deck without it.
try sd.keepAlive(io);
const event = try sd.events.readTimeout(io, alloc, .{
.duration = .{ .raw = .fromMilliseconds(500), .clock = .awake },
}) orelse continue;
defer event.deinit(alloc);
switch (event) {
.keys => |e| std.debug.print("key: {any}\n", .{e.event}),
.encoders => |e| std.debug.print("encoder: {any}\n", .{e.event}),
.touchscreen => |e| std.debug.print("touch: {any}\n", .{e.event}),
}
}
}
}
An Enumerator is initialized in place rather than returned, because it holds
the scratch the enumeration works in and hands back pointers into its own
storage — so it must not move once started. StreamDeckInfo carries the open
deck and the DeviceInfo the system reported: the serial number, the product
and manufacturer strings, and where the device sits on the bus. Keep it rather
than asking the open device, which answers less — on Linux a device reports no
manufacturer at all.
A StreamDeck is mostly a handle plus five control groups, each of which finds
its way back to the device with @fieldParentPtr and answers according to the
model:
keys— how many keys there are, what each can display, andsetImageto put a picture on one. The surface is rotated and flipped as that model's displays are mounted and encoded as BMP or JPEG before being split across as many HID reports as it takes. Nothing is scaled: a surface has to be the size the key'sKeyImageFeatureasks for, andblankImageis the easy way to get one that is.encoders— the rotary encoders, on the Plus (4), the Plus XL (6) and the Studio (2).touchscreen— the screens: a touchscreen on the Plus and the Plus XL, and the Neo's info strip, which displays without reporting touches.panel— the single screen behind the keys, which the key images are cut-outs of, and which can be painted whole.events— decoding of the input reports the device sends when something is pressed, turned or touched.
events.read waits for the device to say something and returns what it said.
A report it will not parse is one of ReportError — ShortReport,
UnknownReportType, UnknownControlType, UnknownEventType — and is worth
carrying on through; anything else means the deck is no longer reachable, which
is the end of that device. The two have to be told apart, because the obvious
loop around read spins forever otherwise: over USB on a deck somebody
unplugged, and over TCP on a connection that will never come back.
The library writes nothing to the log. What to do about a report it will not
parse is the caller's to decide: a daemon may want it logged, a one-shot tool may want to
exit, and neither choice belongs to a library. src/main.zig logs them and
carries on listening, which is the usual answer but not the library's to
assume.
None of those errors means the device is broken. A Stream Deck can be unplugged part-way through a report, and a model whose tables here are wrong will send control and event types this library does not expect — which is exactly the case where a caller wants to see the error rather than have it swallowed.
Networked devices #
The Stream Deck Studio and the Stream Deck Network Dock are not USB devices. They take Ethernet — the Studio is powered over it — and are driven over TCP, on port 5343.
const address = try std.Io.net.IpAddress.parse("192.0.2.10", streamdeck.Tcp.default_port);
const sd = try streamdeck.connect(io, alloc, address);
defer sd.close(io);
Everything above the socket is the same as for a USB deck. keys, encoders
and events behave identically, setImage takes the same surface, and the
image that goes across is byte for byte the one that would have gone over USB —
the same kilobyte reports with the same headers, not re-chunked for the
network. That is what makes one StreamDeck able to drive either.
These devices are not enumerated. Enumerator walks the HID devices attached
to this machine and will never find one, because it is somewhere on a network
rather than plugged in. There is no discovery here either, so the address is the caller's
to know; the devices do advertise themselves over mDNS as _elg._tcp, which is
a reasonable thing to add later but is a protocol of its own.
What a caller has to do #
Keep reading. The device pings every few seconds and hangs up on a host
that has not answered within about five. Answering happens inside
events.read, and inside any question asked of the device — but nothing runs
on its own, so a program that spends five seconds drawing without reading will
be disconnected. An application that is doing anything with a Stream Deck sits
in events.read anyway; one that does not has to say so.
Stay connected. A Studio shows its own demo screen whenever no host is
connected to it, and goes back to it the moment the connection closes. Whatever
was drawn is gone with the connection, so a program that paints the keys and
exits has painted them for nobody. probe --hold=SECONDS stays connected after
acting, asking the device something once a second, for exactly this reason.
The alternative was a task owning the socket, with a queue and a lock between it and the caller. That is a lot of machinery for a library that otherwise has none, and it would impose a threading model on every caller to fix a problem most of them do not have.
What differs from USB #
Two things, and both are the protocol's doing rather than this library's:
resetis refused, witherror.Unsupported. No implementation of this protocol has ever been seen to perform it, and there is nothing to copy — the reference client refuses it outright rather than sending something. Inventing an encoding for a command that clears the device would be guessing with the device's state.resetKeyStreamandsetBrightnesswork normally.- The serial number and firmware version come from elsewhere. Over USB they
are feature reports
0x06and0x05; over the network they are commands0x84and0x83in a separate namespace. The two replies are not even the same shape. The serial number's declares its length big-endian, in a protocol that is little-endian everywhere else: a Studio answers03 84 00 0eand fourteen characters. The firmware's declares a length of zero and carries a four byte word and then the version at offset 8, laid out like the USB firmware report.getSerialNumberandgetFirmwareVersionhide all of it. - Nothing else can be read. A device reached directly answers questions
about itself through those commands and not through feature reports, and the
legacy framing a Studio speaks has no header to say a frame is a question at
all. So every other read —
getUnitInfo,getSleepTimeout, the per-module firmware reports — is refused witherror.Unsupportedrather than sent. A Studio was seen to ignore one sent anyway.
Through a Network Dock #
A Network Dock turns a USB deck into a networked one, and connect given a
dock's address comes back with the deck plugged into it — an ordinary
StreamDeck of whatever model that is. The dock itself is only a way in. It
identifies itself with a product id of 0xffff, Elgato's stand-in rather than
an id anything was assigned, and asked host command 0x1c it says what is
plugged in: the deck's vendor and product ids, its serial number, and the TCP
port the deck is reached on at the dock's own address. That reply begins
01 0b, the same as the notification a dock sends of its own accord when a deck
is plugged in or pulled out, and framing.parseChildInfo reads either.
error.NothingBehindDock means the dock answered and has no deck.
The deck's own connection carries nothing but USB reports, sent verbatim: the
deck answers the same feature reports it would over USB, takes the same image
pages, and sends the same input reports. It knows nothing of host commands, so
it is not asked who it is — the dock has just said. getSerialNumber,
getFirmwareVersion, getUnitInfo and getSleepTimeout all work on it, which
they do not on a Studio.
connect closes the dock's connection before opening the deck's. The deck's
connection was seen to outlive the dock's closed cleanly, and to be dropped
about five seconds after the dock's was left open and unanswered, so keeping
it would only be another connection to service for the sake of plug
notifications nobody is listening for.
All of it was run against a Network Dock on firmware 1.01.013 with a Neo plugged in. The Neo identified, answered every feature report it answers over USB — its serial number, three firmware versions, its unit information — took key images the right way up and a whole-panel image across its keys, info strip and indicator bars, and sent its key and touch key presses as the same twelve position reports it sends over USB.
How it is put together #
framing.zig is the protocol with the socket taken out of it: frames in and
out, the keepalive exchange, the command replies. It touches no socket and no
std.Io, which is what lets it be unit tested and fuzzed without hardware —
the same split Events.decode and Keys.encodeImage already make, and for the
same reason, only more so: these bytes came off a network rather than out of a
USB device.
Tcp.zig is the thin half that owns the socket, and Transport.zig is the
tagged union that lets StreamDeck hold either a HID device or one of these. It is a union rather than a vtable because most of this library is
decided by which model a device is and can be tested with no device at all —
which the tests do, with a .none transport that answers every call with
error.NoTransport. A vtable would make that a pointer nobody set.
How far to trust it #
Elgato publishes nothing about this protocol — not a specification, not a port number, not an SDK. What is here was read out of three independent reverse-engineered implementations, which the references below name, and they agree with each other on the framing, the keepalive exchange and the image path.
A Stream Deck Studio on firmware 2.01.000 has now been run against it, and it speaks the legacy framing: no header, 512 byte frames from the device and 1024 byte frames to it. It connected, answered its keepalives, identified itself, gave its serial number and firmware version, and took key images that it displayed correctly. Running it found three things that all three implementations' agreement had not:
- A question the device did not understand hung forever. A verbatim feature report read, sent to a Studio in legacy framing, goes out as a bare report id padded with zeroes, and the device ignores it. The five second silence timeout never fired, because the device goes on sending keepalives while ignoring the question. A reply is now given up on after two keepalives go by unanswered, and a device reached directly refuses those reads outright (see above).
- The firmware version came back empty, because its reply does not have the
shape of the serial number's.
framing.parseFirmwarereads it where it actually is, and the Studio's own replies are kept as tests inframing.zig. probecould not reach a networked deck at all. It now takes--connect=ADDRESSfor each one, alongside whatever is attached over USB.
The newer cora framing has since been run too: a Network Dock speaks it,
on its own connection and on the connection to the deck behind it, with the
flags a verbatim reply carries (verbatim and result) exactly where the
references put them. A dock's firmware reply has the layout of a Studio's, and
is kept as a test beside it. The Studio's own cora firmware is still unseen,
since the one here speaks legacy framing.
Input comes across as it would over USB, one report to a 512 byte frame. A key
press is an ordinary key report declaring 32 keys, numbered left to right along
the top row and then the bottom, and a turn of either encoder is a report
declaring a body of three: the event type and a byte for each of the two
encoders. The event type is 1 for a turn, with a signed step per detent, and 0
for a press, with 1 while the encoder is held in. Encoder 0 is the left knob and
encoder 1 the right. Events.decode reads all of it unchanged, and the reports
are kept as a test in Events.zig.
The screen behind the keys #
A Stream Deck's keys are not separate displays. Every model that shows images has one LCD panel, and the keys are windows cut out of it — which is visible the moment you paint the whole thing:
var surface = (try sd.panel.blankImage(alloc)).?;
defer surface.deinit(alloc);
// ...draw on it...
try sd.panel.setImage(io, alloc, surface);
A checkerboard written that way on a Neo shows through every key and through
the info strip, with the pattern running continuously from one key to the next
instead of restarting in each. It reaches further than that: the two small
indicator bars flanking the info strip are part of the same panel, and an
image's bottom-right corner lands on the right-hand one. A Neo background
therefore paints eleven things, not eight. That is what Panel is for: a background that
runs behind and between the keys, and one write that repaints everything
instead of a report per key.
| Model family | Panel |
|---|---|
| Classic (Original V2, MK.2, MK.2 Scissor, 15 Module) | 480 × 272 — confirmed on hardware |
| XL (XL, XL V2, 32 Module) | 1024 × 600 |
| Neo | 480 × 320 — confirmed on hardware, and covers the info strip and both indicator bars |
| Plus | 800 × 480 |
| Plus XL | 1280 × 800 |
| Studio | 2 × 1424 × 280, two screens side by side — confirmed on hardware |
The sizes are Elgato's, and a device will confirm its own — see getUnitInfo
below. The Mini family has a panel too, and Elgato documents its size, but the
only output report those devices accept writes a key's image bank, so there is
no command to send and getFeature reports none. The Original has no
documented size at all.
The Studio's panel is two screens #
A Studio's sixteen columns of keys are not in front of one screen but two: the
left eight columns on screen 0 and the right eight on screen 1, each 1424×280.
The size a Studio reports about itself is one of them, which is why sixteen
144-pixel keys do not fit in it. node-elgato-stream-deck gives the Studio two
panels, and the hardware agreed. The fill command carries the screen's index in
front of the colour, 03 05 <screen> r g b, and filling screen 0 red and
screen 1 green lit the left and right halves. The panel image header carries it
in byte 2, where a key image header carries the key.
getFeature describes the whole thing as 2848×280, with screens = 2, so a
Studio background is drawn as one picture. setImage cuts it into its two
halves and writes each to its own screen, and fillScreen fills both. A
checkerboard painted that way ran across all thirty-two keys, with its
top-left corner behind key 0. The physical gap between the two halves of the
keypad is not in the image: pixel 1423 is the right edge of screen 0 and pixel
1424 the left edge of screen 1.
A key fill wipes the panel image — over the network. fillKey sent after a
panel image left that one key lit and the checkerboard gone, where the same
image with nothing after it stayed up for as long as the connection did. A Neo
behind a Network Dock did exactly the same, where a Galleon over USB given the
same sequence kept the checkerboard on every key but the filled one; so it
belongs to the networked path rather than to the Studio. probe --panel paints
the checkerboard alone for that reason, and probe --paint shows the fill, the
image and a key fill one after the other.
Do not call reset before painting the panel #
reset leaves a device able to accept only a short panel image. On an
Original V2, after reset:
| Image | Encoded | Packets | Result |
|---|---|---|---|
| A solid colour | 1,053 bytes | 2 | displays correctly |
| A checkerboard | 5,778 bytes | 6 | a flat wash of its average colour |
Without the reset both display correctly. That was bisected on the hardware
one call at a time over six runs, with the surface dumped to a PNG first to
prove the picture handed to setImage was right, and with this library's own
probe --composite as a known-good control — which never calls reset, and
is why none of this turned up before.
It is not a stuck image stream in the sense resetKeyStream was written for:
issuing that immediately before the panel write does not clear it. What the
device is actually doing is not known; what is known is the boundary, which
sits somewhere between two packets and six.
So a program that paints the panel should not reset first. Little is lost by
leaving it out — resetKeyStream and setBrightness between them still prove
a device answers on both the output and the feature-report channels, and
painting the panel and then every key clears the glass more thoroughly than
reset does.
Backgrounds #
Elgato's software has a feature it calls a background: an image that "sits behind your key layout", showing wherever your key artwork does not cover it. It is worth knowing two things about it. The first is that it is a feature of the desktop application, not of the device — and the second is that you can have the same effect here without it.
How to actually do it #
Paint the panel, then draw over only the keys that want a foreground. A key you leave alone goes on showing the panel:
var background = (try sd.panel.blankImage(alloc)).?;
defer background.deinit(alloc);
// ...draw on it...
try sd.panel.setImage(io, alloc, background);
// Only the keys that need artwork. The rest keep showing the background.
try sd.keys.setImage(io, alloc, 0, icon);
That is the whole mechanism, and it works because the keys are windows onto one sheet of glass rather than separate displays. "The background shows where the foreground is transparent" turns out to mean nothing more than not writing that key.
Confirmed on a Stream Deck Original V2, a Neo and a Plus: panel painted with diagonal stripes, key images drawn over the even-numbered keys only, and the odd-numbered keys show the stripes.
A painted panel frames every key #
A key cap shows slightly more of the panel than the key image covers, so a painted panel is visible as a border around every key, not only the ones left alone. Paint the panel green, write a flat black image to every key, and all of them keep a green edge — confirmed on the same three models.
That is the physical cap rather than anything this library does: the image occupies its documented size exactly, and the cap is wider than it, so it also shows some of the gap around it. A Classic panel is 480×272 carrying fifteen 72×72 keys, which leaves 120 pixels across and 56 down for margins and gaps. Neither Elgato's documentation nor either reference implementation mentions that any of it is visible — node-elgato-stream-deck models a key's bounds as exactly its image size.
It is worth knowing rather than worth fixing, and it is probably what a background is meant to look like: whatever is on the panel becomes a frame around every key, so artwork drawn key by key sits in it rather than against black. If you want a key covered edge to edge, paint the panel behind it too.
Why it is the application's feature and not the device's #
Elgato's own description gives it away three times over. A background is set by right-clicking a key in the app and applies to a profile and a page — concepts the device knows nothing about. A screensaver is shown "when the Stream Deck app is running, and the computer is locked", which a firmware feature would not require. And the list of models supporting it includes the Stream Deck Pedal, which has no displays at all.
So the application composites your artwork over its own copy of the background and sends ordinary, flattened key images. That also explains the transparency: key images are JPEG, which has no alpha channel, so nothing transparent ever reaches the wire.
The HID command, which is something else #
There is also a real, documented HID command for storing a background in the device — and it is not how the desktop feature works.
try sd.panel.setBackground(io, alloc, 0, surface); // store it
try sd.panel.showBackground(io, 0); // and put it up
| Family | Store (0x02 0x0d) |
Show by index (0x03 0x13) |
|---|---|---|
| Classic (Original V2, MK.2, MK.2 Scissor, 15 Module) | yes | no |
| XL (XL, XL V2, 32 Module) | yes | yes |
| everything else | no | no |
The asymmetry is Elgato's: the Classic family's page documents Update Background
and its setter table has no 0x13. backgrounds() reports the two capabilities
separately for that reason.
It has never been seen to do anything. A Stream Deck Original V2 — Classic family, where the command is documented — took all thirty-two pages of a background without complaint, and then:
- Show Background by Index (
0x03 0x13): accepted, nothing appeared. Expected; not a command on this family. - Show Logo (
0x03 0x02): showed the manufacturer's logo, not the stored image. - A differential scan, all 256 feature reports read before and after the upload: none changed. The device admits to nothing.
- Left to go idle with a five second sleep timeout: blanked to darkness.
- Colour-keyed transparency: six candidates painted flat over a stored background — black, white, magenta, green, mid-grey, near-black. All six stayed flat.
So the device is either discarding the upload or displaying it by some means nobody here has found. One consequence worth being explicit about: the field order below is unvalidated too, because a header with its fields the wrong way round and a write that is simply discarded look identical from this side.
setBackground is in the API because the command is documented and costs
little to offer, and it is marked untested in its own doc comment. An XL would
settle it, being the one family with both halves.
Mind the field order #
The background header is the key image header with the chunk index and the
chunk size the other way round — page number at +0x04 and length at +0x06,
where a key image has length at +0x04 and page number at +0x06. Elgato's two
tables differ in exactly that and nothing else, which is easy to read past.
Getting it backwards would not fail loudly. The first page of a small image has
page number zero and a size of about a kilobyte, so a swapped header asks the
device to write page 1016 of nothing, and the device shows no background with
nothing to say why. This library had precisely that bug in the touchscreen
header once, and it looked the same there. ImageHeaderV6's test pins both
layouts side by side so the difference is visible rather than implied.
What the gallery count is not #
getUnitInfo reports lcd_gallery, and it is tempting to read that as the
number of background slots. It is not.
A Stream Deck Neo reports four LCD images in its gallery. It was sent a background and asked to show it; it accepted both without complaint and displayed nothing at all. A Stream Deck Plus reports zero and behaves identically.
The wider lesson is worth stating because it bit repeatedly while this was written: a Stream Deck accepts writes it does not implement. It answers all 256 feature report ids, and takes output reports for commands it has never heard of, in both cases without an error. Nothing about a write being accepted means it did anything. Only looking at the device settles it.
Asking a device about itself #
getUnitInfo is the newer protocol's Get Unit Information, and it is the one
call that checks this library's tables against the hardware rather than against
another implementation:
const unit = try sd.getUnitInfo(io);
// unit.key_width, unit.key_height, unit.lcd_width, unit.lcd_height, ...
A Neo and a Plus both answered with exactly the key and panel sizes Elgato documents for them. Where a table and a device disagree, the device is right.
One trap: rows and cols describe the keypad matrix, not the number of
keys. A Neo answers four by three — twelve positions — where it has eight keys
and two touch buttons, the rest of its bottom row being taken up by the info
strip. Pixel sizes it confirms outright; grid shapes take judgement.
The Mini family has no such report, and getUnitInfo returns
error.Unsupported there rather than reading the zeroes one of them answers
with. A networked deck returns it too: a Studio carries the same dimensions in
its answer to host command 0x80, but past the panel size that reply's layout
parts company with the USB report, so it is not read as one.
Other whole-device commands #
| Call | What it does |
|---|---|
fillKey |
Paint one key a solid colour instead of encoding an image for it. The only way to light a Neo's touch keys, and much cheaper than a JPEG for a key that is one colour. |
fillScreen |
Paint the whole panel a solid colour in one feature report. |
setSleepTimeout / getSleepTimeout |
How long the device sits idle before blanking itself; zero disables it. See the note below. |
getFirmwareVersionOf |
A device carries firmware in several parts. See below. |
getFirmwareReport |
The same, plus the thirty-two bits the device puts in front of the version string. See below. |
keepAlive |
Only the Galleon needs it, about twice a second, and this library will not do it for you — there is no timer here. It does nothing on every other model, so it is safe to call on whatever is attached. It sends feature report 0x03 0x27; see the Galleon's section above for how long the device waits and what else was found to hold it. |
fillKey, fillScreen and getUnitInfo were confirmed on a Neo and a Plus,
and all three firmware versions read correctly from a Mini, a Neo and a Plus.
Note that fillScreen is a fill and not a mode: the next image written over it
covers it, which is easy to mistake for the command not having worked.
A device has more than one firmware version #
Elgato documents three getters for the version, and they are three different programs rather than three ways of asking the same question:
| Report | Firmware |
What it is |
|---|---|---|
0x05 / 0xa1 |
.ap2 |
The primary application firmware. What a user means by "the firmware version", and what getFirmwareVersion reads. |
0x04 / 0xa0 |
.ld |
The bootloader. |
0x07 / 0xa2 |
.ap1 |
The backup application firmware. |
The Mini family numbers them 0xa0–0xa2 instead, and all three were read
correctly off a Mini, a Neo and a Plus. They are genuinely independent: a Neo
reports 1.00.013, 1.00.003 and 1.00.011 for the three. A Plus reports its two
application slots identically, which is what both slots holding the same image
looks like.
The Studio has two more, because its encoders are a board of their own with a bootloader of their own:
| Report | Firmware |
What it is |
|---|---|---|
0x11 |
.encoder_ap2 |
The encoder module's application firmware. |
0x13 |
.encoder_ld |
The encoder module's bootloader. |
Those two rest on node-elgato-stream-deck, whose Studio driver asks for exactly
these where every other model gets the generic three. Elgato publishes no HID
documentation for the Studio at all, so there is nothing to check them against,
and no hardware here has one. firmwareReportFor reports them only for the
Studio and getFirmwareVersionOf answers error.Unsupported elsewhere.
Not for want of asking, either: a Stream Deck Plus was asked for 0x11 and
0x13 and answered with the same empty stub it gives any report it does not
implement, and Elgato's Plus XL page lists that model's getters as 0x04
through 0x08 and 0x0a and nothing more. So having encoders is not what
brings the extra firmware; being a Studio is.
Firmware.all is the lot, for a caller that wants to print them, and
zig build probe does.
Reports Elgato does not document #
zig build probe -- --scan asks a device for all 256 feature reports and
prints the ones that answer with something. It has to work that way round
because a device answers every report id rather than refusing the ones it
does not implement — so "it answered" means nothing, and what separates a real
report from a stub is that the stub is identical whatever you ask for. The scan
derives the stub from ids nothing could plausibly use and subtracts it.
On a Neo and a Plus, nine reports differ from the stub. Six are the documented
ones (0x04–0x08, 0x0a). Three are not documented anywhere:
| Report | Neo | Plus |
|---|---|---|
0x09 |
00 00 00 00 69 16 |
01 00 01 00 e7 34 |
0x0b |
length 2, then 0x0120 |
length 2, then 0x0110 |
0x0c |
length 8, then zeroes | length 8, then zeroes |
All three are stable across repeated reads and across separate runs, which rules out counters and anything sampled like a temperature. Beyond that this library does not guess, and does not expose them: three stable numbers of unknown meaning are a thing to write down, not an API. They are recorded here so the next person has somewhere to start.
The Mini answers only 0x03, 0x04 and 0xa0–0xa3, which is its documented
set plus the undocumented 0x04 that duplicates 0xa1.
The firmware checksum, and why it is not checked #
A firmware report carries four bytes between its length and its version string. Elgato's documentation labels them Checksum on the newer protocol, and that is all it says — not what they cover, not the algorithm, not even the endianness. On the Mini family the same four bytes are listed as "N/A".
getFirmwareReport hands them over as a u32. It does not verify them, and
that is a conclusion rather than an omission.
They were attacked with the hardware to hand: three devices, six firmware reports, and a search over 41 checksum algorithms — the RevEng catalogue of 32-bit CRCs, eight 16-bit ones, Adler-32, Fletcher-32, FNV-1 and FNV-1a, djb2, sdbm, byte and word sums, and MD5, SHA-1 and SHA-256 prefixes — crossed with 23 ways of deriving an input from the report (the string field, the string cut at its terminator, with and without the report id and length, the whole report with the checksum zeroed, the version parsed back into numbers, and so on) and all 24 byte orders of the stored value. A little over twenty-two thousand combinations, each required to agree on all six observations at once. None did.
The reason turns out to be visible in the older protocol. Those same four bytes, the ones Elgato's Mini page declines to describe, read as a plain byte count on a Stream Deck Mini:
| Report | Version | Four bytes, little-endian |
|---|---|---|
0xa0 LD (bootloader) |
0.01.002 | 329,560 — 322 KiB |
0xa1 AP2 (primary) |
3.00.001 | 3,397,852 — 3.28 MiB |
0xa2 AP1 (backup) |
3.00.000 | 3,354,892 — 3.20 MiB |
A small bootloader and two application images of nearly the same size, differing by 42,960 bytes. All three are under 2²⁴, which a uniformly random 32-bit checksum would manage about once in sixteen million times.
So the four bytes in that slot describe the firmware image, not the eight ASCII characters beside them — and the newer protocol's checksum is a checksum of an image this library never sees. It cannot be verified from the host, and no further searching over the version string will change that.
It is still worth reading. The value changes when the firmware changes, so two
reads that disagree mean the device was reflashed underneath you. The observed
values from a Neo and a Plus are kept as a test in StreamDeck.zig, so that
anyone who picks this up again starts with real data:
| Device | Report | Version | Checksum |
|---|---|---|---|
| Neo | 0x04 LD |
1.00.003 | 0x01c8a81a |
| Neo | 0x05 AP2 |
1.00.013 | 0xe19327d5 |
| Neo | 0x07 AP1 |
1.00.011 | 0x63aa63e2 |
| Plus | 0x04 LD |
2.0.0.0 | 0x325db0b1 |
| Plus | 0x05 AP2 |
2.0.3.1 | 0x20a0081e |
| Plus | 0x07 AP1 |
2.0.3.1 | 0x20a0081e |
The Plus reports its two application slots byte for byte identically — same version, same checksum — which is what two slots holding the same image looks like, and is why one device alone could not have settled this.
The sleep timeout lags its own write #
setSleepTimeout takes a count of seconds, little-endian, in feature report
0x03 behind command 0x0d on the newer protocol and in 0x0b behind 0xa2
on the Mini family. Zero disables sleep rather than meaning "immediately".
A device does not apply it before answering the next question. Read it straight back and you get the value it held a moment ago, which looks exactly like the write having failed — and looks worse than that, because a run of writes then produces a run of answers each one step behind, as though the device were echoing. It is not; it is just slow to commit.
A Mini, a Neo and a Plus were each given two different values and asked to read them back. With no gap at all, every answer lagged. With ten milliseconds, all three were correct every time, on both values, and restored cleanly afterwards. Elgato recommends a fifty millisecond polling interval elsewhere in its documentation, and fifty is comfortably enough here.
Nothing in this library waits on your behalf — there is no timer in it — so a
caller that wants to confirm the write has to leave the gap itself. The
round-trip lives in zig build probe -- --sleep, which reads the current
value, writes two others, checks each, and puts the original back.
Diagnostic images #
diagnostic.keyIndexImage draws a key's own index as seven segment
figures on a key-sized image, with a rule under them; Keys.indexImage
is the same thing sized from the key's own feature, so a caller need
not know how big that key's display is. diagnostic.Polarity picks
yellow figures on black or the exact inverse.
The example uses them: every key shows its index at rest and inverts while it is held down, which is the quickest way to see that key numbering, image transforms and event decoding all agree with each other on a device. On a model with a screen, the same figure is echoed there when a key goes down, so one press checks the key path and the screen path against each other.
The rule is not decoration. A key image is rotated and flipped on its way to the display, so a device given the wrong transform shows a 6 where a 9 belongs and looks entirely reasonable doing it — upside down, a seven segment 6 is a 9. An underlined 6 inverted is a 9 with a line over it, which is unmistakable.
The figures are drawn from axis-aligned rectangles rather than set in a typeface. z2d renders text from a TrueType font loaded at run time, and a diagnostic that needs an asset shipped alongside it is one that stops working exactly when something else has already gone wrong. Rectangles also land on whole pixels, so the result is crisp at any key size rather than blurred by antialiasing.
Fuzzing #
zig build fuzz # 10,000 inputs per target
zig build fuzz -- --runs 100000
zig build fuzz -- --target events-decode --seed 42
The targets are in tests/fuzz.zig and cover everything that turns
bytes the hardware said into something this library believes: the input
report framing in Events.decode, the key, encoder and touchscreen
report parsers under it, the image path from a drawn surface to the
bytes that would go on the wire, and the network framing in
framing.zig.
That last one matters most. The rest parse what a USB device said, which is at worst a device this library has the wrong tables for; the framing parses what came out of a socket, and a header declaring its own payload length is exactly the shape of thing that reads past the end of a buffer when it is got wrong. Both of its targets build a well formed prefix — the magic, or a reply's leading byte — around the generated bytes, because random input contains the magic about once in four billion and a target waiting for one would spend the whole run in an early return. The malformed shapes are in the corpus instead, where they are deliberate. Each picks a model first, so the device tables are exercised as well as the parsers — a report that is harmless for one model is a different length and a different shape for another.
zig build test also runs every target over the corpus, so they keep
compiling and an input that once failed keeps being tried.
The loop in tools/fuzz.zig is hand written, and it is worth saying why
rather than using zig build test --fuzz. On Zig 0.16.0 that does not
compile at all for a project with a fuzz test in it: the standard
library's test runner hands @errorReturnTrace()'s result to a function
that takes the other kind of stack trace. The flake patches that one
line, after which it compiles — and then aborts, because nothing in this
release populates the table of program counters the fuzzer works from.
So the loop here brings its own generator and corpus instead. The
in-tree test "fuzz" is wired up regardless, ready for the day coverage
works.
Both the tests and the loop run the allocating paths with an allocation made to
fail. std.testing.checkAllAllocationFailures walks every allocation a handful
of fixed inputs make, failing each in turn and checking that the error comes
back out and that nothing was left behind; the fuzz loop does the same to one
input in four, at a random point, which reaches the error paths of inputs
nobody thought to write down. A test with a working allocator never takes those
paths at all, so an errdefer that is only needed when the second allocation
fails is otherwise never exercised.
Two things that loop reports are worth watching:
- Accepted counts.
Smith.slicehands back an empty slice for a length it does not like andSmith.valueanswers a range's minimum when the input runs out, so a generator that is subtly wrong reports millions of iterations having tested the empty string every time. The driver prints how many inputs got far enough to produce something, and fails the run if a target accepted none. That check caught exactly that bug while this was being written. - The failing input. Most of what a fuzzer finds in Zig is a panic, which ends the process rather than coming back as an error. A panic handler prints the target and the bytes before the trace, so a finding is reproducible rather than just a stack trace.
Permissions #
/dev/hidraw* nodes are normally root-only. Enumerating them needs no
permission — the device list comes from /sys/class/hidraw — but opening
one does, so an unprivileged user gets error.AccessDenied from
Enumerator.next rather than an empty list. That is a better answer than the
silence this used to give, and it is worth knowing which of the two you are
looking at. Grant access with a udev rule rather than running as root.
The rules are generated from the device table rather than written down
beside it, because writing them down is how they come to disagree with it.
src/udev.zig turns StreamDeck.Type into them and zig build udev prints
them:
$ nix develop -c zig build udev
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="0fd9", TAG+="uaccess"
SUBSYSTEM=="hidraw", ATTRS{idVendor}=="1b1c", ATTRS{idProduct}=="2b18", TAG+="uaccess"
Put that in /etc/udev/rules.d/70-streamdeck.rules, then udevadm control --reload-rules && udevadm trigger, and replug the device. The number in the
name matters: uaccess is acted on by systemd's 73-seat-late.rules, so a
file sorting after it — 99-local.rules, say — sets a tag nothing reads, and
the device stays root-only without any error saying so. uaccess is what a
desktop wants: logind hands the device to whoever is logged in at the seat and
takes it back when they log out, so nobody has to be added to a group and a
remote session cannot reach the deck on somebody's desk. For a machine with no
seat, zig build udev -- --group plugdev writes the older shape instead, and
your user then has to be in that group.
Two rules for eighteen models, and the asymmetry is deliberate. Elgato's 0fd9
is Stream Decks and nothing else, so one rule covers every model including ones
not yet released. Corsair's 1b1c is their whole catalogue — the keyboards, the
mice, the coolers — of which exactly one product is a Stream Deck, so that rule
names the product. udev.Vendor carries that judgement per vendor in a switch
with no else, so a device from a third vendor added to StreamDeck.Type
fails to compile until somebody has decided which it is.
On NixOS #
nixosModules.default is the rules and nothing else — no service, no package,
since a library needs nothing else from the system. It installs them as
70-streamdeck.rules through services.udev.packages rather than
services.udev.extraRules, because the latter lands in 99-local.rules, after
uaccess has already been acted on:
{
inputs.zig-streamdeck.url = "git+https://git.jcollie.dev/jeff/zig-streamdeck.git";
# in your configuration
imports = [ inputs.zig-streamdeck.nixosModules.default ];
hardware.streamdeck.enable = true;
# hardware.streamdeck.group = "plugdev"; # for a machine with no seat
}
nix/module.nix is a readable file of Nix rather than something generated at
build time, because a module has to be legible to whoever imports it. That
leaves it able to drift from the generator, so a test in src/udev.zig reads
the module and fails if a rule has gone missing from it — in both the uaccess
and the group shapes.
Where this lives #
The repository is hosted on my Forgejo instance, which is where the issue tracker lives:
git clone https://git.jcollie.dev/jeff/zig-streamdeck.git
The mirrors carry the same history and are there so that the code outlives any one host:
- tangled.org/jcollie.dev/zig-streamdeck
- Radicle, as
rad:z3Vd5zCPSYfAn5ygVN19Lw9wRGyku— see below
Cloning with Radicle #
This repository is also published on Radicle, a peer-to-peer code collaboration network. Its Repository ID is:
rad:z3Vd5zCPSYfAn5ygVN19Lw9wRGyku
With the rad CLI installed and a local identity created (rad auth --alias <name>), start your node and clone:
rad node start
rad clone rad:z3Vd5zCPSYfAn5ygVN19Lw9wRGyku
rad clone finds seeds seeding the repository through your node's routing
table, so the node needs to be running and connected. If discovery fails
because no seed has been found yet, name one directly:
rad clone rad:z3Vd5zCPSYfAn5ygVN19Lw9wRGyku --seed <NID>
The clone checks out the default branch (main) and leaves you seeding the
repository, so your node will serve it to other peers. rad sync pulls later
changes.
To publish work back, push to the rad remote and open a patch:
git push rad HEAD:refs/heads/my-change
rad patch open
The repository is delegated to a single key,
did:key:z6MkoM8gqRFf1hARf3cSX2hhe7kgTfKSQpNksR9uKErWotKq, which is what
authorizes changes to main.
Development #
A Nix flake provides the toolchain:
nix develop
Build, test, and run the example:
zig build
zig build test
zig build run
zig build test runs the tests of both the library module and the example.
Those tests are there as much to keep the code compiling as to check what it
does. Zig does not analyze a function nothing calls, and it does not run the
tests of a file nothing imports, so a file can sit in the tree for a long time
quietly not compiling — which is what had happened here. Two things guard
against it: src/root.zig names every file in the module in its test block,
and build.zig fails the build if a file under src/ is missing from that
list. Anything that cannot be run without a real device is at least referred to
by a refAllDecls so that the compiler still checks it.
Be aware that zig fmt --check . will descend into zig-pkg/, the gitignored
directory the Zig package manager extracts dependencies into, and report
formatting in code this project does not own; check this project's own sources
with:
zig fmt --check build.zig src
This repository follows the REUSE specification for licensing metadata:
reuse lint
References cited #
Elgato does publish protocol documentation, which this library did not know for most of its life. It covers six device families and settles several things the implementations below disagreed about. It does not cover the Studio, the Pedal, the Original or the Galleon, so for those the independent implementations are still all there is; where they disagree, the README and the device modules say so rather than picking a winner quietly. The Galleon is the odd one: python-elgato-streamdeck does not know it exists, and neither do the Go libraries, so its two sources are node-elgato-stream-deck and rust-elgato-streamdeck.
- Elgato. Stream Deck HID API.
https://docs.elgato.com/streamdeck/hid/intro. First-party documentation of
the protocol, with a general reference at
/streamdeck/hid/generaland a page per device family: Classic, XL, Neo, Plus, Plus XL, and Mini, the last documented as a legacy protocol that differs from the rest. It gives the USB product ids, key grid dimensions, key and panel pixel sizes, image rotations, and the feature and output report layouts. It is the source for the panel sizes inPanel.zig, forGet Unit Information, for the sleep timeout and colour fill commands, and for the Plus XL's rotation. It confirmed every key image size in the table above. It says nothing about the Studio, the Pedal, the Original or the Galleon. - Camera, Dean. python-elgato-streamdeck: Python library to control an Elgato Stream Deck. https://github.com/abcminiuser/python-elgato-streamdeck. The de-facto reference implementation. Its per-model device classes are the source for the USB product ids, the key grid geometry, the key image sizes and formats, the rotation and flips each display needs, the image report lengths and header layouts, the feature reports carrying the serial number and firmware version, and the decoding of input reports for keys, dials and the touchscreen.
- Waller, Julian. node-elgato-stream-deck: A Node.js library for interfacing
with the Elgato Stream Deck.
https://github.com/Julusian/node-elgato-stream-deck. The second source.
models/definitions.tsgives each model's control layout and key pixel sizes,modelInfo.tsmaps product ids to models, and theimageWriterandheaderGeneratorservices give the image report sizes, the page numbering and the header byte layouts.models/galleon-k100.tsis the source for the Galleon's keepalive: it sends feature report0x03 0x27on a 500ms interval from open until close and calls it a ping. That file also confirms the model takes no flip in either axis, andservices/encoderLed/galleonK100.tsis the source for the encoder rings: the0x03 0x24report, four LEDs to a ring, indices running from the right-hand encoder, and theledRingOffsetthat rotates each ring's segment zero into place.models/definitions.tsgives the key layout — 160-pixel keys at a pitch of 224, 56 in from each side, with the strip above them — which is what makes the checkerboard test able to show the panel is one continuous sheet. - Barreiros, Raphael. feat: support Corsair Galleon 100 SD, pull request 63 to
OpenActionAPI/rust-elgato-streamdeck.
https://github.com/OpenActionAPI/rust-elgato-streamdeck/pull/63. The second
source for the Galleon and an independent one, though open rather than
merged — the library itself does not carry this yet. It sends the same
0x03 0x27at the same 500ms interval, padded to thirty-two bytes, and calls it refreshing software mode — driven from each operation rather than a timer, with blocking reads split into 100ms windows to keep the refresh timely. It also selects HID interface 0 for the same reason this library does, since opening by vendor and product id alone can land on a keyboard interface, and it derives the same encoder ring numbering by a different route, which is the only reason to believe either. It was tested against firmware 3.06.005. - Elgato. Elgato Stream Deck Studio — Technical Specifications. https://help.elgato.com/hc/en-us/articles/29982976486669-Elgato-Stream-Deck-Studio-Technical-Specifications. Cited for the Studio carrying thirty-two keys and two rotary encoders and no touch keys. It does not give the key resolution, which is why that figure is still unconfirmed here.
The network transport has sources of its own. Elgato publishes nothing at all
about it — no specification, no port number, no SDK — so the three below are
the whole of what is known, and framing.zig follows them where they agree and
says so in a comment where they do not.
- Waller, Julian. node-elgato-stream-deck,
packages/tcp. https://github.com/Julusian/node-elgato-stream-deck/tree/main/packages/tcp. The primary source, and the most trustworthy: it is what Bitfocus Companion ships, and it is tested against real Studio and Network Dock hardware.socketWrapper.tsgives the header layout, the two framings and how a device is classified into one of them;hid-device/cora.tsandlegacy.tsgive the flags, the operation codes and the split between verbatim reports and host commands;device2Info.tsgives the child device table. - Haukcode. Haukcode.StreamDeck. https://github.com/HakanL/Haukcode.StreamDeck. A .NET implementation with a packet capture of Elgato's own application beside it, which is the only source that can say what the official software does rather than what a reimplementation found sufficient. Corroborates the header layout, the keepalive exchange and the big-endian reply length, and is explicit about which of its own claims are untested.
- SKAARHOJ. go-streamdeck. https://github.com/SKAARHOJ/go-streamdeck, and the notes at https://wiki.skaarhoj.com/books/raw-panel/page/stream-deck-on-raw-panel. An independent Go implementation of the older, headerless framing, which is the third agreement on the fixed frame sizes and on the image path being unchanged from USB.
License #
MIT — see LICENSES/MIT.txt.
Copyright © 2025 Jeffrey C. Ollie.