/// © MiroZ 2024 #ifndef __TASK_FACTORY_H__ #define __TASK_FACTORY_H__ #include #include #include #include #include #include typedef std::function TASK_FUNCTION; // no need for mutex here #define _USE_MUTEX class TaskFactory { protected: #ifdef USE_MUTEX SemaphoreHandle_t m_xMutex = NULL; #endif TASK_FUNCTION m_task_function = nullptr; protected: static void taskStarter(void * ptr) { (static_cast(ptr)->run()); } void run(){ m_task_function(); } public: TaskHandle_t createTask(TASK_FUNCTION task_function, const char *name, uint32_t stack_size, UBaseType_t priority, BaseType_t core); static uint32_t getStackHighWaterMark(TaskHandle_t task){ return (uint32_t)uxTaskGetStackHighWaterMark(task); } TaskFactory(); ~TaskFactory(); }; extern TaskFactory TASK_FACTORY; #endif /* __TASK_FACTORY_H__ */