Skip to content

Commit

Permalink
Merge pull request #14 from andrewdavidmackenzie/run-gui
Browse files Browse the repository at this point in the history
fake gpio module added
  • Loading branch information
andrewdavidmackenzie authored May 13, 2024
2 parents 06e5d8f + b6d259d commit 6b9a01d
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 15 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@ clippy: piclippy
cargo clippy --features "iced" --tests --no-deps
#-- --warn clippy::pedantic -D warnings

# This will build all binaries on the current host, be it macos, linux or raspberry pi
# Only enable the "iced" feature so we only build the "piggui" binary
# To build both binaries, running this make on a Pi directly, we will need to modify this
# Enable the "iced" feature so we only build the "piggui" binary on the current host (macos, linux or raspberry pi)
# To build both binaries on a Pi directly, we will need to modify this
.PHONY: build
build:
cargo build --features "iced"

.PHONY: run
run:
cargo run --features "iced"

# This will build all binaries on the current host, be it macos, linux or raspberry pi - with release profile
.PHONY: release-build
release-build:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,14 @@ A headless binary that is only built on RaspberryPi and that has no UI.
We use "cross" to cross compile for Raspberry Pi from Linux or macOS.
Install docker or podman and "cross" for cross compiling rust on your host for the Raspberry Pi.

### Building in general on host development machine
### Building on host development machine
Run `"make"` on macos or linux (or in fact RPi also) host to build these binaries:
* `target/debug/piggui` - GUI version without GPIO, to enable UI development on a host
* `target/aarch64-unknown-linux-gnu/release/piggui` - GUI version for Pi with GPIO, can be run natively from RPi command line
* `target/aarch64-unknown-linux-gnu/release/piglet` - Headless version for Pi with GPIO, can be run natively from RPi command line

Use `"make run"` to start `piggui` on the local machine - for GUI development.

### Building for Pi
#### Helper Env vars
There are a couple of env vars that can be setup to help you interact with your pi.
Expand Down
53 changes: 53 additions & 0 deletions src/gpio/mod.rs
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,
}
}
}
21 changes: 14 additions & 7 deletions src/piggui.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// When built with the "rppal" feature for interacting with GPIO - can only be built for RPi
/// When built with the "rppal" feature include code for interacting with GPIO
#[cfg(feature = "rppal")]
use rppal;

/// When built with the "iced" feature for GUI. This can be on Linux, Macos or RPi (linux)
#[cfg(feature = "iced")]
use iced;
mod gpio;

// This binary will only be built with the "iced" feature enabled, by use of "required-features"
// in Cargo.toml so no need for the feature to be used here for conditional compiling
use iced::widget::text;
use iced::{window, Element, Sandbox, Settings};

Expand All @@ -15,6 +13,15 @@ fn main() -> Result<(), iced::Error> {
..Default::default()
};

// TODO figure out how to connect config and state to the UI....
#[cfg(feature = "rppal")]
{
let config = gpio::GPIOConfig::new();
println!("Pin configs: {:?}", config);
let state = gpio::GPIOState::get(&config);
println!("OINK: {:?}", state);
}

Gpio::run(Settings {
window,
..Default::default()
Expand All @@ -34,7 +41,7 @@ impl Sandbox for Gpio {
}

fn title(&self) -> String {
String::from("Pigg")
String::from("Piggui")
}

fn update(&mut self, message: Message) {
Expand Down
14 changes: 10 additions & 4 deletions src/piglet.rs
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);
}

0 comments on commit 6b9a01d

Please sign in to comment.