butt_head/event.rs
1use crate::{TimeDuration, TimeInstant};
2
3/// A button event produced by the state machine.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5#[cfg_attr(feature = "defmt", derive(defmt::Format))]
6pub enum Event<D: TimeDuration, I: TimeInstant<Duration = D>> {
7 /// The button was pressed. Fires immediately on press edge.
8 /// `at` is the timestamp of the press, identical to what
9 /// [`crate::ButtHead::press_instant`] returns during the pressed state.
10 Press { at: I },
11
12 /// The button was released. `duration` is the total time it was held.
13 /// `click_follows` is `true` when a [`Event::Click`] will follow (the
14 /// release ends a click gesture), and `false` when it ends a hold gesture.
15 Release { duration: D, click_follows: bool },
16
17 /// A complete click gesture (press + release, no hold).
18 /// `count` starts at 1. Fires once after `click_timeout` expires with no
19 /// further press. A double-click produces a single `Click { count: 2 }`.
20 Click { count: u8 },
21
22 /// The button is being held. Fires repeatedly at a configured interval.
23 /// `clicks_before` is the number of clicks that preceded this hold
24 /// (0 = plain hold, 1 = click+hold, 2 = double-click+hold, ...).
25 /// `level` increments on each repeat (0 = first hold event, 1 = second, ...).
26 Hold { clicks_before: u8, level: u8 },
27}