From c5f700d67cfc4852f3659b2c50de8f00fc403afb Mon Sep 17 00:00:00 2001 From: Zgarbul Andrey Date: Sun, 25 Feb 2018 11:29:49 +0300 Subject: [PATCH 1/3] set_state and toggle for digital::OutputPin set_state and toggle with default implementation --- src/digital.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/digital.rs b/src/digital.rs index 88b0c3c4a..ad71d9079 100644 --- a/src/digital.rs +++ b/src/digital.rs @@ -12,7 +12,27 @@ pub trait OutputPin { fn set_low(&mut self); /// Sets the pin high - fn set_high(&mut self); + fn set_high(&mut self) { + !self.is_low() + } + + /// Sets the pin to state + fn set_state(&mut self, state: bool) { + if state { + self.set_high(); + } else { + self.set_low(); + } + } + + /// Toggles the pin state + fn toggle(&mut self) { + if self.is_low() { + self.set_high(); + } else { + self.set_low(); + } + } } /// Single digital input pin From 92830f604acd9098b1c69e605f1fde3e1f9d40fa Mon Sep 17 00:00:00 2001 From: Zgarbul Andrey Date: Sun, 25 Feb 2018 15:41:36 +0300 Subject: [PATCH 2/3] Update digital.rs --- src/digital.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/digital.rs b/src/digital.rs index ad71d9079..5f1760add 100644 --- a/src/digital.rs +++ b/src/digital.rs @@ -3,7 +3,9 @@ /// Single digital output pin pub trait OutputPin { /// Is the output pin high? - fn is_high(&self) -> bool; + fn is_high(&self) -> bool { + !self.is_low() + } /// Is the output pin low? fn is_low(&self) -> bool; @@ -12,9 +14,7 @@ pub trait OutputPin { fn set_low(&mut self); /// Sets the pin high - fn set_high(&mut self) { - !self.is_low() - } + fn set_high(&mut self); /// Sets the pin to state fn set_state(&mut self, state: bool) { From 7be3a5e43794512e2fd95d92b024b69c6f89f3d9 Mon Sep 17 00:00:00 2001 From: Zgarbul Andrey Date: Sun, 25 Feb 2018 16:50:02 +0300 Subject: [PATCH 3/3] get_state --- src/digital.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/digital.rs b/src/digital.rs index 5f1760add..9c9f9db41 100644 --- a/src/digital.rs +++ b/src/digital.rs @@ -25,7 +25,12 @@ pub trait OutputPin { } } - /// Toggles the pin state + /// Gets pin's state + fn get_state(&self) -> bool { + !self.is_low() + } + + /// Toggles pin's state fn toggle(&mut self) { if self.is_low() { self.set_high(); @@ -43,4 +48,9 @@ pub trait InputPin { /// Is the input pin low? fn is_low(&self) -> bool; + + /// Gets pin's state + fn get_state(&self) -> bool { + !self.is_low() + } }