add delay param

This commit is contained in:
Denis-Cosmin Nutiu 2024-11-21 00:16:57 +02:00
parent ddbd11561a
commit 02f80c2439
3 changed files with 7 additions and 3 deletions

2
Cargo.lock generated
View file

@ -89,7 +89,7 @@ dependencies = [
[[package]]
name = "bme680-json"
version = "1.0.0"
version = "1.0.2"
dependencies = [
"anyhow",
"bme680",

View file

@ -1,6 +1,6 @@
[package]
name = "bme680-json"
version = "1.0.1"
version = "1.0.2"
edition = "2021"
[dependencies]

View file

@ -22,6 +22,10 @@ struct Args {
/// I2C address to use
#[arg(long, default_value_t = String::from("/dev/i2c-1"))]
i2c_address: String,
/// Delay reading by the specified amount in milliseconds.
#[arg(long, default_value_t = 1000)]
delay_before_read: u32
}
fn main() -> Result<(), anyhow::Error> {
@ -43,7 +47,7 @@ fn main() -> Result<(), anyhow::Error> {
dev.set_sensor_settings(&mut delay, &settings)?;
dev.set_sensor_mode(&mut delay, PowerMode::ForcedMode)?;
Delay {}.delay_ms(5000u32);
Delay {}.delay_ms(args.delay_before_read);
let (data, _) = dev.get_measurement(&mut delay)?;
let serialized = serde_json::to_string(&JsonData{
temperature: data.temperature_celsius(),