Add more info for user.

This commit is contained in:
mattbk
2026-09-11 17:52:17 -05:00
parent 097da86536
commit 1a5eb11206
+20 -21
View File
@@ -1,29 +1,25 @@
use chrono::Local;
use clap::Parser;
use serialport::DataBits; use serialport::DataBits;
use serialport::Parity; use serialport::Parity;
use serialport::StopBits; use serialport::StopBits;
use std::error::Error;
use std::fs::OpenOptions; use std::fs::OpenOptions;
use std::io::ErrorKind; use std::io::ErrorKind;
use std::io::Write; use std::io::Write;
use std::thread::sleep; use std::thread::sleep;
use std::time::Duration; use std::time::Duration;
use std::{error::Error};
use clap::Parser;
use chrono::Local;
/// Command-line arguments using Clap. /// Command-line arguments using Clap.
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[command( #[command(author, version, about = "ASMR: Automatic S-Meter Reader")]
author,
version,
about = "ASMR: Automatic S-Meter Reader"
)]
struct Cli { struct Cli {
/// COM port /// COM port
#[arg(short = 'c', long)] #[arg(short = 'c', long)]
com: Option<String>, com: Option<String>,
/// Format /// Format
#[arg(short = 'o', long, default_value = "result.csv")] #[arg(short = 'o', long,)]
file: Option<String>, file: Option<String>,
/// Frequency /// Frequency
@@ -101,7 +97,7 @@ fn set_freq(comport: &str, freq: u32) -> String {
std::io::stdout().flush().unwrap(); std::io::stdout().flush().unwrap();
} }
Err(ref e) if e.kind() == ErrorKind::TimedOut => (), Err(ref e) if e.kind() == ErrorKind::TimedOut => (),
Err(e) => eprintln!("{:?}", e) Err(e) => eprintln!("{:?}", e),
} }
let mut buf = [0u8; 1024]; let mut buf = [0u8; 1024];
@@ -112,7 +108,6 @@ fn set_freq(comport: &str, freq: u32) -> String {
Err(_) => { Err(_) => {
return format!("Failed to set frequency."); return format!("Failed to set frequency.");
} }
} }
} }
@@ -144,13 +139,8 @@ fn write_row(str_arr: [String; 5], file: &String, fmt: &str) -> Result<(), Box<d
} }
} }
// Main funtion // Main funtion
fn main() { fn main() {
// Arguments // Arguments
let cli = Cli::parse(); let cli = Cli::parse();
@@ -169,9 +159,13 @@ fn main() {
}; };
let file_out = match cli.file { let file_out = match cli.file {
Some(file_out) => file_out, Some(file_out) => {
println!("Saving results to {}", file_out);
file_out
},
None => { None => {
return; println!("Not saving results. Use `-o file.csv` to save to a file.");
"no file".to_string()
} //todo!() } //todo!()
}; };
@@ -204,11 +198,16 @@ fn main() {
//println!("{a}"); //println!("{a}");
match s_val.parse::<i32>() { match s_val.parse::<i32>() {
// Simple graph as we go. Eventually this will be replaced. // Simple graph as we go. Eventually this will be replaced.
Ok(n) => println!("{} {}", s_val, "#".repeat(n.try_into().unwrap())), Ok(n) => println!(
"{} {} {}",
date.format("%Y-%m-%d %H:%M:%S").to_string(),
s_val,
"#".repeat(n.try_into().unwrap())
),
Err(_e) => todo!(), Err(_e) => todo!(),
} }
// If they provided a file name // If they provided a file name
if file_out != "" { if file_out != "no file" {
if let Err(err) = write_row( if let Err(err) = write_row(
[ [
date.format("%Y-%m-%d %H:%M:%S").to_string(), date.format("%Y-%m-%d %H:%M:%S").to_string(),
@@ -218,7 +217,7 @@ fn main() {
s_val.to_string(), s_val.to_string(),
], ],
&file_out, &file_out,
"csv" "csv",
) { ) {
println!("{}", err); println!("{}", err);
} }