46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
#include "service_dht.h"
|
|
|
|
#include "esp_log.h"
|
|
#include "if_standby.h"
|
|
#include "impl_dht.h"
|
|
#include "task_config.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, "SVC_DHT", TASK_SVC_DHT_STACK_SIZE, NULL, TASK_SVC_DHT_PRIORITY, &s_dht_task_handle) !=
|
|
pdTRUE) {
|
|
return ESP_FAIL;
|
|
}
|
|
|
|
return ESP_OK;
|
|
} |