Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion hermes-five/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = ["dep:serde", "dep:serde_json", "dep:typetag"]
mocks = []

[dependencies]
hermes-five-macros = { path = "../hermes-five-macros", version="0.1.0" }
hermes-five-macros = { path = "../hermes-five-macros", version = "0.1.0" }
dyn-clone = "1.0.19"
futures = "0.3.31"
log = "0.4.26"
Expand Down Expand Up @@ -151,6 +151,13 @@ path = "examples/servo/animate.rs"
name = "servo_p9685"
path = "examples/servo/pca9685.rs"

# ########################################
# EXPANDERS examples

[[example]]
name = "expanders_pcf8575"
path = "examples/expanders/pcf8575.rs"

# ########################################
# IO examples

Expand Down
33 changes: 33 additions & 0 deletions hermes-five/examples/expanders/pcf8575.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//! Demonstrates how to use and control INPUT/OUTPUT devices through the PCF8575 expander.

use hermes_five::devices::Led;
use hermes_five::hardware::{Board, BoardEvent, PCF8575};
use hermes_five::pause;

#[hermes_five::runtime]
async fn main() {
let board = Board::start().unwrap();

board.on(BoardEvent::OnReady, |board: Board| async move {
let pcf8575 = PCF8575::default(&board)?;

// Register leds for each of the 16 channels of the PCF8575.
let mut leds = Vec::new();
for i in 0..16 {
leds.push(Led::new_sink(&pcf8575, i, false)?);
}

// Create a LED chaser.
loop {
for curr in 0..16 {
let prev = if curr == 0 { 15 } else { curr - 1 };
leds[prev].turn_off()?;
leds[curr].turn_on()?;
pause!(100);
}
}

#[allow(unreachable_code)]
Ok(())
});
}
7 changes: 6 additions & 1 deletion hermes-five/examples/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ The available examples are:
- **button/pullup.rs:** Demonstrates how to use a pullup type push button input device.
- **button/inverted.rs:** Demonstrates how to use 'inverted' push buttons.

# Expanders

- **expanders/pcf8575.rs:** Demonstrates how to use and control INPUT/OUTPUT devices through the PCF8575 expander.

# Animation

- **animation/animation.rs:** Demonstrates how to create and run a complex animation (with multiple devices, parts,
Expand All @@ -56,4 +60,5 @@ The available examples are:

# Advanced

- **advanced/gamepad:** Demonstrates how to use the `gilrs` crate to control your board using a gamepad (e.g., a PS4 DualShock controller).
- **advanced/gamepad:** Demonstrates how to use the `gilrs` crate to control your board using a gamepad (e.g., a PS4
DualShock controller).
2 changes: 2 additions & 0 deletions hermes-five/src/hardware/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

mod board;
mod pca9685;
mod pcf8575;

use crate::io::{IoProtocol, IO};
pub use board::Board;
pub use board::BoardEvent;
pub use pca9685::PCA9685;
pub use pcf8575::PCF8575;

/// You most likely don't need this function (outside this crate).
pub trait Hardware: IO {
Expand Down
Loading