-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also moves the linux-embedded-hal example out of the readme and into a standalone file in examples/.
- Loading branch information
Showing
5 changed files
with
51 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[package] | ||
name = "sen0177" | ||
description = "Read air quality data from the SEN0177 and PMSA003I sensors" | ||
version = "0.4.0-alpha.1" | ||
version = "0.5.0" | ||
authors = ["Brian J. Tarricone <[email protected]>"] | ||
homepage = "https://github.com/kelnos/sen0177-rs" | ||
repository = "https://github.com/kelnos/sen0177-rs" | ||
|
@@ -20,9 +20,10 @@ default = [] | |
std = [] | ||
|
||
[dependencies] | ||
embedded-hal = "=1.0.0-alpha.8" | ||
embedded-hal = "=1.0.0-rc.1" | ||
embedded-hal-nb = "=1.0.0-rc.1" | ||
|
||
[dev-dependencies] | ||
anyhow = "1" | ||
linux-embedded-hal = "0.3" | ||
linux-embedded-hal = { git = "https://github.com/rust-embedded/linux-embedded-hal", rev = "27daf71e8ee22ff2b33fca5972a47dd139de69e2" } | ||
serial = "0.4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use linux_embedded_hal::{ | ||
serialport::{self, DataBits, FlowControl, Parity, StopBits}, | ||
Serial, | ||
}; | ||
use sen0177::{serial::Sen0177, AirQualitySensor}; | ||
use std::time::Duration; | ||
|
||
const SERIAL_PORT: &str = "/dev/ttyS0"; | ||
const BAUD_RATE: u32 = 9600; | ||
const DATA_BITS: DataBits = DataBits::Eight; | ||
const PARITY: Parity = Parity::None; | ||
const STOP_BITS: StopBits = StopBits::One; | ||
const FLOW_CONTROL: FlowControl = FlowControl::None; | ||
|
||
pub fn main() -> anyhow::Result<()> { | ||
let builder = serialport::new(SERIAL_PORT, BAUD_RATE) | ||
.data_bits(DATA_BITS) | ||
.flow_control(FLOW_CONTROL) | ||
.parity(PARITY) | ||
.stop_bits(STOP_BITS) | ||
.timeout(Duration::from_millis(1500)); | ||
let serial = Serial::open_from_builder(builder)?; | ||
let mut sensor = Sen0177::new(serial); | ||
|
||
loop { | ||
match sensor.read() { | ||
Ok(reading) => { | ||
println!( | ||
"PM1: {}µg/m³, PM2.5: {}µg/m³, PM10: {}µg/m³", | ||
reading.pm1(), | ||
reading.pm2_5(), | ||
reading.pm10() | ||
); | ||
} | ||
Err(err) => eprintln!("Error: {:?}", err), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters