Skip to content

Commit

Permalink
ravedude: Allow skipping the reset question
Browse files Browse the repository at this point in the history
Add a new commandline option to skip the reset question.  This can be
useful when a self-reset function is implemented in the firmware running
on the board.
  • Loading branch information
TerminatorNL committed May 29, 2022
1 parent 81edfcd commit bf222fe
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions ravedude/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use anyhow::Context as _;
use colored::Colorize as _;
use structopt::clap::AppSettings;

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

mod avrdude;
mod board;
mod console;
Expand Down Expand Up @@ -39,6 +42,12 @@ struct Args {
#[structopt(short = "P", long = "port", parse(from_os_str), env = "RAVEDUDE_PORT")]
port: Option<std::path::PathBuf>,

/// This assumes the board is already resetting.
/// Instead of giving the reset instructions and waiting for user confirmation, we wait the amount in milliseconds before proceeding.
/// Set this value to 0 to skip the board reset question instantly.
#[structopt(short = "d", long = "reset-delay")]
reset_delay: Option<u64>,

/// Which board to interact with.
///
/// Must be one of the known board identifiers:
Expand Down Expand Up @@ -81,13 +90,23 @@ fn ravedude() -> anyhow::Result<()> {

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

if let Some(msg) = board.needs_reset() {
warning!("this board cannot reset itself.");
eprintln!("");
eprintln!(" {}", msg);
eprintln!("");
eprint!("Once reset, press ENTER here: ");
std::io::stdin().read_line(&mut String::new())?;
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{
println!("Assuming board has been reset");
}
}else{
if let Some(msg) = board.needs_reset() {
warning!("this board cannot reset itself.");
eprintln!("");
eprintln!(" {}", msg);
eprintln!("");
eprint!("Once reset, press ENTER here: ");
std::io::stdin().read_line(&mut String::new())?;
}
}

let port = match args.port {
Expand Down

0 comments on commit bf222fe

Please sign in to comment.