extern crate simple_logger;
extern crate usbrh;
#[macro_use]
extern crate structopt;
use structopt::StructOpt;
use usbrh::read_sensors;
#[derive(StructOpt, Debug)]
#[structopt(name = "usbrh", author = "")]
struct Opt {
#[structopt(short = "v", long = "verbose", parse(from_occurrences))]
verbose: u32,
#[structopt(short = "t", long = "temperature")]
temperature: bool,
#[structopt(short = "h", long = "humidity")]
humidity: bool,
#[structopt(short = "H", long = "no-header")]
no_header: bool,
#[structopt(short = "d", long = "device", default_value = "1")]
device_num: u32,
}
fn main() {
let opt = Opt::from_args();
let opt = if !(opt.temperature || opt.humidity) {
Opt {
temperature: true,
humidity: true,
..opt
}
} else {
opt
};
if opt.verbose >= 1 {
simple_logger::init().unwrap();
}
match read_sensors(opt.verbose, opt.device_num) {
Ok(result) => {
if opt.temperature && opt.humidity {
if !opt.no_header {
println!("temperature\thumidity");
}
println!("{:.2}\t{:.2}", result.temperature, result.humidity);
} else if opt.temperature {
println!("{:.2}", result.temperature);
} else if opt.humidity {
println!("{:.2}", result.humidity);
}
}
Err(e) => panic!("{}", e),
}
}