Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ edition = "2018"


[dependencies]
rppal = "0.12.0"
rppal = "0.22"

2 changes: 1 addition & 1 deletion src/debounce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 16 additions & 3 deletions src/input_devices.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down Expand Up @@ -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();
}
};
Expand Down Expand Up @@ -219,15 +221,26 @@ impl Button {
}

/// Adds an async interrupt for the corresponding trigger type to support `when_pressed`/`when_released`
pub(crate) fn action_on<C>(&mut self, active: bool, action: C) -> Result<(), gpio::Error>
pub(crate) fn action_on<C>(&mut self, active: bool, mut action: C) -> Result<(), gpio::Error>
where
C: FnMut(Level) + Send + 'static,
{
let trigger = match active {
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`)
Expand Down
Loading