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;
|
_init_config = *config;
|
||||||
if (_init_config.sensor_pin != 0xFF)
|
if (_init_config.sensor_pin != 0xFF)
|
||||||
{
|
{
|
||||||
gpio_config_t cfg = {0};
|
gpio_config_t one_wire_config = {0};
|
||||||
cfg.intr_type = GPIO_INTR_DISABLE;
|
one_wire_config.intr_type = GPIO_INTR_DISABLE;
|
||||||
cfg.mode = GPIO_MODE_INPUT;
|
one_wire_config.mode = GPIO_MODE_INPUT;
|
||||||
cfg.pin_bit_mask = (1ULL << _init_config.sensor_pin);
|
one_wire_config.pin_bit_mask = (1ULL << _init_config.sensor_pin);
|
||||||
cfg.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
one_wire_config.pull_down_en = GPIO_PULLDOWN_DISABLE;
|
||||||
cfg.pull_up_en = GPIO_PULLUP_ENABLE;
|
one_wire_config.pull_up_en = GPIO_PULLUP_ENABLE;
|
||||||
if (gpio_config(&cfg) != ESP_OK)
|
if (gpio_config(&one_wire_config) != ESP_OK)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "DHT initialization fail. Incorrect GPIO number.");
|
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
|
else
|
||||||
{
|
{
|
||||||
// I2C.
|
// I2C.
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "DHT initialization success.");
|
|
||||||
_is_initialized = true;
|
_is_initialized = true;
|
||||||
return ESP_OK;
|
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.");
|
ESP_LOGE(TAG, "DHT read fail. BH1750 not initialized.");
|
||||||
return ESP_ERR_NOT_FOUND;
|
return ESP_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
if (_init_config.sensor_pin != 0xFF)
|
||||||
|
{
|
||||||
if (gpio_get_level(_init_config.sensor_pin) != 1)
|
if (gpio_get_level(_init_config.sensor_pin) != 1)
|
||||||
{
|
{
|
||||||
ESP_LOGE(TAG, "DHT read fail. Bus is busy.");
|
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;
|
*temperature *= -1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ESP_LOGI(TAG, "DHT read success.");
|
ESP_LOGI(TAG, "DHT read success.");
|
||||||
return ESP_OK;
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user