Skip to contentSkip to conversation

iio: dht11: Improve detection of sensor type

PATCH Applied Harald Geyer 2 participants 2 messages Feb 11, 2018 – Feb 17, 2018 IIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: dht11: Improve detection of sensor type

The old code was based on a DHT11 datasheet which specifies a measurement range of 20%-90% RH. Turns out the sensor actually reports values outside this range, so we should support it as far as possible.

---
 drivers/iio/humidity/dht11.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/humidity/dht11.c +1 -1
index df6bab4..1a9f8f4 100644
@@ -159,7 +159,7 @@ static int dht11_decode(struct dht11 *dht11, int offset)
 	}
 
 	dht11->timestamp = ktime_get_boot_ns();
-	if (hum_int < 20) {  /* DHT22 */
+	if (hum_int < 4) {  /* DHT22: 100000 = (3*256+232)*100 */
 		dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
 					((temp_int & 0x80) ? -100 : 100);
 		dht11->humidity = ((hum_int << 8) + hum_dec) * 100;
Signature · 1 line
2.1.4
maintainer Applied
#1 lore raw
Quoted 6 lines · On Sun, 11 Feb 2018 11:09:40 +0000 Harald Geyer <[email protected]> wrote:

The old code was based on a DHT11 datasheet which specifies a measurement range of 20%-90% RH. Turns out the sensor actually reports values outside this range, so we should support it as far as possible.

Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan

Quoted 17 lines
---
 drivers/iio/humidity/dht11.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/humidity/dht11.c +1 -1
index df6bab4..1a9f8f4 100644
@@ -159,7 +159,7 @@ static int dht11_decode(struct dht11 *dht11, int offset)
 	}
 
 	dht11->timestamp = ktime_get_boot_ns();
-	if (hum_int < 20) {  /* DHT22 */
+	if (hum_int < 4) {  /* DHT22: 100000 = (3*256+232)*100 */
 		dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
 					((temp_int & 0x80) ? -100 : 100);
 		dht11->humidity = ((hum_int << 8) + hum_dec) * 100;