This commit is contained in:
2024-06-14 15:28:23 +03:00
parent 7339f1544b
commit 11d30d29f4
3 changed files with 8 additions and 6 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.vscode
.DS_Store

View File

@ -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.

View File

@ -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)