2015-05-15 22:10:27 +02:00
|
|
|
/*
|
2016-01-21 15:24:57 +01:00
|
|
|
* Copyright 2015 Ludwig Knüpfer,
|
|
|
|
* 2015 Christian Mehlis
|
2017-01-30 16:47:26 +01:00
|
|
|
* 2016-2017 Freie Universität Berlin
|
2015-05-15 22:10:27 +02:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-11-19 17:13:33 +01:00
|
|
|
* @defgroup drivers_dht DHT Family of Humidity and Temperature Sensors
|
2015-09-25 21:06:17 +02:00
|
|
|
* @ingroup drivers_sensors
|
2015-05-15 22:10:27 +02:00
|
|
|
* @brief Device driver for the DHT Family of humidity
|
|
|
|
* and temperature sensors
|
|
|
|
*
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Device driver interface for the DHT family of humidity
|
|
|
|
* and temperature sensors
|
|
|
|
*
|
2015-09-27 18:58:30 +02:00
|
|
|
* @author Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de
|
2015-05-15 22:10:27 +02:00
|
|
|
* @author Christian Mehlis <mehlis@inf.fu-berlin.de>
|
2016-01-21 15:24:57 +01:00
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2015-05-15 22:10:27 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DHT_H
|
|
|
|
#define DHT_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2016-01-21 22:33:02 +01:00
|
|
|
#include "saul.h"
|
2015-05-15 22:10:27 +02:00
|
|
|
#include "periph/gpio.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-30 16:47:26 +01:00
|
|
|
/**
|
|
|
|
* @brief possible return codes
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
DHT_OK = 0, /**< all good */
|
|
|
|
DHT_NOCSUM = -1, /**< checksum error */
|
|
|
|
DHT_NODEV = -2 /**< device type not defined */
|
|
|
|
};
|
|
|
|
|
2015-05-15 22:10:27 +02:00
|
|
|
/**
|
|
|
|
* @brief data type for storing DHT sensor readings
|
|
|
|
*/
|
|
|
|
typedef struct {
|
|
|
|
uint16_t humidity; /**< relative deca-humidity */
|
|
|
|
uint16_t temperature; /**< temperature in deca-Celsius */
|
|
|
|
} dht_data_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief device type of the DHT device
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
DHT11, /**< DHT11 device identifier */
|
2015-06-06 17:07:00 +02:00
|
|
|
DHT22, /**< DHT22 device identifier */
|
|
|
|
DHT21 = DHT22 /**< DHT21 device identifier */
|
2015-05-15 22:10:27 +02:00
|
|
|
} dht_type_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief device descriptor for DHT sensor devices
|
|
|
|
*/
|
|
|
|
typedef struct {
|
2016-01-21 15:24:57 +01:00
|
|
|
gpio_t pin; /**< GPIO pin of the device's data pin */
|
2015-05-15 22:10:27 +02:00
|
|
|
dht_type_t type; /**< type of the DHT device */
|
2016-03-17 14:55:01 +01:00
|
|
|
gpio_mode_t in_mode; /**< input pin configuration, with or without pull
|
|
|
|
* resistor */
|
2015-05-15 22:10:27 +02:00
|
|
|
} dht_t;
|
|
|
|
|
2016-01-21 15:24:57 +01:00
|
|
|
/**
|
|
|
|
* @brief configuration parameters for DHT devices
|
|
|
|
*/
|
|
|
|
typedef dht_t dht_params_t;
|
|
|
|
|
2016-01-21 22:33:02 +01:00
|
|
|
/**
|
|
|
|
* @brief export SAUL endpoints
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
extern const saul_driver_t dht_temp_saul_driver;
|
|
|
|
extern const saul_driver_t dht_hum_saul_driver;
|
|
|
|
/** @} */
|
|
|
|
|
2016-01-21 15:24:57 +01:00
|
|
|
/**
|
|
|
|
* @brief auto-initialize all configured DHT devices
|
|
|
|
*/
|
|
|
|
void dht_auto_init(void);
|
|
|
|
|
2015-05-15 22:10:27 +02:00
|
|
|
/**
|
|
|
|
* @brief initialize a new DHT device
|
|
|
|
*
|
2016-01-21 15:24:57 +01:00
|
|
|
* @param[out] dev device descriptor of a DHT device
|
|
|
|
* @param[in] params configuration parameters
|
2015-05-15 22:10:27 +02:00
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on error
|
|
|
|
*/
|
2016-01-21 15:24:57 +01:00
|
|
|
int dht_init(dht_t *dev, const dht_params_t *params);
|
2015-05-15 22:10:27 +02:00
|
|
|
|
2016-01-21 18:42:36 +01:00
|
|
|
/**
|
|
|
|
* @brief get a new temperature and humidity value from the device
|
2015-05-15 22:10:27 +02:00
|
|
|
*
|
2016-01-21 18:42:36 +01:00
|
|
|
* @note if reading fails or checksum is invalid, no new values will be
|
|
|
|
* written into the result values
|
2015-05-15 22:10:27 +02:00
|
|
|
*
|
2016-01-21 18:42:36 +01:00
|
|
|
* @param[in] dev device descriptor of a DHT device
|
|
|
|
* @param[out] temp temperature value [in °C * 10^-1]
|
|
|
|
* @param[out] hum relative humidity value [in percent * 10^-1]
|
2015-05-15 22:10:27 +02:00
|
|
|
*
|
|
|
|
* @return 0 on success
|
|
|
|
* @return -1 on checksum error
|
2016-01-21 18:42:36 +01:00
|
|
|
* @return -2 on parsing error
|
2015-05-15 22:10:27 +02:00
|
|
|
*/
|
2016-01-21 18:42:36 +01:00
|
|
|
int dht_read(dht_t *dev, int16_t *temp, int16_t *hum);
|
2015-05-15 22:10:27 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* DHT_H */
|
|
|
|
/** @} */
|