use crate::buttons::core::{PollButton, TransitionEvent};
#[derive(Debug)]
pub enum Event {
Click,
}
pub struct LazyMonitor<T: PollButton> {
button: T,
}
impl<T: PollButton> LazyMonitor<T> {
pub fn new(button: T) -> LazyMonitor<T> {
LazyMonitor {button}
}
pub fn free(self) -> T {
self.button
}
pub fn poll(&mut self) -> Option<Event> {
match self.button.poll_event() {
Some(TransitionEvent::Press) => None,
Some(TransitionEvent::Release) => Some(Event::Click),
None => None,
}
}
}
pub struct EagerMonitor<T: PollButton> {
button: T,
}
impl<T: PollButton> EagerMonitor<T> {
pub fn new(button: T) -> EagerMonitor<T> {
EagerMonitor {button}
}
pub fn free(self) -> T {
self.button
}
pub fn poll(&mut self) -> Option<Event> {
match self.button.poll_event() {
Some(TransitionEvent::Press) => Some(Event::Click),
Some(TransitionEvent::Release) => None,
None => None,
}
}
}