Skip to main content

pot_head/
state.rs

1use crate::hysteresis::HysteresisState;
2
3use crate::filters::EmaFilter;
4
5#[cfg(feature = "moving-average")]
6use crate::filters::MovingAvgFilter;
7
8pub struct State<T> {
9    /// Hysteresis processing state
10    pub hysteresis: HysteresisState<T>,
11
12    /// EMA filter state
13    pub ema_filter: Option<EmaFilter>,
14
15    /// Moving average filter state
16    #[cfg(feature = "moving-average")]
17    pub ma_filter: Option<MovingAvgFilter>,
18
19    /// Last output value (for dead zones)
20    pub last_output: T,
21
22    /// Grab mode: whether pot has been grabbed
23    #[cfg(feature = "grab-mode")]
24    pub grabbed: bool,
25
26    /// Grab mode: virtual parameter value (locked when not grabbed)
27    #[cfg(feature = "grab-mode")]
28    pub virtual_value: T,
29
30    /// Grab mode: physical position after processing (before snap zones)
31    #[cfg(feature = "grab-mode")]
32    pub physical_position: T,
33
34    /// Grab mode: last physical position (for PassThrough crossing detection)
35    #[cfg(feature = "grab-mode")]
36    pub last_physical: T,
37
38    /// Grab mode: whether we've initialized last_physical (for PassThrough first read)
39    #[cfg(feature = "grab-mode")]
40    pub passthrough_initialized: bool,
41}
42
43impl<T> Default for State<T>
44where
45    T: Default + Copy,
46{
47    fn default() -> Self {
48        Self {
49            hysteresis: HysteresisState::default(),
50            ema_filter: None,
51            #[cfg(feature = "moving-average")]
52            ma_filter: None,
53            last_output: T::default(),
54            #[cfg(feature = "grab-mode")]
55            grabbed: false,
56            #[cfg(feature = "grab-mode")]
57            virtual_value: T::default(),
58            #[cfg(feature = "grab-mode")]
59            physical_position: T::default(),
60            #[cfg(feature = "grab-mode")]
61            last_physical: T::default(),
62            #[cfg(feature = "grab-mode")]
63            passthrough_initialized: false,
64        }
65    }
66}