Skip to content

Commit

Permalink
ravedude: Apply rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Rahix committed Jan 20, 2024
1 parent c54e5f5 commit c1b78e9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
21 changes: 8 additions & 13 deletions ravedude/src/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,14 @@ impl Board for ArduinoLeonardo {
fn needs_reset(&self) -> Option<&str> {
let a = self.guess_port();
match a {
Some(Ok(name)) => {
match serialport::new(name.to_str().unwrap(), 1200).open() {
Ok(_) => {
std::thread::sleep(core::time::Duration::from_secs(1));
None
},
Err(_) => Some("Reset the board by pressing the reset button once.")
Some(Ok(name)) => match serialport::new(name.to_str().unwrap(), 1200).open() {
Ok(_) => {
std::thread::sleep(core::time::Duration::from_secs(1));
None
}
Err(_) => Some("Reset the board by pressing the reset button once."),
},
_ => Some("Reset the board by pressing the reset button once.")
_ => Some("Reset the board by pressing the reset button once."),
}
}

Expand All @@ -202,7 +200,6 @@ impl Board for ArduinoLeonardo {
}
}


struct ArduinoMega1280;

impl Board for ArduinoMega1280 {
Expand All @@ -224,12 +221,11 @@ impl Board for ArduinoMega1280 {
}

fn guess_port(&self) -> Option<anyhow::Result<std::path::PathBuf>> {
// This board uses a generic serial interface id 0403:6001 which is too common for auto detection.
Some(Err(anyhow::anyhow!("Unable to guess port.")))
// This board uses a generic serial interface id 0403:6001 which is too common for auto detection.
Some(Err(anyhow::anyhow!("Unable to guess port.")))
}
}


struct ArduinoMega2560;

impl Board for ArduinoMega2560 {
Expand Down Expand Up @@ -417,7 +413,6 @@ impl Board for Nano168 {
}
}


struct ArduinoDuemilanove;

impl Board for ArduinoDuemilanove {
Expand Down
5 changes: 3 additions & 2 deletions ravedude/src/console.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ pub fn open(port: &std::path::Path, baudrate: u32) -> anyhow::Result<()> {
eprintln!("");
eprintln!("Exiting.");
std::process::exit(0);
}).context("failed setting a CTRL+C handler")?;
})
.context("failed setting a CTRL+C handler")?;

// Spawn a thread for the receiving end because stdio is not portably non-blocking...
std::thread::spawn(move || loop {
Expand All @@ -27,7 +28,7 @@ pub fn open(port: &std::path::Path, baudrate: u32) -> anyhow::Result<()> {
// Use buffer size 1 for windows because it blocks on rx.read until the buffer is full
#[cfg(target_os = "windows")]
let mut buf = [0u8; 1];

match rx.read(&mut buf) {
Ok(count) => {
stdout.write(&buf[..count]).unwrap();
Expand Down
14 changes: 5 additions & 9 deletions ravedude/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Context as _;
use colored::Colorize as _;
use structopt::clap::AppSettings;

use std::time::Duration;
use std::thread;
use std::time::Duration;

mod avrdude;
mod board;
Expand Down Expand Up @@ -94,15 +94,15 @@ fn ravedude() -> anyhow::Result<()> {

task_message!("Board", "{}", board.display_name());

if let Some(wait_time) = args.reset_delay{
if let Some(wait_time) = args.reset_delay {
if wait_time > 0 {
println!("Waiting {} ms before proceeding", wait_time);
let wait_time = Duration::from_millis(wait_time);
thread::sleep(wait_time);
}else{
} else {
println!("Assuming board has been reset");
}
}else{
} else {
if let Some(msg) = board.needs_reset() {
warning!("this board cannot reset itself.");
eprintln!("");
Expand Down Expand Up @@ -157,11 +157,7 @@ fn ravedude() -> anyhow::Result<()> {
let port = port.context("console can only be opened for devices with USB-to-Serial")?;

task_message!("Console", "{} at {} baud", port.display(), baudrate);
task_message!(
"",
"{}",
"CTRL+C to exit.".dimmed()
);
task_message!("", "{}", "CTRL+C to exit.".dimmed());
// Empty line for visual consistency
eprintln!();
console::open(&port, baudrate)?;
Expand Down

0 comments on commit c1b78e9

Please sign in to comment.