Updated zh_dht

This commit is contained in:
2024-05-30 09:42:12 +03:00
parent bb0a99ac2b
commit 97c8418bda
4 changed files with 27 additions and 27 deletions

View File

@ -13,7 +13,7 @@ In an existing project, run the following command to install the component:
```text ```text
cd ../your_project/components cd ../your_project/components
git clone http://git.zh.com.ru/alexey.zholtikov/zh_dht.git git clone https://github.com/aZholtikov/zh_dht.git
``` ```
In the application, add the component: In the application, add the component:
@ -29,7 +29,7 @@ Reading the sensor:
```c ```c
#include "zh_dht.h" #include "zh_dht.h"
void app_main() void app_main(void)
{ {
zh_dht_handle_t dht_handle = zh_dht_init(ZH_DHT22, GPIO_NUM_5); zh_dht_handle_t dht_handle = zh_dht_init(ZH_DHT22, GPIO_NUM_5);
float humidity; float humidity;

View File

@ -24,9 +24,9 @@ extern "C"
*/ */
typedef enum typedef enum
{ {
ZH_DHT11, ///< Sensor type DHT11 ZH_DHT11, ///< Sensor type DHT11.
ZH_DHT22 ///< Sensor type DHT22 or AM2302 ZH_DHT22 ///< Sensor type DHT22 or AM2302.
} __attribute__((packed)) zh_dht_sensor_type_t; } zh_dht_sensor_type_t;
/** /**
* @brief Unique handle of the sensor. * @brief Unique handle of the sensor.
@ -34,34 +34,33 @@ extern "C"
*/ */
typedef struct typedef struct
{ {
uint8_t sensor_pin; ///< Sensor GPIO connection uint8_t sensor_pin; ///< Sensor GPIO connection. @note
zh_dht_sensor_type_t sensor_type; ///< Sensor type zh_dht_sensor_type_t sensor_type; ///< Sensor type. @note
} __attribute__((packed)) zh_dht_handle_t; } zh_dht_handle_t;
/** /**
* @brief Initialize DHT sensor. * @brief Initialize DHT sensor.
* *
* @param[in] sensor_type Sensor type (ZH_DHT11 or ZH_DHT22). * @param[in] sensor_type Sensor type.
* @param[in] sensor_pin Sensor connection gpio. * @param[in] sensor_pin Sensor connection gpio.
* *
* @return * @return Handle of the sensor
* - Handle of the sensor.
*/ */
zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin); zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin);
/** /**
* @brief Read DHT sensor. * @brief Read DHT sensor.
* *
* @param[in] dht_handle Pointer for handle of the sensor. * @param[in] dht_handle Pointer for handle of the sensor.
* @param[out] humidity Pointer for DHT sensor reading data of humidity. * @param[out] humidity Pointer for DHT sensor reading data of humidity.
* @param[out] temperature Pointer for DHT sensor reading data of temperature. * @param[out] temperature Pointer for DHT sensor reading data of temperature.
* *
* @return * @return
* - ESP_OK if read was success * - ESP_OK if read was success
* - ESP_ERR_INVALID_ARG if parameter error * - ESP_ERR_INVALID_ARG if parameter error
* - ESP_ERR_INVALID_RESPONSE if the bus is busy * - ESP_ERR_INVALID_RESPONSE if the bus is busy
* - ESP_ERR_TIMEOUT if operation timeout * - ESP_ERR_TIMEOUT if operation timeout
* - ESP_ERR_INVALID_CRC if check CRC is fail * - 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(const zh_dht_handle_t *dht_handle, float *humidity, float *temperature);

View File

@ -1 +1 @@
1.2.6 1.0.0

View File

@ -1,6 +1,7 @@
/** /**
* @file * @file
* The main code of the zh_dht component. * The main code of the zh_dht component.
*
*/ */
#include "zh_dht.h" #include "zh_dht.h"
@ -27,10 +28,10 @@ static esp_err_t _read_bit(const zh_dht_handle_t *dht_handle, bool *bit);
zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin) zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t sensor_pin)
{ {
ESP_LOGI(TAG, "DHT initialization begin."); ESP_LOGI(TAG, "DHT initialization begin.");
zh_dht_handle_t zh_dht_handle; zh_dht_handle_t zh_dht_handle = {
zh_dht_handle.sensor_type = sensor_type; .sensor_type = sensor_type,
zh_dht_handle.sensor_pin = sensor_pin; .sensor_pin = sensor_pin};
gpio_config_t config; gpio_config_t config = {0};
config.intr_type = GPIO_INTR_DISABLE; config.intr_type = GPIO_INTR_DISABLE;
config.mode = GPIO_MODE_INPUT; config.mode = GPIO_MODE_INPUT;
config.pin_bit_mask = (1ULL << sensor_pin); config.pin_bit_mask = (1ULL << sensor_pin);