Skip to content

Commit

Permalink
iio: humidity: dht11: Allow non-zero decimals
Browse files Browse the repository at this point in the history
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: #6220

Signed-off-by: Phil Elwell <[email protected]>
  • Loading branch information
pelwell committed Nov 6, 2024
1 parent e9e852a commit ce65ed0
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/iio/humidity/dht11.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ static int dht11_decode(struct dht11 *dht11, int offset)
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",
Expand Down

0 comments on commit ce65ed0

Please sign in to comment.