Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to digital v2 traits #18

Merged
merged 1 commit into from
Jul 1, 2019
Merged
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
28 changes: 16 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,31 @@ impl Pin {
}
}

impl hal::digital::OutputPin for Pin {
fn set_low(&mut self) {
self.0.set_value(0).unwrap()
impl hal::digital::v2::OutputPin for Pin {
type Error = sysfs_gpio::Error;

fn set_low(&mut self) -> Result<(), Self::Error> {
self.0.set_value(0)
}

fn set_high(&mut self) {
self.0.set_value(1).unwrap()
fn set_high(&mut self) -> Result<(), Self::Error> {
self.0.set_value(1)
}
}

impl hal::digital::InputPin for Pin {
fn is_high(&self) -> bool{
if !self.0.get_active_low().unwrap() {
self.0.get_value().unwrap() != 0
impl hal::digital::v2::InputPin for Pin {
type Error = sysfs_gpio::Error;

fn is_high(&self) -> Result<bool, Self::Error> {
if !self.0.get_active_low()? {
self.0.get_value().map(|val| val != 0)
} else {
self.0.get_value().unwrap() == 0
self.0.get_value().map(|val| val == 0)
}
}

fn is_low(&self) -> bool{
!self.is_high()
fn is_low(&self) -> Result<bool, Self::Error> {
self.is_high().map(|val| !val)
}
}

Expand Down