mirror of
https://github.com/icewind1991/mhz19-rs
synced 2026-06-03 09:34:12 +02:00
take tty path as arugment
This commit is contained in:
parent
4edd0ffff0
commit
630087ac72
1 changed files with 8 additions and 4 deletions
12
src/bin.rs
12
src/bin.rs
|
|
@ -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");
|
||||
sleep(DELAY);
|
||||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue