diff --git a/.gitignore b/.gitignore index 496ee2c..6d0ee45 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ +.vscode .DS_Store \ No newline at end of file diff --git a/include/zh_dht.h b/include/zh_dht.h index 688969e..4e622f1 100644 --- a/include/zh_dht.h +++ b/include/zh_dht.h @@ -24,8 +24,9 @@ extern "C" */ typedef enum { - ZH_DHT11, ///< Sensor type DHT11. - ZH_DHT22 ///< Sensor type DHT22 or AM2302. + ZH_DHT11, ///< Sensor type DHT11. + ZH_DHT22, ///< Sensor type DHT22 or AM2302. + ZH_AM2320, ///< Sensor type AM2320. } zh_dht_sensor_type_t; /** @@ -34,7 +35,7 @@ extern "C" */ typedef struct { - uint8_t sensor_pin; ///< Sensor GPIO connection. @note + uint8_t sensor_pin; ///< Sensor GPIO connection. @note Can be NULL for AM2320 sensor with I2C connection. zh_dht_sensor_type_t sensor_type; ///< Sensor type. @note } zh_dht_handle_t; @@ -46,7 +47,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); + zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_t *sensor_pin); /** * @brief Read DHT sensor. diff --git a/zh_dht.c b/zh_dht.c index 58a50ae..4806686 100644 --- a/zh_dht.c +++ b/zh_dht.c @@ -25,7 +25,7 @@ static const char *TAG = "zh_dht"; 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."); zh_dht_handle_t zh_dht_handle = { @@ -34,7 +34,7 @@ zh_dht_handle_t zh_dht_init(const zh_dht_sensor_type_t sensor_type, const uint8_ gpio_config_t config = {0}; config.intr_type = GPIO_INTR_DISABLE; config.mode = GPIO_MODE_INPUT; - config.pin_bit_mask = (1ULL << sensor_pin); + config.pin_bit_mask = (1ULL << *sensor_pin); config.pull_down_en = GPIO_PULLDOWN_DISABLE; config.pull_up_en = GPIO_PULLUP_ENABLE; if (gpio_config(&config) != ESP_OK)