ESP32S2_Cal/main/service/service_dht.c

51 lines
1.2 KiB
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) {
if_standby_queue_t queue_item;
htu21d_result_t result;
for (;;) {
while(htu21d_measure(&s_htu, &result) != HTU21D_OK) {
vTaskDelay(pdMS_TO_TICKS(100));
}
queue_item.item = IF_STANDBY_ITEM_TEMP,
snprintf(queue_item.payload, 16, "%.2f", result.temperature);
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
queue_item.item = IF_STANDBY_ITEM_HUMID;
snprintf(queue_item.payload, 16, "%.2f", result.humidity);
xQueueSendToBack(g_standby_screen_queue, &queue_item, 0);
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;
}