This question evaluates competency in real-time event stream processing, per-button state management, and timing-based classification of input events such as distinguishing single versus long presses.
Implement a click detector for multiple physical buttons.
You receive button state updates as a stream. Each update provides:
button_id
(integer)
state
where
1 = pressed
,
0 = released
A “click” is a press followed by a release. Classify each completed click as:
For each detected click, output something like:
Button 1: Single Click
Button 2: Long Click
Requirements / edge cases:
Follow-up:
If state updates do not arrive every 10 ms (variable intervals), how would you modify the implementation? Assume you can obtain timestamps (e.g., via a system call like now_ms()) for each update.