use super::Duration;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ButtonConfig {
pub debounce: Duration,
pub double_click: Duration,
pub long_press: Duration,
pub mode: Mode,
}
impl ButtonConfig {
pub fn new(
debounce: Duration,
double_click: Duration,
long_press: Duration,
mode: Mode,
) -> Self {
Self {
debounce,
double_click,
long_press,
mode,
}
}
}
impl Default for ButtonConfig {
fn default() -> Self {
Self {
debounce: Duration::from_millis(10),
double_click: Duration::from_millis(350),
long_press: Duration::from_millis(1000),
mode: Mode::default(),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Mode {
#[default]
PullUp,
PullDown,
}
impl Mode {
pub const fn is_pullup(&self) -> bool {
matches!(self, Mode::PullUp)
}
pub const fn is_pulldown(&self) -> bool {
!self.is_pullup()
}
}