Firmware for the b-parasite board, but in Rust!

Switch to async shtc3 methods

+6 -5
Cargo.lock
···
"embedded-io",
"embedded-io-async",
"futures-intrusive",
-
"heapless 0.8.0",
+
"heapless 0.9.2",
]
[[package]]
···
[[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",
···
[[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",
···
"embassy-sync",
"embassy-time",
"embedded-hal 1.0.0",
+
"embedded-hal-async",
"embedded-io",
"nrf-mpsl",
"nrf-sdc",
···
[[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",
+1
Cargo.toml
···
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 = [
+1 -1
src/constants.rs
···
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];
+10 -16
src/shtc3.rs
···
Peri, peripherals,
twim::{self, Twim},
};
-
use embassy_time::Timer;
-
use embedded_hal::i2c::SevenBitAddress;
-
use sachy_fmt::{info, error, unwrap};
+
use embassy_time::{Delay, Timer};
+
use embedded_hal_async::i2c::{I2c, SevenBitAddress};
+
use sachy_fmt::{error, info, unwrap};
use sachy_shtc3::{Error as ShtError, Measurement, PowerMode, ShtC3};
use static_cell::ConstStaticCell;
···
async fn measure<I>(sht: &mut ShtC3<I>) -> Result<Measurement, ShtError<I::Error>>
where
-
I: embedded_hal::i2c::I2c<SevenBitAddress>,
+
I: I2c<SevenBitAddress>,
{
-
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;
}
···
m.humidity.as_percent()
);
-
sht.sleep()?;
+
sht.sleep_async().await?;
Ok(m)
}
async fn reset<I>(sht: &mut ShtC3<I>) -> Result<(), ShtError<I::Error>>
where
-
I: embedded_hal::i2c::I2c<SevenBitAddress>,
+
I: I2c<SevenBitAddress>,
{
-
sht.start_reset()?;
-
-
Timer::after_micros(sht.reset_duration() as u64).await;
+
sht.reset_async(&mut Delay).await?;
Ok(())
}