Minimize contract, add ADC read and send its data to coonsole
This commit is contained in:
39
esp32/main/sampler_task.cpp
Normal file
39
esp32/main/sampler_task.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#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
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user