Files
iot_skeleton/esp32/main/sampler_task.cpp

39 lines
773 B
C++

#include "sampler_task.h"
#include "adc_reader.h"
#include "ringbuf.h"
extern "C" {
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
}
// буфер объявим здесь (глобальный для простоты)
static ringbuf_t rb;
// дать доступ другим модулям (sender потом возьмёт)
ringbuf_t* sampler_get_buffer() {
return &rb;
}
static void sampler_task(void *arg) {
while (1) {
int val = adc_reader_read();
ringbuf_push(&rb, val);
vTaskDelay(pdMS_TO_TICKS(100)); // 10 Гц
}
}
void sampler_task_start() {
ringbuf_init(&rb);
adc_reader_init();
xTaskCreate(
sampler_task,
"sampler",
2048,
NULL,
5,
NULL
);
}