-
Notifications
You must be signed in to change notification settings - Fork 1
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
SNS - High Power Relay #55
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
name = "hyped_control" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
hyped_io = { path = "../io" } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// need to take in a GPIO pin like Keyence does | ||
// functions: switch_on, switch_off | ||
|
||
use hyped_io::gpio::HypedGpioPin; | ||
|
||
pub struct HighPowerRelay<T: HypedGpioPin> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a Rust doc comment here explaining what this does |
||
gpio: T, | ||
} | ||
|
||
impl<T: HypedGpioPin> HighPowerRelay<T> { | ||
pub fn new(gpio: T) -> HighPowerRelay<T> { | ||
HighPowerRelay { gpio } | ||
} | ||
|
||
pub fn switch_on(&mut self) { | ||
self.gpio.switch_on(); | ||
} | ||
|
||
pub fn switch_off(&mut self) { | ||
self.gpio.switch_off(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#![no_std] | ||
|
||
pub mod hp_relay; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,47 @@ | ||
/// Abstraction for a GPIO pin so that sensors can be tested with a mock GPIO pin | ||
pub trait HypedGpioPin { | ||
fn is_high(&mut self) -> bool; | ||
} | ||
|
||
pub mod mock_gpio { | ||
use heapless::Vec; | ||
|
||
/// A mock GPIO pin that can be used for testing | ||
pub struct MockGpio { | ||
current_value: bool, | ||
next_values: Vec<bool, 10>, | ||
} | ||
|
||
impl crate::gpio::HypedGpioPin for MockGpio { | ||
fn is_high(&mut self) -> bool { | ||
let next_value = self.next_values.pop().unwrap_or(self.current_value); | ||
self.current_value = next_value; | ||
self.current_value | ||
} | ||
} | ||
|
||
impl MockGpio { | ||
pub fn new(values: Vec<bool, 10>) -> MockGpio { | ||
let mut next_values = values.clone(); | ||
next_values.reverse(); | ||
MockGpio { | ||
current_value: false, | ||
next_values, | ||
} | ||
} | ||
} | ||
} | ||
/// Abstraction for a GPIO pin so that sensors can be tested with a mock GPIO pin | ||
pub trait HypedGpioPin { | ||
fn is_high(&mut self) -> bool; | ||
fn switch_on(&mut self) -> bool; | ||
fn switch_off(&mut self) -> bool; | ||
} | ||
|
||
Comment on lines
+1
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We actually need to separate the input and output GPIO pins, like in PR #40 lib/io/src/gpio.rs. |
||
pub mod mock_gpio { | ||
use heapless::Vec; | ||
|
||
/// A mock GPIO pin that can be used for testing | ||
pub struct MockGpio { | ||
current_value: bool, | ||
next_values: Vec<bool, 10>, | ||
} | ||
|
||
impl crate::gpio::HypedGpioPin for MockGpio { | ||
fn is_high(&mut self) -> bool { | ||
let next_value = self.next_values.pop().unwrap_or(self.current_value); | ||
self.current_value = next_value; | ||
self.current_value | ||
} | ||
|
||
fn switch_on(&mut self) -> bool { | ||
let next_value = self.next_values.pop().unwrap_or(self.current_value); | ||
self.current_value = next_value; | ||
self.current_value | ||
} | ||
|
||
fn switch_off(&mut self) -> bool { | ||
let next_value = self.next_values.pop().unwrap_or(self.current_value); | ||
self.current_value = next_value; | ||
self.current_value | ||
} | ||
} | ||
|
||
impl MockGpio { | ||
pub fn new(values: Vec<bool, 10>) -> MockGpio { | ||
let mut next_values = values.clone(); | ||
next_values.reverse(); | ||
MockGpio { | ||
current_value: false, | ||
next_values, | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove