diff --git a/Cargo.toml b/Cargo.toml index df54053..36abbb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dht-pio" -version = "0.5.2" +version = "0.5.3" edition = "2021" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 6da9cb4..d484a37 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,34 @@ impl Dht22 { }) } } + +pub struct Dht22Type2 { + dht: DhtPio, +} + +impl Dht22Type2 { + pub fn new>( + pio: rp2040_hal::pio::PIO

, + sm: UninitStateMachine<(P, STI)>, + dht_pin: I, + ) -> Self { + Self { + dht: DhtPio::new(pio, sm, dht_pin), + } + } + + pub fn read(&mut self, delay: &mut Delay) -> Result { + let (raw_temp, raw_hum) = self.dht.read_data(delay)?; + + let tmp: i16 = raw_temp as i16; + + Ok(DhtResult { + temperature: (tmp as f32) / 10.0, + humidity: raw_hum as f32 / 10.0, + }) + } +} + pub struct Dht11 { dht: DhtPio, }