4 #include "freertos/FreeRTOS.h"
5 #include "freertos/task.h"
23 Task(
const char* name,
int stackSize,
int priority = 1,
int core = -1) {
24 create(name, stackSize, priority, core);
31 bool create(
const char* name,
int stackSize,
int priority = 1,
33 if (xHandle != 0)
return false;
36 xTaskCreatePinnedToCore(task_loop, name, stackSize,
this, priority,
39 xTaskCreate(task_loop, name, stackSize,
this, priority, &xHandle);
41 xTaskCreate(task_loop, name, stackSize,
this, priority, &xHandle);
49 if (xHandle !=
nullptr) {
56 bool begin(std::function<
void()> process) {
64 void end() { suspend(); }
66 void suspend() { vTaskSuspend(xHandle); }
68 void resume() { vTaskResume(xHandle); }
70 TaskHandle_t &getTaskHandle() {
74 void setReference(
void *r){
84 return xPortGetCoreID();
89 TaskHandle_t xHandle =
nullptr;
90 std::function<void()> loop_code = nop;
93 static void nop() { delay(100); }
95 static void task_loop(
void* arg) {