1
0
Fork 0
mirror of https://github.com/icewind1991/mhz19-rs synced 2026-06-03 17:44:09 +02:00

take tty path as arugment

This commit is contained in:
Robin Appelman 2019-09-06 21:55:54 +02:00
commit 630087ac72

View file

@ -2,20 +2,24 @@ use mhz19::MHZ19;
use std::time::Duration;
use std::thread::sleep;
use std::ffi::OsStr;
use std::env;
const DELAY: Duration = Duration::from_secs(1);
fn main() {
loop {
listen("/dev/ttyUSB0");
match env::args().skip(1).next() {
Some(path) => loop {
listen(&path);
sleep(DELAY);
},
None => eprintln!("Path required")
}
}
fn listen<T: AsRef<OsStr> + ?Sized>(port: &T) {
let mut mhz19 = MHZ19::open(port).unwrap();
loop {
match { mhz19.read()} {
match { mhz19.read() } {
Ok(value) => println!("{}", value),
Err(err) => {
eprintln!("Error while reading value: {}, reconnecting", err);