diff --git a/Cargo.toml b/Cargo.toml index ced06bc..589dfcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,5 @@ edition = "2018" [dependencies] -rppal = "0.12.0" +rppal = "0.22" diff --git a/src/debounce.rs b/src/debounce.rs index 36a18e6..a15ab59 100644 --- a/src/debounce.rs +++ b/src/debounce.rs @@ -88,7 +88,7 @@ impl Debounced { false => Trigger::FallingEdge, }; let timeout = timeout.map(|seconds| Duration::from_millis((seconds * 1000.0) as u64)); - self.inner.pin.set_interrupt(trigger).unwrap(); + self.inner.pin.set_interrupt(trigger, None).unwrap(); loop { self.inner.pin.poll_interrupt(true, timeout).unwrap(); // Check that enough time has passed since the last press diff --git a/src/input_devices.rs b/src/input_devices.rs index b89914a..b250d25 100644 --- a/src/input_devices.rs +++ b/src/input_devices.rs @@ -1,6 +1,8 @@ //! Input device component interfaces for devices such as `Button` use rppal::gpio::{self, Gpio, InputPin, Level, Trigger}; use std::time::Duration; +use rppal::gpio::Event; +//use rppal::gpio::{Event, Level}; /// Represents a generic GPIO input device. #[derive(Debug)] @@ -66,7 +68,7 @@ macro_rules! impl_events_mixin { false => Trigger::FallingEdge, }; let timeout = timeout.map(|seconds| Duration::from_millis((seconds * 1000.0) as u64)); - self.pin.set_interrupt(trigger).unwrap(); + self.pin.set_interrupt(trigger, None).unwrap(); self.pin.poll_interrupt(true, timeout).unwrap(); } }; @@ -219,7 +221,7 @@ impl Button { } /// Adds an async interrupt for the corresponding trigger type to support `when_pressed`/`when_released` - pub(crate) fn action_on(&mut self, active: bool, action: C) -> Result<(), gpio::Error> + pub(crate) fn action_on(&mut self, active: bool, mut action: C) -> Result<(), gpio::Error> where C: FnMut(Level) + Send + 'static, { @@ -227,7 +229,18 @@ impl Button { true => Trigger::RisingEdge, false => Trigger::FallingEdge, }; - self.pin.set_async_interrupt(trigger, action) + + let adapted_action = move |event: Event| { + if let Some(level) = match event.trigger { + Trigger::RisingEdge => Some(Level::High), + Trigger::FallingEdge => Some(Level::Low), + _ => None, + } { + action(level); + } + }; + + self.pin.set_async_interrupt(trigger, None, adapted_action) } /// Removes all previously configured async trigger(s) (E.g. `when_pressed`/`when_released`)