From fe8684976c4c8710763612ba762ff78e33bffbf5 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Mon, 20 May 2019 00:01:20 +0200 Subject: [PATCH] Move to digital v2 traits The v1 traits are deprecated because they don't have a way to report errors. --- src/lib.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 487ae16..768cfe6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 { + 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 { + self.is_high().map(|val| !val) } }