From 97c8418bda6eec0f7e0ea6ec73d7c975fa254187 Mon Sep 17 00:00:00 2001 From: Alexey Zholtikov Date: Thu, 30 May 2024 09:42:12 +0300 Subject: [PATCH] Updated zh_dht --- components/zh_dht/README.md | 4 +-- components/zh_dht/include/zh_dht.h | 39 +++++++++++++++--------------- components/zh_dht/version.txt | 2 +- components/zh_dht/zh_dht.c | 9 ++++--- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/components/zh_dht/README.md b/components/zh_dht/README.md index 880573f..21e9991 100644 --- a/components/zh_dht/README.md +++ b/components/zh_dht/README.md @@ -13,7 +13,7 @@ In an existing project, run the following command to install the component: ```text 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: @@ -29,7 +29,7 @@ Reading the sensor: ```c #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); float humidity; diff --git a/components/zh_dht/include/zh_dht.h b/components/zh_dht/include/zh_dht.h index 8eaded0..688969e 100644 --- a/components/zh_dht/include/zh_dht.h +++ b/components/zh_dht/include/zh_dht.h @@ -24,9 +24,9 @@ extern "C" */ typedef enum { - ZH_DHT11, ///< Sensor type DHT11 - ZH_DHT22 ///< Sensor type DHT22 or AM2302 - } __attribute__((packed)) zh_dht_sensor_type_t; + ZH_DHT11, ///< Sensor type DHT11. + ZH_DHT22 ///< Sensor type DHT22 or AM2302. + } zh_dht_sensor_type_t; /** * @brief Unique handle of the sensor. @@ -34,34 +34,33 @@ extern "C" */ typedef struct { - uint8_t sensor_pin; ///< Sensor GPIO connection - zh_dht_sensor_type_t sensor_type; ///< Sensor type - } __attribute__((packed)) zh_dht_handle_t; + uint8_t sensor_pin; ///< Sensor GPIO connection. @note + zh_dht_sensor_type_t sensor_type; ///< Sensor type. @note + } 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_pin Sensor connection gpio. + * @param[in] sensor_type Sensor type. + * @param[in] sensor_pin Sensor connection gpio. * - * @return - * - Handle of the sensor. + * @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); /** - * @brief Read DHT sensor. + * @brief Read DHT sensor. * - * @param[in] dht_handle Pointer for handle of the sensor. - * @param[out] humidity Pointer for DHT sensor reading data of humidity. - * @param[out] temperature Pointer for DHT sensor reading data of temperature. + * @param[in] dht_handle Pointer for handle of the sensor. + * @param[out] humidity Pointer for DHT sensor reading data of humidity. + * @param[out] temperature Pointer for DHT sensor reading data of temperature. * * @return - * - ESP_OK if read was success - * - ESP_ERR_INVALID_ARG if parameter error - * - ESP_ERR_INVALID_RESPONSE if the bus is busy - * - ESP_ERR_TIMEOUT if operation timeout - * - ESP_ERR_INVALID_CRC if check CRC is fail + * - ESP_OK if read was success + * - ESP_ERR_INVALID_ARG if parameter error + * - ESP_ERR_INVALID_RESPONSE if the bus is busy + * - 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); diff --git a/components/zh_dht/version.txt b/components/zh_dht/version.txt index 7e099ec..afaf360 100644 --- a/components/zh_dht/version.txt +++ b/components/zh_dht/version.txt @@ -1 +1 @@ -1.2.6 \ No newline at end of file +1.0.0 \ No newline at end of file diff --git a/components/zh_dht/zh_dht.c b/components/zh_dht/zh_dht.c index 588ad6e..58a50ae 100644 --- a/components/zh_dht/zh_dht.c +++ b/components/zh_dht/zh_dht.c @@ -1,6 +1,7 @@ /** * @file * The main code of the zh_dht component. + * */ #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) { ESP_LOGI(TAG, "DHT initialization begin."); - zh_dht_handle_t zh_dht_handle; - zh_dht_handle.sensor_type = sensor_type; - zh_dht_handle.sensor_pin = sensor_pin; - gpio_config_t config; + zh_dht_handle_t zh_dht_handle = { + .sensor_type = sensor_type, + .sensor_pin = sensor_pin}; + gpio_config_t config = {0}; config.intr_type = GPIO_INTR_DISABLE; config.mode = GPIO_MODE_INPUT; config.pin_bit_mask = (1ULL << sensor_pin);