Add more info for user.
This commit is contained in:
+20
-21
@@ -1,29 +1,25 @@
|
||||
use chrono::Local;
|
||||
use clap::Parser;
|
||||
use serialport::DataBits;
|
||||
use serialport::Parity;
|
||||
use serialport::StopBits;
|
||||
use std::error::Error;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::ErrorKind;
|
||||
use std::io::Write;
|
||||
use std::thread::sleep;
|
||||
use std::time::Duration;
|
||||
use std::{error::Error};
|
||||
use clap::Parser;
|
||||
use chrono::Local;
|
||||
|
||||
/// Command-line arguments using Clap.
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(
|
||||
author,
|
||||
version,
|
||||
about = "ASMR: Automatic S-Meter Reader"
|
||||
)]
|
||||
#[command(author, version, about = "ASMR: Automatic S-Meter Reader")]
|
||||
struct Cli {
|
||||
/// COM port
|
||||
#[arg(short = 'c', long)]
|
||||
com: Option<String>,
|
||||
|
||||
/// Format
|
||||
#[arg(short = 'o', long, default_value = "result.csv")]
|
||||
#[arg(short = 'o', long,)]
|
||||
file: Option<String>,
|
||||
|
||||
/// Frequency
|
||||
@@ -101,7 +97,7 @@ fn set_freq(comport: &str, freq: u32) -> String {
|
||||
std::io::stdout().flush().unwrap();
|
||||
}
|
||||
Err(ref e) if e.kind() == ErrorKind::TimedOut => (),
|
||||
Err(e) => eprintln!("{:?}", e)
|
||||
Err(e) => eprintln!("{:?}", e),
|
||||
}
|
||||
|
||||
let mut buf = [0u8; 1024];
|
||||
@@ -112,7 +108,6 @@ fn set_freq(comport: &str, freq: u32) -> String {
|
||||
Err(_) => {
|
||||
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
|
||||
fn main() {
|
||||
|
||||
// Arguments
|
||||
let cli = Cli::parse();
|
||||
|
||||
@@ -169,9 +159,13 @@ fn main() {
|
||||
};
|
||||
|
||||
let file_out = match cli.file {
|
||||
Some(file_out) => file_out,
|
||||
Some(file_out) => {
|
||||
println!("Saving results to {}", file_out);
|
||||
file_out
|
||||
},
|
||||
None => {
|
||||
return;
|
||||
println!("Not saving results. Use `-o file.csv` to save to a file.");
|
||||
"no file".to_string()
|
||||
} //todo!()
|
||||
};
|
||||
|
||||
@@ -204,11 +198,16 @@ fn main() {
|
||||
//println!("{a}");
|
||||
match s_val.parse::<i32>() {
|
||||
// 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!(),
|
||||
}
|
||||
// If they provided a file name
|
||||
if file_out != "" {
|
||||
if file_out != "no file" {
|
||||
if let Err(err) = write_row(
|
||||
[
|
||||
date.format("%Y-%m-%d %H:%M:%S").to_string(),
|
||||
@@ -218,7 +217,7 @@ fn main() {
|
||||
s_val.to_string(),
|
||||
],
|
||||
&file_out,
|
||||
"csv"
|
||||
"csv",
|
||||
) {
|
||||
println!("{}", err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user