This document describes the algorithm used to detect button presses and releases on the Stream Deck+ device.
The Stream Deck+ sends 14-byte packets for button events. The first byte (data[0]
) determines the event type:
1
: Button or encoder event2
: Touchscreen event3
: Dial event
For button events (data[0] == 1
), the data format is as follows:
[1 0 8 0 X Y Z W V U T S R Q]
Where:
X
(data[4]): Button 0 state (1 = pressed, 0 = released)Y
throughQ
(data[5] through data[12]): Buttons 1-7 states (1 = pressed, 0 = released)
-
Button 0 Detection:
- Press: Check if
data[4] == 1
- Release: Check if
data[4] == 0
and button was previously pressed
- Press: Check if
-
Buttons 1-7 Detection:
- For each position
i
from 5 to 12:- Calculate button number:
buttonNum = i - 4
- Press: Check if
data[i] == 1
- Release: Check if
data[i] == 0
and button was previously pressed
- Calculate button number:
- For each position
-
State Tracking:
- Maintain an array
lastKeyStates[8]
to track the previous state of each button - Update state only when a change is detected
- Use state tracking to prevent duplicate press/release events
- Maintain an array
Button 0 press:
[1 0 8 0 1 0 0 0 0 0 0 0 0 0]
Button 0 release:
[1 0 8 0 0 0 0 0 0 0 0 0 0 0]
Button 1 press:
[1 0 8 0 0 1 0 0 0 0 0 0 0 0]
Button 1 release:
[1 0 8 0 0 0 0 0 0 0 0 0 0 0]
- The algorithm uses a polling frequency of 20Hz (50ms intervals)
- Raw data is only printed when an actual button event is detected
- Button numbers are zero-based (0-7)
- Array bounds checking is implemented to prevent index out of range errors
- The algorithm handles both press and release events for all buttons
- Multiple Button Presses: The algorithm can detect multiple buttons pressed simultaneously
- Rapid Presses: State tracking prevents duplicate events during rapid button presses
- Out of Range: Button numbers >= 8 are skipped to prevent array index errors
- Encoder Events: The algorithm distinguishes between button and encoder events by checking
data[1]
anddata[2]