WIP
This commit is contained in:
21
zh_dht.c
21
zh_dht.c
@ -35,23 +35,23 @@ esp_err_t zh_dht_init(const zh_dht_init_config_t *config)
|
||||
_init_config = *config;
|
||||
if (_init_config.sensor_pin != 0xFF)
|
||||
{
|
||||
gpio_config_t cfg = {0};
|
||||
cfg.intr_type = GPIO_INTR_DISABLE;
|
||||
cfg.mode = GPIO_MODE_INPUT;
|
||||
cfg.pin_bit_mask = (1ULL << _init_config.sensor_pin);
|
||||
cfg.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
cfg.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
if (gpio_config(&cfg) != ESP_OK)
|
||||
gpio_config_t one_wire_config = {0};
|
||||
one_wire_config.intr_type = GPIO_INTR_DISABLE;
|
||||
one_wire_config.mode = GPIO_MODE_INPUT;
|
||||
one_wire_config.pin_bit_mask = (1ULL << _init_config.sensor_pin);
|
||||
one_wire_config.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||
one_wire_config.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||
if (gpio_config(&one_wire_config) != ESP_OK)
|
||||
{
|
||||
ESP_LOGE(TAG, "DHT initialization fail. Incorrect GPIO number.");
|
||||
return ESP_FAIL;
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_LOGI(TAG, "DHT initialization success. 1-wire connection.");
|
||||
}
|
||||
else
|
||||
{
|
||||
// I2C.
|
||||
}
|
||||
ESP_LOGI(TAG, "DHT initialization success.");
|
||||
_is_initialized = true;
|
||||
return ESP_OK;
|
||||
}
|
||||
@ -69,6 +69,8 @@ esp_err_t zh_dht_read(float *humidity, float *temperature)
|
||||
ESP_LOGE(TAG, "DHT read fail. BH1750 not initialized.");
|
||||
return ESP_ERR_NOT_FOUND;
|
||||
}
|
||||
if (_init_config.sensor_pin != 0xFF)
|
||||
{
|
||||
if (gpio_get_level(_init_config.sensor_pin) != 1)
|
||||
{
|
||||
ESP_LOGE(TAG, "DHT read fail. Bus is busy.");
|
||||
@ -145,6 +147,7 @@ esp_err_t zh_dht_read(float *humidity, float *temperature)
|
||||
{
|
||||
*temperature *= -1;
|
||||
}
|
||||
}
|
||||
ESP_LOGI(TAG, "DHT read success.");
|
||||
return ESP_OK;
|
||||
}
|
||||
|
Reference in New Issue
Block a user