ESP32S2_Cal/main/service/service_dht.c

44 lines
1005 B
C

#include "service_dht.h"
#include "esp_log.h"
#include "if_standby.h"
#include "impl_dht.h"
#define LOG_TAG "SERVICE_DHT"
static htu21d_t s_htu = {
.cb =
{
.read_cb = impl_dht_i2c_read,
.write_cb = impl_dht_i2c_write,
.delay_cb = impl_dht_delay,
},
.user_data = NULL,
};
static TaskHandle_t s_dht_task_handle;
void dht_task(void *pvParameters) {
htu21d_result_t result;
for (;;) {
while(htu21d_measure(&s_htu, &result) != HTU21D_OK) {
vTaskDelay(pdMS_TO_TICKS(100));
}
if_standby_component_update(IF_STANDBY_COMPONENT_TEMP, "%.2f", result.temperature);
if_standby_component_update(IF_STANDBY_COMPONENT_HUMID, "%.2f", result.humidity);
vTaskDelay(pdMS_TO_TICKS(30000));
}
}
esp_err_t service_dht_init(void) {
htu21d_init(&s_htu);
if (xTaskCreate(dht_task, "DHT", 2048, NULL, 6, &s_dht_task_handle) != pdTRUE) {
return ESP_FAIL;
}
return ESP_OK;
}