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>
This commit is contained in:
Phil Elwell
2024-11-04 14:10:53 +00:00
committed by Dom Cobley
parent 6fa2c584ba
commit e8a0f3edf2

View File

@@ -151,9 +151,9 @@ static int dht11_decode(struct dht11 *dht11, int offset)
dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) * dht11->temperature = (((temp_int & 0x7f) << 8) + temp_dec) *
((temp_int & 0x80) ? -100 : 100); ((temp_int & 0x80) ? -100 : 100);
dht11->humidity = ((hum_int << 8) + hum_dec) * 100; dht11->humidity = ((hum_int << 8) + hum_dec) * 100;
} else if (temp_dec == 0 && hum_dec == 0) { /* DHT11 */ } else if (temp_dec < 10 && hum_dec < 10) { /* DHT11 */
dht11->temperature = temp_int * 1000; dht11->temperature = temp_int * 1000 + temp_dec * 100;
dht11->humidity = hum_int * 1000; dht11->humidity = hum_int * 1000 + hum_dec * 100;
} else { } else {
dev_err(dht11->dev, dev_err(dht11->dev,
"Don't know how to decode data: %d %d %d %d\n", "Don't know how to decode data: %d %d %d %d\n",