Skip to content

Commit 2ae8805

Browse files
committed
feat: start preparing dht20
1 parent 2412cdf commit 2ae8805

File tree

4 files changed

+33
-2
lines changed

4 files changed

+33
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ We’ve tested it with the ESP32-WROOM, and you can find a detailed example belo
1212

1313
## Getting Started
1414

15-
### Example
15+
### Example - ESP32
1616

1717
```rust
1818
#![no_std]

src/dht.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use embedded_hal::{
55

66
use crate::SensorError;
77

8-
/// Common base struct for DHT sensors.
8+
/// Common base struct for DHT11, DHT22 sensors.
99
pub struct Dht<P: InputPin + OutputPin, D: DelayNs> {
1010
pub pin: P,
1111
pub delay: D,

src/dht20.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use embedded_hal::{delay::DelayNs, i2c::I2c};
2+
3+
use crate::{SensorError, SensorReading};
4+
5+
pub struct Dht20<P: I2c, D: DelayNs> {
6+
pub pin: P,
7+
pub delay: D,
8+
}
9+
10+
impl<P: I2c, D: DelayNs> Dht20<P, D> {
11+
pub fn new(pin: P, delay: D) -> Self {
12+
Self {
13+
pin: pin,
14+
delay: delay,
15+
}
16+
}
17+
18+
pub fn read(&mut self) -> Result<SensorReading, SensorError> {
19+
20+
// TODO
21+
let humidity_percentage = 10.0;
22+
// TODO
23+
let temperatue_percentage = 10.0;
24+
25+
Ok(SensorReading {
26+
humidity: humidity_percentage as f32,
27+
temperature: temperatue_percentage as f32,
28+
})
29+
}
30+
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
mod dht;
44
pub mod dht11;
5+
pub mod dht20;
56
pub mod dht22;
67

78
/// Represents a reading from the sensor.

0 commit comments

Comments
 (0)