dht.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015 Ludwig Knüpfer,
3  * 2015 Christian Mehlis
4  * 2016-2017 Freie Universität Berlin
5  *
6  * This file is subject to the terms and conditions of the GNU Lesser
7  * General Public License v2.1. See the file LICENSE in the top level
8  * directory for more details.
9  */
10 
31 #ifndef DHT_H
32 #define DHT_H
33 
34 #include <stdint.h>
35 
36 #include "periph/gpio.h"
37 
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
45 enum {
46  DHT_OK = 0,
47  DHT_NOCSUM = -1,
48  DHT_TIMEOUT = -2,
49  DHT_NODEV = -3
50 };
51 
55 typedef struct {
56  uint16_t humidity;
57  uint16_t temperature;
58 } dht_data_t;
59 
63 typedef enum {
67 } dht_type_t;
68 
72 typedef struct {
73  gpio_t pin;
78 } dht_params_t;
79 
83 typedef struct {
86  uint32_t last_read_us;
87 } dht_t;
88 
98 int dht_init(dht_t *dev, const dht_params_t *params);
99 
115 int dht_read(dht_t *dev, int16_t *temp, int16_t *hum);
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif /* DHT_H */
122 
DHT_OK
@ DHT_OK
all good
Definition: dht.h:46
dht_read
int dht_read(dht_t *dev, int16_t *temp, int16_t *hum)
get a new temperature and humidity value from the device
DHT22
@ DHT22
DHT22 device identifier.
Definition: dht.h:65
dht_t::last_read_us
uint32_t last_read_us
Time of the last measurement.
Definition: dht.h:86
dht_data_t::humidity
uint16_t humidity
relative deca-humidity
Definition: dht.h:56
dht_type_t
dht_type_t
Device type of the DHT device.
Definition: dht.h:63
DHT21
@ DHT21
DHT21 device identifier.
Definition: dht.h:66
dht_t
Device descriptor for DHT sensor devices.
Definition: dht.h:83
dht_init
int dht_init(dht_t *dev, const dht_params_t *params)
Initialize a new DHT device.
dht_t::params
dht_params_t params
Device parameters.
Definition: dht.h:84
DHT_NODEV
@ DHT_NODEV
device type not defined
Definition: dht.h:49
dht_t::last_val
dht_data_t last_val
Values of the last measurement.
Definition: dht.h:85
DHT_TIMEOUT
@ DHT_TIMEOUT
communication timed out
Definition: dht.h:48
DHT_NOCSUM
@ DHT_NOCSUM
checksum error
Definition: dht.h:47
dht_params_t::type
dht_type_t type
type of the DHT device
Definition: dht.h:74
dht_data_t::temperature
uint16_t temperature
temperature in deca-Celsius
Definition: dht.h:57
gpio.h
Low-level GPIO peripheral driver interface definitions.
DHT11
@ DHT11
DHT11 device identifier.
Definition: dht.h:64
dht_data_t
Data type for storing DHT sensor readings.
Definition: dht.h:55
gpio_mode_t
gpio_mode_t
Available pin modes.
Definition: periph_cpu.h:70
dht_params_t
Configuration parameters for DHT devices.
Definition: dht.h:72
dht_params_t::in_mode
gpio_mode_t in_mode
input pin configuration, with or without pull resistor
Definition: dht.h:75
dht_params_t::pin
gpio_t pin
GPIO pin of the device's data pin.
Definition: dht.h:73