From 61a2ef02bbda7a062b7f7ac6cdcdde5538ad729d Mon Sep 17 00:00:00 2001 From: Ryan Kurte Date: Wed, 10 Oct 2018 18:37:24 +1300 Subject: [PATCH 1/2] Added input pin impl (requires unproven) --- Cargo.toml | 2 +- src/lib.rs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index c483225..1f7f95f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/japaric/linux-embedded-hal" version = "0.2.0" [dependencies] -embedded-hal = "0.2.0" +embedded-hal = { version = "0.2.0", features = ["unproven"] } i2cdev = "0.3.1" spidev = "0.3.0" sysfs_gpio = "0.5.1" diff --git a/src/lib.rs b/src/lib.rs index 7ff21f3..2b0756a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -119,6 +119,16 @@ impl hal::digital::OutputPin for Pin { } } +impl hal::digital::InputPin for Pin { + fn is_high(&self) -> bool{ + self.0.get_value().unwrap() != 0 + } + + fn is_low(&self) -> bool{ + self.0.get_value().unwrap() == 0 + } +} + impl ops::Deref for Pin { type Target = sysfs_gpio::Pin; From 45130042e84d6a52e3737a7d18b8f9fc71a4aae0 Mon Sep 17 00:00:00 2001 From: Ryan Kurte Date: Wed, 10 Oct 2018 19:00:14 +1300 Subject: [PATCH 2/2] Include pin active low logic --- src/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2b0756a..0c8782e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -121,11 +121,15 @@ impl hal::digital::OutputPin for Pin { impl hal::digital::InputPin for Pin { fn is_high(&self) -> bool{ - self.0.get_value().unwrap() != 0 + if !self.0.get_active_low().unwrap() { + self.0.get_value().unwrap() != 0 + } else { + self.0.get_value().unwrap() == 0 + } } fn is_low(&self) -> bool{ - self.0.get_value().unwrap() == 0 + !self.is_high() } }