45 lines
883 B
C++
45 lines
883 B
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 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() {
|
|
ringbuf_init(&rb);
|
|
ds18b20_init(GPIO_NUM_27); // новый драйвер
|
|
|
|
xTaskCreate(
|
|
sampler_task,
|
|
"sampler",
|
|
4096,
|
|
NULL,
|
|
5,
|
|
NULL
|
|
);
|
|
} |