1 Star 0 Fork 0

奥大梨呀/base-application

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
BaseApplication.h 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
奥大梨呀 提交于 2025-01-25 22:18 +08:00 . upload
#ifndef BASE_APPLICATION_H
#define BASE_APPLICATION_H
#include "FreeRTOS.h"
#include "task.h"
#include <vector>
#define BASEAPPLICATION_USING_EVENT 0u
#if BASEAPPLICATION_USING_EVENT
#include "queue.h"
#define BASEAPPLICATION_EVENT_QUEUE_LENGTH 3u
#endif
class BaseApplication;
class BaseApplication
{
private:
uint32_t _stackDepth; // 任务栈深度(字节)
bool ApplicationRunFlag; // 程序启动运行标志位
bool ApplicationExitFlag; // 程序退出完毕标志位
bool ApplicationPauseFlag; // 程序暂停标志位
TaskHandle_t taskHandle; // 程序线程句柄
BaseApplication *parent; // 父对象
std::vector<BaseApplication *> *childList; // 子程序列表
static constexpr int defaultMainTaskStackDepth = 256;
#if BASEAPPLICATION_USING_EVENT
static constexpr int defaultEventTaskStackDepth = 256;
static constexpr int quitEvent = 0x12345678;
uint32_t eventTaskStackDepth;
QueueHandle_t eventQueue;
#endif
protected:
// 子类需要实现的方法
virtual void Setup(void) {} // 程序运行前调用一次
virtual void Loop(void) = 0; // 程序运行时循环调用
virtual void Exit(void) {} // 程序退出时调用一次
#if BASEAPPLICATION_USING_EVENT
virtual void EventHandler(int event) = 0; // 程序事件处理
#endif
friend void ApplicationTask(void *arg);
friend void EventTask(void *arg);
public:
BaseApplication(uint32_t stackDepth = defaultMainTaskStackDepth);
~BaseApplication();
void Run(void);
void Pause(void);
void AddChild(BaseApplication *child);
void RunChild(int index);
#if BASEAPPLICATION_USING_EVENT
void SetEventTaskStackDepth(uint32_t stackDepth) { eventTaskStackDepth = stackDepth; }
bool SendEvent(int event);
#endif
/**
* @brief 停止程序
*/
void Stop(void) { ApplicationRunFlag = false; }
};
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/Jumping99/base-application.git
git@gitee.com:Jumping99/base-application.git
Jumping99
base-application
base-application
master

搜索帮助