-
-
Notifications
You must be signed in to change notification settings - Fork 16
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 #14 from andrewdavidmackenzie/run-gui
fake gpio module added
- Loading branch information
Showing
5 changed files
with
86 additions
and
15 deletions.
There are no files selected for viewing
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
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,53 @@ | ||
/// When built with the "rppal" feature for interacting with GPIO - can only be built for RPi | ||
#[cfg(feature = "rppal")] | ||
use rppal::gpio::{InputPin, Level, Trigger}; | ||
|
||
// TODO will need to create a GPIOConfig and state that is NOT related to rrpal - | ||
// for use in the UI when not compiled for Pi | ||
|
||
// TODO do this for real | ||
#[derive(Debug)] | ||
#[allow(dead_code)] // TODO remove later | ||
pub struct GPIOState { | ||
pin_state: [Option<Level>; 40] | ||
} | ||
|
||
impl GPIOState { | ||
pub fn get(_config: &GPIOConfig) -> GPIOState { | ||
GPIOState { | ||
pin_state: [None; 40] | ||
} | ||
} | ||
} | ||
|
||
// TODO - add in here all the possible config options for GPIO | ||
#[derive(Debug)] | ||
#[allow(dead_code)] // TODO remove later | ||
pub enum PinConfig { | ||
Input(InputPin, Option<Trigger>), | ||
Output | ||
} | ||
|
||
const SDA1: usize = 2; | ||
|
||
const NO_CONFIG: Option<PinConfig> = None; | ||
|
||
// Model the 40 pin GPIO connections - including Ground, 3.3V and 5V outputs | ||
// If no specific config is set on a pin, it will have None | ||
#[derive(Debug)] | ||
#[allow(dead_code)] // TODO remove later | ||
pub struct GPIOConfig { | ||
pin_configs: [Option<PinConfig>; 40] | ||
} | ||
|
||
impl GPIOConfig { | ||
pub fn new() -> Self { | ||
let mut pin_configs = [NO_CONFIG; 40]; | ||
|
||
pin_configs[SDA1] = None; | ||
|
||
GPIOConfig { | ||
pin_configs, | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,7 +1,13 @@ | ||
/// When built with the "rppal" feature for interacting with GPIO - can only be built for RPi | ||
#[cfg(feature = "rppal")] | ||
use rppal; | ||
// This binary will only be built when the "rppal" feature for interacting with GPIO is enabled | ||
// so no need for conditional compilation here | ||
|
||
mod gpio; | ||
|
||
fn main() { | ||
println!("Oink"); | ||
let config = gpio::GPIOConfig::new(); | ||
println!("Pin configs: {:?}", config); | ||
|
||
let state = gpio::GPIOState::get(&config); | ||
|
||
println!("Oink: {:?}", state); | ||
} |