Skip to content

Commit 0a68421

Browse files
committed
Merge branch 'main' into feature/dht20
2 parents 42f3514 + 37b3dca commit 0a68421

File tree

7 files changed

+37
-11
lines changed

7 files changed

+37
-11
lines changed

.github/workflows/rust.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Rust
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Build
20+
run: cargo build --verbose
21+
- name: Run tests
22+
run: cargo test --verbose

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "embedded-dht-rs"
3-
version = "0.1.1"
3+
version = "0.2.0"
44
edition = "2021"
55
license = "Apache-2.0"
66
description = "A platform agnostic driver to interface with the DHT11/DHT22 (AM2302) temperature and humidity sensor"

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
![build workflow](https://github.com/rust-dd/embedded-dht-rs/actions/workflows/rust.yml/badge.svg)
2+
[![Crates.io](https://img.shields.io/crates/v/embedded-dht-rs?style=flat-square)](https://crates.io/crates/embedded-dht-rs)
3+
![Crates.io](https://img.shields.io/crates/l/embedded-dht-rs?style=flat-square)
4+
15
# embedded-dht-rs
26

37
Welcome to `embedded-dht-rs`, a Rust library designed to make working with DHT sensors a breeze!

src/dht11.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<P: InputPin + OutputPin, D: DelayNs> Dht11<P, D> {
1616
}
1717
}
1818

19-
pub fn read(&mut self) -> Result<SensorReading, SensorError> {
19+
pub fn read(&mut self) -> Result<SensorReading<u8>, SensorError> {
2020
// Start communication: pull pin low for 18ms, then release.
2121
let _ = self.dht.pin.set_low();
2222
self.dht.delay.delay_ms(18);
@@ -46,8 +46,8 @@ impl<P: InputPin + OutputPin, D: DelayNs> Dht11<P, D> {
4646
}
4747

4848
Ok(SensorReading {
49-
humidity: humidity_integer as f32,
50-
temperature: temperature_integer as f32,
49+
humidity: humidity_integer,
50+
temperature: temperature_integer,
5151
})
5252
}
5353
}

src/dht22.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl<P: InputPin + OutputPin, D: DelayNs> Dht22<P, D> {
1616
}
1717
}
1818

19-
pub fn read(&mut self) -> Result<SensorReading, SensorError> {
19+
pub fn read(&mut self) -> Result<SensorReading<f32>, SensorError> {
2020
// Start communication: pull pin low for 18ms, then release.
2121
let _ = self.dht.pin.set_low();
2222
self.dht.delay.delay_ms(18);
@@ -52,8 +52,8 @@ impl<P: InputPin + OutputPin, D: DelayNs> Dht22<P, D> {
5252
let temperatue_percentage = temperature_value as f32 / 10.0;
5353

5454
Ok(SensorReading {
55-
humidity: humidity_percentage as f32,
56-
temperature: temperatue_percentage as f32,
55+
humidity: humidity_percentage,
56+
temperature: temperatue_percentage,
5757
})
5858
}
5959
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ pub mod dht20;
66
pub mod dht22;
77

88
/// Represents a reading from the sensor.
9-
pub struct SensorReading {
10-
pub humidity: f32,
11-
pub temperature: f32,
9+
pub struct SensorReading<T> {
10+
pub humidity: T,
11+
pub temperature: T,
1212
}
1313

1414
/// Possible errors when interacting with the sensor.

0 commit comments

Comments
 (0)