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:
parent
4edd0ffff0
commit
630087ac72
1 changed files with 8 additions and 4 deletions
10
src/bin.rs
10
src/bin.rs
|
|
@ -2,20 +2,24 @@ use mhz19::MHZ19;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use std::thread::sleep;
|
use std::thread::sleep;
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
const DELAY: Duration = Duration::from_secs(1);
|
const DELAY: Duration = Duration::from_secs(1);
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
loop {
|
match env::args().skip(1).next() {
|
||||||
listen("/dev/ttyUSB0");
|
Some(path) => loop {
|
||||||
|
listen(&path);
|
||||||
sleep(DELAY);
|
sleep(DELAY);
|
||||||
|
},
|
||||||
|
None => eprintln!("Path required")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn listen<T: AsRef<OsStr> + ?Sized>(port: &T) {
|
fn listen<T: AsRef<OsStr> + ?Sized>(port: &T) {
|
||||||
let mut mhz19 = MHZ19::open(port).unwrap();
|
let mut mhz19 = MHZ19::open(port).unwrap();
|
||||||
loop {
|
loop {
|
||||||
match { mhz19.read()} {
|
match { mhz19.read() } {
|
||||||
Ok(value) => println!("{}", value),
|
Ok(value) => println!("{}", value),
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error while reading value: {}, reconnecting", err);
|
eprintln!("Error while reading value: {}, reconnecting", err);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue