From bf222feb2f111e1cd85ecc1190e4152d6783a2bb Mon Sep 17 00:00:00 2001 From: Terminator Date: Sun, 29 May 2022 09:25:59 +0200 Subject: [PATCH] ravedude: Allow skipping the reset question 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. --- ravedude/src/main.rs | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/ravedude/src/main.rs b/ravedude/src/main.rs index 11c73c19c6..ce12a9641a 100644 --- a/ravedude/src/main.rs +++ b/ravedude/src/main.rs @@ -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; @@ -39,6 +42,12 @@ struct Args { #[structopt(short = "P", long = "port", parse(from_os_str), env = "RAVEDUDE_PORT")] port: Option, + /// 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, + /// Which board to interact with. /// /// Must be one of the known board identifiers: @@ -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 {