diff --git a/Cargo.toml b/Cargo.toml index afadc10..df54053 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dht-pio" -version = "0.5.1" +version = "0.5.2" edition = "2021" license = "MIT" diff --git a/src/lib.rs b/src/lib.rs index 65c2ef6..6da9cb4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,16 +40,16 @@ impl Dht22 { } pub fn read(&mut self, delay: &mut Delay) -> Result { - let (t, h) = self.dht.read_data(delay)?; - let mut final_t: i32 = (t & 0x7FFF) as i32; + let (raw_temp, raw_hum) = self.dht.read_data(delay)?; + let mut final_t: f32 = (raw_temp & 0x7FFF) as f32; - if (t & 0x8000) > 0 { - final_t *= -1; + if (raw_temp & 0x8000) > 0 { + final_t *= -1.0; } Ok(DhtResult { - temperature: final_t as f32 / 10.0, - humidity: h as f32 / 10.0, + temperature: final_t / 10.0, + humidity: raw_hum as f32 / 10.0, }) } } @@ -70,14 +70,14 @@ impl Dht11 { pub fn read(&mut self, delay: &mut Delay) -> Result { let (t, h) = self.dht.read_data(delay)?; - let mut final_t: i32 = ((t & 0x7FFF) >> 8) as i32; + let mut final_t: f32 = ((t & 0x7FFF) >> 8) as f32; if (t & 0x8000) > 0 { - final_t *= -1; + final_t *= -1.0; } Ok(DhtResult { - temperature: final_t as f32, + temperature: final_t, humidity: (h >> 8) as f32, }) }