Skip to content

Commit

Permalink
new new DHT11 data format handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hugueslarrive committed Jun 12, 2023
1 parent 0672ac1 commit 44ebdad
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/dht/dht.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ static int _parse_raw_values(dht_t *dev, uint8_t *data)
* abs() of value (beware: this is not two's complement!) */
is_negative = data[BYTEPOS_TEMPERATURE_LOW] & 0x80;
data[BYTEPOS_TEMPERATURE_LOW] &= ~0x80;
/* 2022-12 aosong.com data sheet uses interprets low bits as
* 0.01°C per LSB */
if (!dev->params.lsb_is_hundreds && data[BYTEPOS_TEMPERATURE_LOW] > 9) {
/* in case of miss configuration */
dev->params.lsb_is_hundreds = 1;
}
if (dev->params.lsb_is_hundreds) {
data[BYTEPOS_TEMPERATURE_LOW] /= 10;
}
dev->last_val.temperature = data[BYTEPOS_TEMPERATURE_HIGH] * 10
+ data[BYTEPOS_TEMPERATURE_LOW];
break;
Expand Down
5 changes: 5 additions & 0 deletions drivers/dht/include/dht_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,17 @@ extern "C" {
#ifndef DHT_PARAM_TYPE
#define DHT_PARAM_TYPE (DHT11)
#endif
#ifndef DHT_PARAM_LSB_IS_HUNDREDS
#define DHT_PARAM_LSB_IS_HUNDREDS (0)
#endif
#ifndef DHT_PARAM_PULL
#define DHT_PARAM_PULL (GPIO_IN)
#endif
#ifndef DHT_PARAMS
#define DHT_PARAMS { .pin = DHT_PARAM_PIN, \
.type = DHT_PARAM_TYPE, \
.lsb_is_hundreds = \
DHT_PARAM_LSB_IS_HUNDREDS, \
.in_mode = DHT_PARAM_PULL }
#endif
#ifndef DHT_SAULINFO
Expand Down
2 changes: 2 additions & 0 deletions drivers/include/dht.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ typedef enum {
typedef struct {
gpio_t pin; /**< GPIO pin of the device's data pin */
dht_type_t type; /**< type of the DHT device */
bool lsb_is_hundreds; /**< 2022-12 aosong.com data sheet uses interprets
* low bits as 0.01°C per LSB */
gpio_mode_t in_mode; /**< input pin configuration, with or without pull
* resistor */
} dht_params_t;
Expand Down

0 comments on commit 44ebdad

Please sign in to comment.