-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from UCI-HyperXite/feature/signal-light
Add `SignalLight` component and demo with RPPAL
- Loading branch information
Showing
6 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod signal_light; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use tracing::debug; | ||
|
||
use rppal::gpio::{Gpio, OutputPin}; | ||
|
||
pub struct SignalLight { | ||
pin: OutputPin, | ||
} | ||
|
||
const PIN_SIGNAL_LIGHT: u8 = 21; | ||
|
||
impl SignalLight { | ||
pub fn new() -> Self { | ||
SignalLight { | ||
pin: Gpio::new() | ||
.unwrap() | ||
.get(PIN_SIGNAL_LIGHT) | ||
.unwrap() | ||
.into_output(), | ||
} | ||
} | ||
|
||
pub fn disable(&mut self) { | ||
debug!("Disabling signal light."); | ||
self.pin.set_low(); | ||
} | ||
|
||
pub fn enable(&mut self) { | ||
debug!("Enabling signal light."); | ||
self.pin.set_high(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use tracing::info; | ||
|
||
use crate::components::signal_light::SignalLight; | ||
|
||
pub async fn blink(mut signal_light: SignalLight) { | ||
let mut i = 0; | ||
|
||
info!("Starting blink demo."); | ||
loop { | ||
tokio::time::sleep(std::time::Duration::from_millis(500)).await; | ||
if i % 4 == 0 { | ||
signal_light.enable(); | ||
} else if i % 4 == 1 { | ||
signal_light.disable(); | ||
} | ||
|
||
i += 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters