63 lines
1.2 KiB
C++
63 lines
1.2 KiB
C++
#include "sampler_task.h"
|
|
#include "ringbuf.h"
|
|
#include "ds18b20.h" // добавим
|
|
|
|
extern "C" {
|
|
#include "freertos/FreeRTOS.h"
|
|
#include "freertos/task.h"
|
|
#include "esp_timer.h"
|
|
}
|
|
|
|
// буфер
|
|
static ringbuf_t rb;
|
|
|
|
ringbuf_t* sampler_get_buffer()
|
|
{
|
|
return &rb;
|
|
}
|
|
|
|
static TaskHandle_t sampler_task_handle = nullptr;
|
|
|
|
static void sampler_task(void* arg)
|
|
{
|
|
const TickType_t period = pdMS_TO_TICKS(6000);
|
|
TickType_t last_wake = xTaskGetTickCount();
|
|
|
|
while (1)
|
|
{
|
|
int64_t now_ms = esp_timer_get_time() / 1000;
|
|
|
|
float temp = ds18b20_read();
|
|
ringbuf_push(&rb, now_ms, (int)(temp * 100));
|
|
|
|
vTaskDelayUntil(&last_wake, period); // 6 секунд
|
|
}
|
|
}
|
|
|
|
void sampler_task_start()
|
|
{
|
|
if (sampler_task_handle == nullptr)
|
|
{
|
|
ringbuf_init(&rb);
|
|
ds18b20_init(GPIO_NUM_27); // новый драйвер
|
|
|
|
xTaskCreate(
|
|
sampler_task,
|
|
"sampler",
|
|
4096,
|
|
nullptr,
|
|
5,
|
|
&sampler_task_handle
|
|
);
|
|
}
|
|
}
|
|
|
|
void sampler_task_stop()
|
|
{
|
|
if (sampler_task_handle != nullptr)
|
|
{
|
|
vTaskDelete(sampler_task_handle);
|
|
sampler_task_handle = nullptr;
|
|
}
|
|
}
|