WIP
This commit is contained in:
@ -5,25 +5,33 @@
|
||||
#include "esp_err.h"
|
||||
#include "esp_log.h"
|
||||
#include "driver/gpio.h"
|
||||
#ifdef CONFIG_IDF_TARGET_ESP8266
|
||||
#include "driver/i2c.h"
|
||||
#else
|
||||
#include "driver/i2c_master.h"
|
||||
#endif
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/task.h"
|
||||
|
||||
#define ZH_DHT_INIT_CONFIG_DEFAULT() \
|
||||
{ \
|
||||
.sensor_pin = 0xFF, \
|
||||
.i2c_port = 0 \
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef enum // Enumeration of supported sensor types.
|
||||
typedef struct
|
||||
{
|
||||
ZH_DHT11, // Sensor type DHT11.
|
||||
ZH_DHT22 // Sensor type DHT22 or AM2302.
|
||||
} zh_dht_sensor_type_t;
|
||||
|
||||
typedef struct // Unique handle of the sensor.
|
||||
{
|
||||
uint8_t sensor_pin; // Sensor GPIO connection.
|
||||
zh_dht_sensor_type_t sensor_type; // Sensor type.
|
||||
} zh_dht_handle_t;
|
||||
uint8_t sensor_pin; // Sensor GPIO connection.
|
||||
bool i2c_port; // I2C port.
|
||||
#ifndef CONFIG_IDF_TARGET_ESP8266
|
||||
i2c_master_bus_handle_t i2c_handle; // Unique I2C bus handle.
|
||||
#endif
|
||||
} zh_dht_init_config_t;
|
||||
|
||||
/**
|
||||
* @brief Initialize DHT sensor.
|
||||
@ -33,7 +41,7 @@ extern "C"
|
||||
*
|
||||
* @return Handle of the sensor
|
||||
*/
|
||||
zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin);
|
||||
esp_err_t zh_dht_init(const zh_dht_init_config_t *config);
|
||||
|
||||
/**
|
||||
* @brief Read DHT sensor.
|
||||
@ -49,7 +57,7 @@ extern "C"
|
||||
* - ESP_ERR_TIMEOUT if operation timeout
|
||||
* - ESP_ERR_INVALID_CRC if check CRC is fail
|
||||
*/
|
||||
esp_err_t zh_dht_read(const zh_dht_handle_t *dht_handle, float *humidity, float *temperature);
|
||||
esp_err_t zh_dht_read(float *humidity, float *temperature);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Reference in New Issue
Block a user