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

Switch to async shtc3 methods

authored by sachy.dev and committed by Tangled 0c95f8fc 0065f218

+6 -5
Cargo.lock
··· 82 82 "embedded-io", 83 83 "embedded-io-async", 84 84 "futures-intrusive", 85 - "heapless 0.8.0", 85 + "heapless 0.9.2", 86 86 ] 87 87 88 88 [[package]] ··· 1044 1044 [[package]] 1045 1045 name = "sachy-battery" 1046 1046 version = "0.1.0" 1047 - source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" 1047 + source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" 1048 1048 1049 1049 [[package]] 1050 1050 name = "sachy-bthome" 1051 1051 version = "0.1.0" 1052 - source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" 1052 + source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" 1053 1053 dependencies = [ 1054 1054 "defmt 1.0.1", 1055 1055 "heapless 0.9.2", ··· 1059 1059 [[package]] 1060 1060 name = "sachy-fmt" 1061 1061 version = "0.1.0" 1062 - source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" 1062 + source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" 1063 1063 dependencies = [ 1064 1064 "defmt 1.0.1", 1065 1065 ] ··· 1079 1079 "embassy-sync", 1080 1080 "embassy-time", 1081 1081 "embedded-hal 1.0.0", 1082 + "embedded-hal-async", 1082 1083 "embedded-io", 1083 1084 "nrf-mpsl", 1084 1085 "nrf-sdc", ··· 1095 1096 [[package]] 1096 1097 name = "sachy-shtc3" 1097 1098 version = "0.1.0" 1098 - source = "git+https://tangled.org/sachy.dev/sachy-embed-core#da0ffed807760563c59c9d6360190aaf028878a9" 1099 + source = "git+https://tangled.org/sachy.dev/sachy-embed-core#24c6e6058b733cad84234854941ac25836158b79" 1099 1100 dependencies = [ 1100 1101 "defmt 1.0.1", 1101 1102 "embedded-hal 1.0.0",
+1
Cargo.toml
··· 75 75 embassy-sync = "0.7" 76 76 embassy-time = { version = "0.5" } 77 77 embedded-hal = { version = "1.0.0" } 78 + embedded-hal-async = "1.0.0" 78 79 embedded-io = "0.6" 79 80 80 81 nrf-sdc = { git = "https://github.com/alexmoon/nrf-sdc", features = [
+1 -1
src/constants.rs
··· 7 7 pub const PARA_MAX_ADV_INTERVAL_MS: u64 = 80; 8 8 pub const PARA_BLE_TX_POWER: TxPower = TxPower::Plus8dBm; 9 9 10 - pub static PARA_NAME: &str = "rpara"; 10 + pub static PARA_NAME: &str = "spara"; 11 11 12 12 pub static DRY_COEFFS: [f32; 3] = [154.0, 110.0, -15.3]; 13 13 pub static WET_COEFFS: [f32; 3] = [319.0, -63.1, 7.2];
+10 -16
src/shtc3.rs
··· 2 2 Peri, peripherals, 3 3 twim::{self, Twim}, 4 4 }; 5 - use embassy_time::Timer; 6 - use embedded_hal::i2c::SevenBitAddress; 7 - use sachy_fmt::{info, error, unwrap}; 5 + use embassy_time::{Delay, Timer}; 6 + use embedded_hal_async::i2c::{I2c, SevenBitAddress}; 7 + use sachy_fmt::{error, info, unwrap}; 8 8 use sachy_shtc3::{Error as ShtError, Measurement, PowerMode, ShtC3}; 9 9 use static_cell::ConstStaticCell; 10 10 ··· 15 15 16 16 async fn measure<I>(sht: &mut ShtC3<I>) -> Result<Measurement, ShtError<I::Error>> 17 17 where 18 - I: embedded_hal::i2c::I2c<SevenBitAddress>, 18 + I: I2c<SevenBitAddress>, 19 19 { 20 - sht.start_wakeup()?; 20 + let mut delay = Delay; 21 21 22 - Timer::after_micros(sht.wakeup_duration() as u64).await; 22 + sht.wakeup_async(&mut delay).await?; 23 23 24 24 let divisor = 4; 25 25 let mut m = Measurement::default(); 26 26 27 27 for _ in 0..divisor { 28 - sht.start_measurement()?; 29 - 30 - Timer::after_micros(sht.max_measurement_duration() as u64).await; 31 - 32 - m += sht.get_measurement_result()?; 28 + m += sht.measure_async(&mut delay).await?; 33 29 34 30 Timer::after_millis(5).await; 35 31 } ··· 42 38 m.humidity.as_percent() 43 39 ); 44 40 45 - sht.sleep()?; 41 + sht.sleep_async().await?; 46 42 47 43 Ok(m) 48 44 } 49 45 50 46 async fn reset<I>(sht: &mut ShtC3<I>) -> Result<(), ShtError<I::Error>> 51 47 where 52 - I: embedded_hal::i2c::I2c<SevenBitAddress>, 48 + I: I2c<SevenBitAddress>, 53 49 { 54 - sht.start_reset()?; 55 - 56 - Timer::after_micros(sht.reset_duration() as u64).await; 50 + sht.reset_async(&mut Delay).await?; 57 51 58 52 Ok(()) 59 53 }