Skip to content

Commit

Permalink
Update to ebyte-32 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
barafael authored and Rafael Bachmann committed Nov 18, 2022
1 parent 6a69fb6 commit 236067f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ clap = { version = "3.1.14", features = ["derive"] }
#ebyte-e32 = { git = "https://github.com/barafael/ebyte-e32-rs", rev = "fee291a427df8e7c55e8dc154e181257ebb52a41", features = [
#"arg_enum",
#] }
ebyte-e32 = { version = "0.8.0", features = ["value_enum"] }
ebyte-e32 = { version = "0.9.0", features = ["value_enum"] }
embedded-hal = "0.2.7"
klask = "1"
linux-embedded-hal = "0.3.2"
Expand Down
20 changes: 11 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ pub fn create(args: &Args) -> anyhow::Result<Ebyte<Serial, Pin, Pin, Pin, Delay,
.context("Failed to request settings for M1 pin")?;
let m1 = Pin::new(m1).context("Failed to create M1 CDEV pin")?;

Ok(Ebyte::new(serial, aux, m0, m1, Delay).expect("Failed to initialize driver"))
Ebyte::new(serial, aux, m0, m1, Delay).context("Failed to initialize driver")
}

pub fn run<S, AUX, M0, M1, D>(
Expand All @@ -102,17 +102,19 @@ where
Mode::Listen => loop {
let b = block!(ebyte.read()).expect("Failed to read");
print!("{}", b as char);
std::io::Write::flush(&mut std::io::stdout()).expect("Failed to flush");
std::io::Write::flush(&mut std::io::stdout()).context("Failed to flush")?;
},
Mode::ReadModelData => {
println!("Reading model data");
let model_data = ebyte.model_data().expect("Failed to read model data");
let model_data = ebyte.model_data().context("Failed to read model data")?;
println!("{model_data:#?}");
Ok(())
}
Mode::ReadParameters => {
println!("Reading parameter data");
let parameters = ebyte.parameters().expect("Failed to read parameter data");
let parameters = ebyte
.parameters()
.context("Failed to read parameter data")?;
println!("{parameters:#?}");
Ok(())
}
Expand All @@ -132,7 +134,7 @@ where
M1: OutputPin,
D: delay::DelayMs<u32>,
{
let mut prompt = Editor::<()>::new().expect("Failed to set up prompt");
let mut prompt = Editor::<()>::new().context("Failed to set up prompt")?;
loop {
match prompt.readline("Enter message >> ") {
Ok(line) => {
Expand All @@ -144,7 +146,7 @@ where
for b in line.as_bytes() {
block!(ebyte.write(*b)).expect("Failed to write");
print!("{}", *b as char);
std::io::Write::flush(&mut std::io::stdout()).expect("Failed to flush");
std::io::Write::flush(&mut std::io::stdout()).context("Failed to flush")?;
}
block!(ebyte.write(b'\n')).expect("Failed to write");
println!();
Expand Down Expand Up @@ -187,7 +189,7 @@ where
println!("Loading existing parameters");
let old_params = ebyte
.parameters()
.expect("Failed to read existing parameters");
.context("Failed to read existing parameters")?;
println!("Loaded parameters: {old_params:#?}");

// Create Ebyte parameters from argument parameters.
Expand All @@ -202,12 +204,12 @@ where
);
ebyte
.set_parameters(&new_params, parameters.persistence)
.expect("Failed to set new parameters");
.context("Failed to set new parameters")?;

// Check if it worked.
let current_params = ebyte
.parameters()
.expect("Failed to read current parameters");
.context("Failed to read current parameters")?;
if current_params != new_params {
eprintln!("Error: parameters unchanged: {current_params:#?}");
}
Expand Down

0 comments on commit 236067f

Please sign in to comment.