From e60bacc94064a83faf0fd8b48ad0417e6ed49584 Mon Sep 17 00:00:00 2001 From: Sachymetsu Date: Mon, 8 Dec 2025 10:31:41 +0100 Subject: [PATCH] Switch to async shtc3 methods Change-Id: lllosvxksqupwnsomsmktsyotnvwqnlz --- Cargo.lock | 11 ++++++----- Cargo.toml | 1 + src/constants.rs | 2 +- src/shtc3.rs | 22 ++++++++-------------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 57a4616..ad52acf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -82,7 +82,7 @@ dependencies = [ "embedded-io", "embedded-io-async", "futures-intrusive", - "heapless 0.8.0", + "heapless 0.9.2", ] [[package]] @@ -1044,12 +1044,12 @@ checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "sachy-battery" version = "0.1.0" -source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" +source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" [[package]] name = "sachy-bthome" version = "0.1.0" -source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" +source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" dependencies = [ "defmt 1.0.1", "heapless 0.9.2", @@ -1059,7 +1059,7 @@ dependencies = [ [[package]] name = "sachy-fmt" version = "0.1.0" -source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" +source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" dependencies = [ "defmt 1.0.1", ] @@ -1079,6 +1079,7 @@ dependencies = [ "embassy-sync", "embassy-time", "embedded-hal 1.0.0", + "embedded-hal-async", "embedded-io", "nrf-mpsl", "nrf-sdc", @@ -1095,7 +1096,7 @@ dependencies = [ [[package]] name = "sachy-shtc3" version = "0.1.0" -source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" +source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" dependencies = [ "defmt 1.0.1", "embedded-hal 1.0.0", diff --git a/Cargo.toml b/Cargo.toml index 3ed4f65..4c794b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,6 +75,7 @@ embassy-nrf = { version = "0.8", features = [ embassy-sync = "0.7" embassy-time = { version = "0.5" } embedded-hal = { version = "1.0.0" } +embedded-hal-async = "1.0.0" embedded-io = "0.6" nrf-sdc = { git = "https://github.com/alexmoon/nrf-sdc", features = [ diff --git a/src/constants.rs b/src/constants.rs index 95d458b..56b260e 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -7,7 +7,7 @@ pub const PARA_MIN_ADV_INTERVAL_MS: u64 = 30; pub const PARA_MAX_ADV_INTERVAL_MS: u64 = 80; pub const PARA_BLE_TX_POWER: TxPower = TxPower::Plus8dBm; -pub static PARA_NAME: &str = "rpara"; +pub static PARA_NAME: &str = "spara"; pub static DRY_COEFFS: [f32; 3] = [154.0, 110.0, -15.3]; pub static WET_COEFFS: [f32; 3] = [319.0, -63.1, 7.2]; diff --git a/src/shtc3.rs b/src/shtc3.rs index 45a4d97..4ba318b 100644 --- a/src/shtc3.rs +++ b/src/shtc3.rs @@ -2,7 +2,7 @@ use embassy_nrf::{ Peri, peripherals, twim::{self, Twim}, }; -use embassy_time::Timer; +use embassy_time::{Timer, Delay}; use embedded_hal::i2c::SevenBitAddress; use sachy_fmt::{info, error, unwrap}; use sachy_shtc3::{Error as ShtError, Measurement, PowerMode, ShtC3}; @@ -15,21 +15,17 @@ use crate::{ async fn measure(sht: &mut ShtC3) -> Result> where - I: embedded_hal::i2c::I2c, + I: embedded_hal_async::i2c::I2c, { - sht.start_wakeup()?; + let mut delay = Delay; - Timer::after_micros(sht.wakeup_duration() as u64).await; + sht.wakeup_async(&mut delay).await?; let divisor = 4; let mut m = Measurement::default(); for _ in 0..divisor { - sht.start_measurement()?; - - Timer::after_micros(sht.max_measurement_duration() as u64).await; - - m += sht.get_measurement_result()?; + m += sht.measure_async(&mut delay).await?; Timer::after_millis(5).await; } @@ -42,18 +38,16 @@ where m.humidity.as_percent() ); - sht.sleep()?; + sht.sleep_async().await?; Ok(m) } async fn reset(sht: &mut ShtC3) -> Result<(), ShtError> where - I: embedded_hal::i2c::I2c, + I: embedded_hal_async::i2c::I2c, { - sht.start_reset()?; - - Timer::after_micros(sht.reset_duration() as u64).await; + sht.reset_async(&mut Delay).await?; Ok(()) } -- 2.52.0