Expand description
Button event recognition state machine.
Resolves a stream of raw ButtonEdge events plus a monotonic
millisecond clock into the high-level ButtonEvents the UX is
defined in terms of: single, double, triple, and quadruple clicks,
plus long-press and an optional very-long-press.
The machine is pure logic — no embassy, no hardware, no I/O — so it can be exhaustively unit-tested with synthetic time. Callers are expected to:
- Call
ButtonFsm::on_edgefor each debounced press / release. - Call
ButtonFsm::pollwhen the deadline reported byButtonFsm::next_deadlineelapses.
Both methods can produce a ButtonEvent when one becomes
resolvable.
§Recognition rules
- A “click” is a press-then-release where the hold duration is at
most
max_click_hold. - One to four clicks within
inter_click_gapof each other produceButtonEvent::Single,ButtonEvent::Double,ButtonEvent::Triple, orButtonEvent::Quadrespectively. Quad fires immediately on the fourth release without waiting for the gap; single / double / triple fire after the gap elapses with no further press. - By default, holding the button continuously for
long_pressproducesButtonEvent::Longwhile the button is still pressed and consumes any clicks accumulated before the hold began. - When
very_long_pressis configured, releasing betweenlong_pressandvery_long_pressproducesButtonEvent::Long. Remaining held throughvery_long_pressproducesButtonEvent::VeryLongwithout first emittingLong. This supports a navigational hold plus a distinct always-available sleep hold. - Releases longer than
max_click_holdbut shorter thanlong_pressare discarded clicks; if there are accumulated prior clicks they are emitted, otherwise nothing fires. This matches the rule: a press that’s “too long to be a click but too short to be a long-press” is a user error and should not silently become either.
Structs§
- Button
Fsm - Button event recognition state machine.
- Button
Timings - Tunable timings; tune on real hardware.
Enums§
- Button
Edge - Raw debounced button transition.
- Button
Event - High-level button event recognized by the FSM.