mirror of
https://github.com/openwrt/openwrt.git
synced 2025-01-28 23:23:59 +00:00
33 lines
1.3 KiB
Diff
33 lines
1.3 KiB
Diff
|
From ce65ed02cb6707ae5c9f3a304f5b0124f4eed559 Mon Sep 17 00:00:00 2001
|
||
|
From: Phil Elwell <phil@raspberrypi.com>
|
||
|
Date: Mon, 4 Nov 2024 14:10:53 +0000
|
||
|
Subject: [PATCH] iio: humidity: dht11: Allow non-zero decimals
|
||
|
|
||
|
The DHT11 datasheet is pretty cryptic, but it does suggest that after
|
||
|
each integer value (humidity and temperature) there are "decimal"
|
||
|
values. Validate these as integers in the range 0-9 and treat them as
|
||
|
tenths of a unit.
|
||
|
|
||
|
Link: https://github.com/raspberrypi/linux/issues/6220
|
||
|
|
||
|
Signed-off-by: Phil Elwell <phil@raspberrypi.com>
|
||
|
---
|
||
|
drivers/iio/humidity/dht11.c | 6 +++---
|
||
|
1 file changed, 3 insertions(+), 3 deletions(-)
|
||
|
|
||
|
--- a/drivers/iio/humidity/dht11.c
|
||
|
+++ b/drivers/iio/humidity/dht11.c
|
||
|
@@ -152,9 +152,9 @@ static int dht11_decode(struct dht11 *dh
|
||
|
dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
|
||
|
((temp_int & 0x80) ? -100 : 100);
|
||
|
dht11->humidity = ((hum_int << 8) + hum_dec) * 100;
|
||
|
- } else if (temp_dec == 0 && hum_dec == 0) { /* DHT11 */
|
||
|
- dht11->temperature = temp_int * 1000;
|
||
|
- dht11->humidity = hum_int * 1000;
|
||
|
+ } else if (temp_dec < 10 && hum_dec < 10) { /* DHT11 */
|
||
|
+ dht11->temperature = temp_int * 1000 + temp_dec * 100;
|
||
|
+ dht11->humidity = hum_int * 1000 + hum_dec * 100;
|
||
|
} else {
|
||
|
dev_err(dht11->dev,
|
||
|
"Don't know how to decode data: %d %d %d %d\n",
|