Fix #2 add "Type2" DHT22 sensor
This commit is contained in:
parent
45f47e1b1a
commit
ba94973ad9
2 changed files with 29 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "dht-pio"
|
name = "dht-pio"
|
||||||
version = "0.5.2"
|
version = "0.5.3"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
28
src/lib.rs
28
src/lib.rs
|
@ -53,6 +53,34 @@ impl<P: PIOExt, STI: StateMachineIndex> Dht22<P, STI> {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Dht22Type2<P: PIOExt, STI: StateMachineIndex> {
|
||||||
|
dht: DhtPio<P, STI>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<P: PIOExt, STI: StateMachineIndex> Dht22Type2<P, STI> {
|
||||||
|
pub fn new<I: AnyPin<Function = P::PinFunction>>(
|
||||||
|
pio: rp2040_hal::pio::PIO<P>,
|
||||||
|
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<DhtResult, DhtError> {
|
||||||
|
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<P: PIOExt, STI: StateMachineIndex> {
|
pub struct Dht11<P: PIOExt, STI: StateMachineIndex> {
|
||||||
dht: DhtPio<P, STI>,
|
dht: DhtPio<P, STI>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue