diff --git a/Demo/STM32/HARDWARE/cTask/cTask.c b/Demo/STM32/HARDWARE/cTask/cTask.c new file mode 100644 index 0000000000000000000000000000000000000000..ef0c5734983166c5d0d291afc1d2fcc38c91b898 --- /dev/null +++ b/Demo/STM32/HARDWARE/cTask/cTask.c @@ -0,0 +1,387 @@ +/** + ********************************************************************************************************************** + * @file cTask.c + * @brief 该文件提供任务时间片论功能 + * @author const_zpc any question please send mail to const_zpc@163.com + * @version V0.1.0 + * @date 2022-04-16 + * + * @details 功能详细说明: + * + 任务调度初始化 + * + 任务调度功能启动 + * + ********************************************************************************************************************** + * 源码路径:https://gitee.com/const-zpc/cTask.git 具体问题及建议可在该网址填写 Issue + * + * 使用方式: + * 1、使用前初始化函数 cTASK_Init + * 2、主函数调用 cTASK_Start 启动任务调度, 函数不会退出 + * 3、使用 1ms 定时器中断调用 cTASK_Remarks + * 4、定义 sg_tTaskManage 添加任务 + * + * 注意事项: + * 1、每个任务函数不能被阻塞,尽量保证任务执行的时间小于 1ms,且调度周期一定要大于调度函数任务耗时 + * + ********************************************************************************************************************** + */ + +/* Includes ----------------------------------------------------------------------------------------------------------*/ +#include "cTask.h" +#include "cTask_cfg.h" +#include + +/* Private typedef ---------------------------------------------------------------------------------------------------*/ + +/** + * @brief 普通调度任务信息结构体定义 + */ +typedef struct +{ + bool isUsed; /*!< 是否被使用 */ + + bool isRunnig; /*!< 程序正在运行:0-不运行,1运行 */ + + uint8_t priority; /*!< 任务优先级, 值越小, 优先级越高 */ + + uint16_t timer; /*!< 计时器 */ + + uint16_t itvTime; /*!< 任务运行间隔时间 */ + + TaskRunCB pfnTaskHook; /*!< 要运行的任务函数 */ +} TaskInfo_t; + +/** + * @brief 中断任务信息结构体定义 + */ +typedef struct +{ + uint16_t timer; /*!< 计时器 */ + + uint16_t itvTime; /*!< 任务运行间隔时间 */ + + TaskRunCB pfnTaskHook; /*!< 要运行的任务函数 */ +} IsrTaskInfo_t; + +/** + * @brief 任务信息结构体定义 + */ +typedef struct +{ +#ifdef CTASK_USE_LOAD_RATE + uint8_t mcuLoadRate; /*!< mcuLoadRate 负载率 0-100% */ + + uint16_t idleTaskExpectedCnt; /*!< 空闲任务理想运行次数 */ + + uint16_t idleTaskActualCnt; /*!< 空闲任务实际运行次数 */ +#endif + bool isStart; /*!< 调度系统是否启动 */ + + uint32_t systimer; /*!< 系统计时器 */ + + TaskInfo_t task[CTASK_SUPPORT_NUM]; /*!< 普通任务:主循环调用 */ + + IsrTaskInfo_t isrTask[CTASK_ISR_SUPPORT_NUM];/*!< 中断任务:中断调用 */ +} TaskManage_t; + +/* Private define ----------------------------------------------------------------------------------------------------*/ +/* Private macro -----------------------------------------------------------------------------------------------------*/ +/* Private variables -------------------------------------------------------------------------------------------------*/ + +/*static*/ TaskManage_t sg_tTaskManage; + +/* Private function prototypes ---------------------------------------------------------------------------------------*/ +static void __IdleTask(void); +static void __IdleIsrTask(void); +/* Private function --------------------------------------------------------------------------------------------------*/ + +#ifdef CTASK_USE_LOAD_RATE +/** + * @brief 空闲任务 + * + */ +static void __IdleTask(void) +{ + sg_tTaskManage.idleTaskActualCnt++; +} + +/** + * @brief 空闲中断任务 + * + */ +static void __IdleIsrTask(void) +{ + sg_tTaskManage.idleTaskExpectedCnt++; + + if (sg_tTaskManage.idleTaskExpectedCnt >= 1000) + { + sg_tTaskManage.mcuLoadRate = 100 - (sg_tTaskManage.idleTaskActualCnt * 100 / sg_tTaskManage.idleTaskExpectedCnt); + sg_tTaskManage.idleTaskExpectedCnt = 0; + sg_tTaskManage.idleTaskActualCnt = 0; + } +} +#endif + +/** + * @brief 任务调度初始化 + * + */ +void cTASK_Init(void) +{ + int i; + + sg_tTaskManage.isStart = false; + sg_tTaskManage.mcuLoadRate = 0; + sg_tTaskManage.idleTaskActualCnt = 0; + sg_tTaskManage.idleTaskExpectedCnt = 0; + sg_tTaskManage.systimer = 0; + + for (i = 0; i < CTASK_SUPPORT_NUM; i++) + { + sg_tTaskManage.task[i].isUsed = false; + sg_tTaskManage.task[i].isRunnig = false; + sg_tTaskManage.task[i].itvTime = 0; + sg_tTaskManage.task[i].pfnTaskHook = NULL; + sg_tTaskManage.task[i].timer = 0; + sg_tTaskManage.task[i].priority = 255; + } + + for (i = 0; i < CTASK_ISR_SUPPORT_NUM; i++) + { + sg_tTaskManage.isrTask[i].itvTime = 0; + sg_tTaskManage.isrTask[i].pfnTaskHook = NULL; + sg_tTaskManage.isrTask[i].timer = 0; + } + +#ifdef CTASK_USE_LOAD_RATE + cTASK_Creat(__IdleTask, 1, 255); + cTASK_IsrCreat(__IdleIsrTask, 1); +#endif +} + +/** + * @brief 创建新的任务调度 + * + * @note 任务函数不能被阻塞,尽量保证任务执行的时间小于 1ms,且调度周期一定要大于调度函数任务耗时 + * @param[in] pfnTask 回调任务函数 + * @param[in] time 调度周期, 单位ms. + * @param[in] priority 调度优先级 5-250, 其他预留, 值越小, 优先级越高 + */ +void cTASK_Creat(TaskRunCB pfnTask, uint16_t time, uint8_t priority) +{ + int i, j; + + if (priority < 5) + { + priority = 5; + } + + if (priority > 250) + { + priority = 250; + } + + for (i = 0; i < CTASK_SUPPORT_NUM; i++) + { + if (sg_tTaskManage.task[i].priority < priority) + { + continue; + } + + if (sg_tTaskManage.task[i].isUsed) + { + for (j = CTASK_SUPPORT_NUM - 1; j > i; j--) + { + sg_tTaskManage.task[j] = sg_tTaskManage.task[j - 1]; + sg_tTaskManage.task[j - 1].isUsed = false; + } + } + + sg_tTaskManage.task[i].isUsed = true; + sg_tTaskManage.task[i].isRunnig = false; + sg_tTaskManage.task[i].itvTime = time; + sg_tTaskManage.task[i].pfnTaskHook = pfnTask; + sg_tTaskManage.task[i].timer = time; + sg_tTaskManage.task[i].priority = priority; + break; + } +} + +/** + * @brief 销毁任务 + * + * @param[in] pfnTask 回调任务函数 + */ +void cTASK_Destory(TaskRunCB pfnTask) +{ + int i; + + for (i = 0; i < CTASK_SUPPORT_NUM; i++) + { + if (sg_tTaskManage.task[i].pfnTaskHook == pfnTask) + { + sg_tTaskManage.task[i].isUsed = false; + break; + } + } +} + +/** + * @brief 创建新的中断任务调度 + * + * @note 由于采用的是中断方式, 中断任务函数不能被阻塞,必须保证任务耗时极短; 适用于要求极高且耗时极短的任务 + * @param[in] pfnTask 回调任务函数 + * @param[in] time 调度周期, 单位ms. + */ +void cTASK_IsrCreat(TaskRunCB pfnTask, uint16_t time) +{ + int i; + + for (i = 0; i < CTASK_ISR_SUPPORT_NUM; i++) + { + if (sg_tTaskManage.isrTask[i].pfnTaskHook == NULL) + { + sg_tTaskManage.isrTask[i].itvTime = time; + sg_tTaskManage.isrTask[i].pfnTaskHook = pfnTask; + sg_tTaskManage.isrTask[i].timer = time; + break; + } + } +} + +/** + * @brief 销毁中断任务 + * + * @param[in] pfnTask 回调任务函数 + */ +void cTASK_IsrDestory(TaskRunCB pfnTask) +{ + int i, j; + + for (i = 0; i < CTASK_ISR_SUPPORT_NUM; i++) + { + if (sg_tTaskManage.isrTask[i].pfnTaskHook == pfnTask) + { + sg_tTaskManage.isrTask[i].pfnTaskHook = NULL; + + for (j = i; j < CTASK_ISR_SUPPORT_NUM - 1; j++) + { + sg_tTaskManage.isrTask[j] = sg_tTaskManage.isrTask[j + 1]; + } + + break; + } + } +} + +/** + * @brief 执行任务调度函数 + */ +static void __TaskScheduling(void) +{ + uint8_t idx = 0; + + while (idx < CTASK_SUPPORT_NUM && sg_tTaskManage.task[idx].pfnTaskHook != NULL) + { + if (sg_tTaskManage.task[idx].isUsed && sg_tTaskManage.task[idx].isRunnig) + { + sg_tTaskManage.task[idx].pfnTaskHook(); + sg_tTaskManage.task[idx].isRunnig = false; + break; + } + + idx++; + } +} + +/** + * @brief 任务启动. + * + */ +void cTASK_Start(void) +{ + sg_tTaskManage.isStart = true; + + while (1) + { + __TaskScheduling(); + } +} + +/** + * @brief 任务调度状态管理. + * + * @note 需要 1ms 定时器中断调用 + */ +void cTASK_Remarks(void) +{ + uint8_t idx = 0; + + if (!sg_tTaskManage.isStart) + { + return; + } + + sg_tTaskManage.systimer++; + + while (idx < CTASK_SUPPORT_NUM && sg_tTaskManage.task[idx].pfnTaskHook != NULL) + { + if (sg_tTaskManage.task[idx].isUsed) + { + if (sg_tTaskManage.task[idx].timer) + { + sg_tTaskManage.task[idx].timer--; + + if (sg_tTaskManage.task[idx].timer == 0) + { + sg_tTaskManage.task[idx].timer = sg_tTaskManage.task[idx].itvTime; + sg_tTaskManage.task[idx].isRunnig = true; + } + } + } + + idx++; + } + + idx = 0; + + while (idx < CTASK_ISR_SUPPORT_NUM && sg_tTaskManage.isrTask[idx].pfnTaskHook != NULL) + { + if (sg_tTaskManage.isrTask[idx].timer) + { + sg_tTaskManage.isrTask[idx].timer--; + + if (sg_tTaskManage.isrTask[idx].timer == 0) + { + sg_tTaskManage.isrTask[idx].timer = sg_tTaskManage.isrTask[idx].itvTime; + sg_tTaskManage.isrTask[idx].pfnTaskHook(); + } + } + + idx++; + } +} + +#ifdef CTASK_USE_LOAD_RATE +/** + * @brief 获取 MCU 负载率 + * + * @note 通过该函数得到 MCU 负载率, 负载率越大, 实时性和响应性越差 + * @retval MCU 负载率.0-100% + */ +uint8_t cTASK_GetLoadRate(void) +{ + return sg_tTaskManage.mcuLoadRate; +} +#endif + +/** + * @brief 获取系统计时 + * + * @note 需等启动后才开始计时 + * @retval 系统计时, 单位ms + */ +uint32_t cTASK_GetSysTimer(void) +{ + return sg_tTaskManage.systimer; +} + diff --git a/Demo/STM32/HARDWARE/cTask/cTask.h b/Demo/STM32/HARDWARE/cTask/cTask.h new file mode 100644 index 0000000000000000000000000000000000000000..4c97d1b9dd6a2e6178c18fc1986ffa13d584d117 --- /dev/null +++ b/Demo/STM32/HARDWARE/cTask/cTask.h @@ -0,0 +1,44 @@ +/** + ********************************************************************************************************************** + * @file cTask.h + * @brief 该文件提供任务时间片论功能函数原型 + * @author const_zpc any question please send mail to const_zpc@163.com + * @date 2022-04-16 + ********************************************************************************************************************** + * + ********************************************************************************************************************** + */ + +/* Define to prevent recursive inclusion -----------------------------------------------------------------------------*/ +#ifndef __C_TASH_H +#define __C_TASH_H + +/* Includes ----------------------------------------------------------------------------------------------------------*/ +#include + +#ifndef NULL +#define NULL (void *)0 +#endif + +/* Exported types ----------------------------------------------------------------------------------------------------*/ + +typedef void (*TaskRunCB)(void); + +/* Exported constants ------------------------------------------------------------------------------------------------*/ +/* Exported macro ----------------------------------------------------------------------------------------------------*/ +/* Exported functions ------------------------------------------------------------------------------------------------*/ + +extern void cTASK_Init(void); +extern void cTASK_Remarks(void); +extern void cTASK_Start(void); + +extern void cTASK_Creat(TaskRunCB pfnTask, uint16_t time, uint8_t priority); +extern void cTASK_Destory(TaskRunCB pfnTask); + +extern void cTASK_IsrCreat(TaskRunCB pfnTask, uint16_t time); +extern void cTASK_IsrDestory(TaskRunCB pfnTask); + +extern uint8_t cTASK_GetLoadRate(void); +extern uint32_t cTASK_GetSysTimer(void); + +#endif // !__C_TASH_H diff --git a/Demo/STM32/HARDWARE/cTask/cTask_cfg.h b/Demo/STM32/HARDWARE/cTask/cTask_cfg.h new file mode 100644 index 0000000000000000000000000000000000000000..e1e123084f48416440d85ccdab17be000d7092ed --- /dev/null +++ b/Demo/STM32/HARDWARE/cTask/cTask_cfg.h @@ -0,0 +1,26 @@ +/** + ********************************************************************************************************************** + * @file cTask_cfg.h + * @brief 该文件提供任务时间片论功能配置 + * @author const_zpc any question please send mail to const_zpc@163.com + * @date 2022-04-16 + ********************************************************************************************************************** + * + ********************************************************************************************************************** + */ + +/* Define to prevent recursive inclusion -----------------------------------------------------------------------------*/ +#ifndef __C_TASH_CFG_H +#define __C_TASH_CFG_H + + +/* 支持的最大通用任务数目 */ +#define CTASK_SUPPORT_NUM 10 + +/* 支持的最大中断任务数目 */ +#define CTASK_ISR_SUPPORT_NUM 5 + +/* 定义使用负载率计算, 若定义, 则会占用一个通用任务和一个中断任务 */ +#define CTASK_USE_LOAD_RATE + +#endif // !__C_TASH_CFG_H diff --git a/Demo/STM32/HMI/src/hmi_camera.c b/Demo/STM32/HMI/src/hmi_camera.c index a1bf1c9b6cc4d82cfef8855b48117b3cc78e9a04..e528860eb623ea865989dbd79acfd87b4a18903e 100644 --- a/Demo/STM32/HMI/src/hmi_camera.c +++ b/Demo/STM32/HMI/src/hmi_camera.c @@ -54,7 +54,7 @@ void Hmi_CameraLoad(void) KEY_Register(IO_KEY_1, OnKeyFunCB); KEY_Register(IO_KEY_UP, OnKeyFunCB); - Menu_BingMenu(sg_CameraMenuTable, GET_MENU_NUM(sg_CameraMenuTable), ShowCameraMenu); + Menu_Bind(sg_CameraMenuTable, GET_MENU_NUM(sg_CameraMenuTable), ShowCameraMenu); } void Hmi_CameraExit(void) diff --git a/Demo/STM32/HMI/src/hmi_more_set.c b/Demo/STM32/HMI/src/hmi_more_set.c index cdf641ca2c17234ab247905d5e215446d0703a2f..a1377b0dc42b59354843897a1b35bd4a8ac1da4d 100644 --- a/Demo/STM32/HMI/src/hmi_more_set.c +++ b/Demo/STM32/HMI/src/hmi_more_set.c @@ -112,7 +112,7 @@ void Hmi_MoreSetLoad(void) KEY_Register(IO_KEY_1, OnKeyFunCB); KEY_Register(IO_KEY_UP, OnKeyFunCB); - Menu_BingMenu(sg_MoreSetMenuTable, GET_MENU_NUM(sg_MoreSetMenuTable), ShowMoreSetMenu); + Menu_Bind(sg_MoreSetMenuTable, GET_MENU_NUM(sg_MoreSetMenuTable), ShowMoreSetMenu); } void Hmi_MoreSetExit(void) diff --git a/Demo/STM32/HMI/src/hmi_set.c b/Demo/STM32/HMI/src/hmi_set.c index 892e9c3e3c96e45d41c51010fd5cc827a831323d..7a6a1e57f1cb7b7e52dbc27efda08a104c07fd53 100644 --- a/Demo/STM32/HMI/src/hmi_set.c +++ b/Demo/STM32/HMI/src/hmi_set.c @@ -87,7 +87,7 @@ void Hmi_SetLoad(void) KEY_Register(IO_KEY_1, OnKeyFunCB); KEY_Register(IO_KEY_UP, OnKeyFunCB); - Menu_BingMenu(sg_SetMenuTable, GET_MENU_NUM(sg_SetMenuTable), ShowSetMenu); + Menu_Bind(sg_SetMenuTable, GET_MENU_NUM(sg_SetMenuTable), ShowSetMenu); } void Hmi_SetExit(void) @@ -142,7 +142,7 @@ static void OnLanguageFunctionLoad(void) KEY_Register(IO_KEY_0, OnKeyFunLanguageCB); KEY_Register(IO_KEY_1, OnKeyFunLanguageCB); KEY_Register(IO_KEY_UP, OnKeyFunLanguageCB); - Menu_BingMenu(sg_LanguageMenuTable, GET_MENU_NUM(sg_LanguageMenuTable), NULL); + Menu_Bind(sg_LanguageMenuTable, GET_MENU_NUM(sg_LanguageMenuTable), NULL); } static void OnLanguageFunction(void) @@ -156,7 +156,7 @@ static void OnLanguageFunction(void) static void OnChangeChinese(void) { - Menu_SetEnglish(false); + Menu_EnableEnglish(false); // 切换完成自动退出 Menu_Exit(false); // 退出到语言设置界面 @@ -165,7 +165,7 @@ static void OnChangeChinese(void) static void OnChangeEnglish(void) { - Menu_SetEnglish(true); + Menu_EnableEnglish(true); // 切换完成自动退出 Menu_Exit(false); // 退出到语言设置界面 diff --git a/Demo/STM32/HMI/src/mainhmi.c b/Demo/STM32/HMI/src/mainhmi.c index 25602ca7a2cb1e2dff418bee514f2935f0687d96..fe42662f7eaa4f0a3ccdddda9933f4433c9cde1d 100644 --- a/Demo/STM32/HMI/src/mainhmi.c +++ b/Demo/STM32/HMI/src/mainhmi.c @@ -61,7 +61,7 @@ void Hmi_LoadMainHmi(void) KEY_Register(IO_KEY_1, OnKeyFunCB); KEY_Register(IO_KEY_UP, OnKeyFunCB); - Menu_BingMenu(sg_MainMenuTable, GET_MENU_NUM(sg_MainMenuTable), ShowMainMenu); + Menu_Bind(sg_MainMenuTable, GET_MENU_NUM(sg_MainMenuTable), ShowMainMenu); sg_isInit = true; } diff --git a/Demo/cmd_shell/hmi/src/hmi_camera.c b/Demo/cmd_shell/hmi/src/hmi_camera.c index b08e232fc072f5c1924f694b67d5b28c2c28e261..c27059d8a867b880e09a9c172a459289a008fdd1 100644 --- a/Demo/cmd_shell/hmi/src/hmi_camera.c +++ b/Demo/cmd_shell/hmi/src/hmi_camera.c @@ -53,7 +53,7 @@ void Hmi_CameraLoad(void) MOVETO(0, 0); printf("---鍔犺浇-----\n"); sg_isInit = true; - Menu_BingMenu(sg_CameraMenuTable, GET_MENU_NUM(sg_CameraMenuTable), ShowCameraMenu); + Menu_Bind(sg_CameraMenuTable, GET_MENU_NUM(sg_CameraMenuTable), ShowCameraMenu); } void Hmi_CameraExit(void) diff --git a/Demo/cmd_shell/hmi/src/hmi_more_set.c b/Demo/cmd_shell/hmi/src/hmi_more_set.c index f90c130c45bce0816107e38afe19c9bd2ecb1cc3..596966d0bc6ffbcb5ef9baff21f447a2e529537b 100644 --- a/Demo/cmd_shell/hmi/src/hmi_more_set.c +++ b/Demo/cmd_shell/hmi/src/hmi_more_set.c @@ -67,7 +67,7 @@ static void ShowMoreSetMenu(MenuShow_t *ptShowInfo) void Hmi_MoreSetLoad(void) { - Menu_BingMenu(sg_MoreSetMenuTable, GET_MENU_NUM(sg_MoreSetMenuTable), ShowMoreSetMenu); + Menu_Bind(sg_MoreSetMenuTable, GET_MENU_NUM(sg_MoreSetMenuTable), ShowMoreSetMenu); } void Hmi_MoreSetExit(void) diff --git a/Demo/cmd_shell/hmi/src/hmi_set.c b/Demo/cmd_shell/hmi/src/hmi_set.c index 7e645fd18be8e4513ff2d405f6f18f3e2b0ade5e..f2e8ac48d5488d0f333d0c0da7c710b0d6a3fe66 100644 --- a/Demo/cmd_shell/hmi/src/hmi_set.c +++ b/Demo/cmd_shell/hmi/src/hmi_set.c @@ -52,7 +52,7 @@ static void ShowSetMenu(MenuShow_t *ptShowInfo) void Hmi_SetLoad(void) { - Menu_BingMenu(sg_SetMenuTable, GET_MENU_NUM(sg_SetMenuTable), ShowSetMenu); + Menu_Bind(sg_SetMenuTable, GET_MENU_NUM(sg_SetMenuTable), ShowSetMenu); } void Hmi_SetExit(void) @@ -104,11 +104,11 @@ static void OnLanguageFunction(void) if (cmd == 0) { - Menu_SetEnglish(false); + Menu_EnableEnglish(false); } else { - Menu_SetEnglish(true); + Menu_EnableEnglish(true); } Menu_Exit(0); // 鍒囨崲鍚庤嚜鍔ㄩ鍑 diff --git a/Demo/cmd_shell/hmi/src/mainhmi.c b/Demo/cmd_shell/hmi/src/mainhmi.c index 9b9199ce7ce62f610ef4bf69ccea5831e43b9923..a2532255355bf43ea83f45e51831235ca43fc58a 100644 --- a/Demo/cmd_shell/hmi/src/mainhmi.c +++ b/Demo/cmd_shell/hmi/src/mainhmi.c @@ -89,7 +89,7 @@ static void ShowMainMenu(MenuShow_t *ptShowInfo) void Hmi_LoadMainHmi(void) { - Menu_BingMenu(sg_MainMenuTable, GET_MENU_NUM(sg_MainMenuTable), ShowMainMenu); + Menu_Bind(sg_MainMenuTable, GET_MENU_NUM(sg_MainMenuTable), ShowMainMenu); } void Hmi_MainTask(void) diff --git a/Menu/inc/menu.h b/Menu/inc/menu.h index 06f78b3ee84a4a53d0ef7f3c9d7539ebe001f7dd..806d5b4339c04f150d1bd5cc313bb0fe0ee53daa 100644 --- a/Menu/inc/menu.h +++ b/Menu/inc/menu.h @@ -3,8 +3,8 @@ * @file menu.h * @brief 璇ユ枃浠舵彁渚涜彍鍗曟鏋舵墍鏈夊嚱鏁板師鍨 * @author const_zpc any question please send mail to const_zpc@163.com - * @version V3.0.0 - * @date 2022-07-22 + * @version V3.1.0 + * @date 2022-09-04 ********************************************************************************************************************** * ********************************************************************************************************************** @@ -19,6 +19,10 @@ #include #include +#ifdef __cplusplus + extern "C" { +#endif + #ifndef NULL #define NULL 0 #endif @@ -37,9 +41,6 @@ /* 鑿滃崟鏀寔鐨勬渶澶ч夐」鏁扮洰 */ #define MENU_MAX_NUM 20 -/* 閫夋嫨椤硅缃笉鍙鐘舵佺殑鏈澶ф暟鐩 */ -#define MENU_MAX_DISABLE_VIEW_NUM 5 - /******************************************* 閰嶇疆椤 ********************************************************************/ @@ -63,8 +64,6 @@ typedef struct char *pszDesc; /*!< 褰撳墠鑿滃崟鐨勫瓧绗︿覆鎻忚堪 */ - bool itemsView[MENU_MAX_NUM]; /*!< 褰撳墠鑿滃崟涓墍鏈夐夐」鐨勫彲瑙嗙姸鎬 */ - char *pszItemsDesc[MENU_MAX_NUM]; /*!< 褰撳墠鑿滃崟涓墍鏈夐夐」鐨勫瓧绗︿覆鎻忚堪 */ void *pItemsExData[MENU_MAX_NUM]; /*!< 褰撳墠鑿滃崟涓墍鏈夐夐」娉ㄥ唽鏃剁殑鎵╁睍鏁版嵁 */ @@ -118,12 +117,11 @@ typedef struct extern int Menu_Init(MainMenuCfg_t *pMainMenu); extern int Menu_DeInit(void); -extern int Menu_BingMenu(MenuList_t *pMenuList, menusize_t menuNum, ShowMenuCallFun_f pfnShowMenuFun); +extern int Menu_Bind(MenuList_t *pMenuList, menusize_t menuNum, ShowMenuCallFun_f pfnShowMenuFun); /* 鑿滃崟鍔熻兘璁剧疆 */ -extern int Menu_SetEnglish(bool isEnable); -extern int Menu_DisableViewMenu(MenuItem_t *pMenu, bool isDisableView); +extern int Menu_EnableEnglish(bool isEnable); /* 鑿滃崟閫夐」鏄剧ず鏃堕渶瑕佷娇鐢ㄧ殑鍔熻兘鎵╁睍鍑芥暟 */ @@ -149,4 +147,8 @@ extern int Menu_ShortcutEnter(bool isAbsolute, uint8_t deep, ...); extern int Menu_Task(void); +#ifdef __cplusplus + } +#endif + #endif // MENU_H diff --git a/Menu/src/menu.c b/Menu/src/menu.c index 2be354bfbfb127e54cf6d7208bd1d510c378caab..f84938e30e41673ab940b4b33c9e01566ef67c36 100644 --- a/Menu/src/menu.c +++ b/Menu/src/menu.c @@ -3,8 +3,8 @@ * @file menu.c * @brief 璇ユ枃浠舵彁渚涜彍鍗曟鏋跺姛鑳 * @author const_zpc any question please send mail to const_zpc@163.com - * @version V3.0.0 - * @date 2022-07-22 + * @version V3.1.0 + * @date 2022-09-04 * * @details 鍔熻兘璇︾粏璇存槑锛 * + 鑿滃崟鍒濆鍖栧嚱鏁 @@ -53,8 +53,7 @@ typedef struct MenuCtrl typedef struct { MenuCtrl_t *pMenuCtrl; /*!< 褰撳墠鑿滃崟鎺у埗澶勭悊 */ - bool isEnglish; /*!< 鏄惁鍒囨崲鎴愯嫳鏂 */ - MenuItem_t *pDisableViewMenuList[MENU_MAX_DISABLE_VIEW_NUM];/*!< 鍙鐘舵佺姝㈤夋嫨椤瑰垪琛 */ + bool isEnglish; /*!< 鏄惁浣胯兘鑻辨枃 */ }MenuManage_t; /* Private define ----------------------------------------------------------------------------------------------------*/ @@ -206,7 +205,7 @@ int Menu_DeInit(void) * @param pfnShowMenuFun 鏂扮殑鑿滃崟鍒楄〃鏄剧ず鏁堟灉鍥炶皟鍑芥暟, 涓篘ULL鍒欏欢缁笂绾ц彍鍗曟樉绀烘晥鏋 * @return int */ -int Menu_BingMenu(MenuList_t *pMenuList, menusize_t menuNum, ShowMenuCallFun_f pfnShowMenuFun) +int Menu_Bind(MenuList_t *pMenuList, menusize_t menuNum, ShowMenuCallFun_f pfnShowMenuFun) { if (sg_tMenuManage.pMenuCtrl == NULL) { @@ -240,72 +239,17 @@ bool Menu_IsEnglish(void) } /** - * @brief 璁剧疆鑻辨枃鏄剧ず + * @brief 浣胯兘鑻辨枃鏄剧ず * * @param[in] isEnable 浣胯兘鑻辨枃鏄剧ず * @return 0,鎴愬姛; -1,澶辫触 */ -int Menu_SetEnglish(bool isEnable) +int Menu_EnableEnglish(bool isEnable) { sg_tMenuManage.isEnglish = isEnable; return 0; } -/** - * @brief 璁剧疆绂佹鏄剧ず鐨勮彍鍗曢」 - * - * @param[in] pMenu 鑿滃崟椤 - * @param[in] isDisableView - * @return 0,鎴愬姛; -1,澶辫触 - */ -int Menu_DisableViewMenu(MenuItem_t *pMenu, bool isDisableView) -{ - int i, idx = 0; - - if (isDisableView) - { - while (idx < MENU_MAX_DISABLE_VIEW_NUM && sg_tMenuManage.pDisableViewMenuList[idx++] != NULL) - { - if (sg_tMenuManage.pDisableViewMenuList[idx++] == NULL) - { - sg_tMenuManage.pDisableViewMenuList[idx] = pMenu; - break; - } - - idx++; - } - - if (idx == MENU_MAX_DISABLE_VIEW_NUM) - { - return -1; - } - } - else - { - while (idx < MENU_MAX_DISABLE_VIEW_NUM && sg_tMenuManage.pDisableViewMenuList[idx] != NULL) - { - if (sg_tMenuManage.pDisableViewMenuList[idx] == pMenu) - { - for (i = idx; i < MENU_MAX_DISABLE_VIEW_NUM; i++) - { - if (i == MENU_MAX_DISABLE_VIEW_NUM - 1) - { - sg_tMenuManage.pDisableViewMenuList[i] = NULL; - } - else - { - sg_tMenuManage.pDisableViewMenuList[i] = sg_tMenuManage.pDisableViewMenuList[i + 1]; - } - } - } - - idx++; - } - } - - return 0; -} - /** * @brief 澶嶄綅鑿滃崟, 鍥炲埌涓昏彍鍗曠晫闈 * @@ -547,21 +491,6 @@ int Menu_ShortcutEnter(bool isAbsolute, uint8_t deep, ...) #endif -static bool IsMenuVeiw(MenuList_t *pMenu) -{ - int i; - - for (i = 0; i < MENU_MAX_DISABLE_VIEW_NUM; i++) - { - if (sg_tMenuManage.pDisableViewMenuList[i] == pMenu) - { - return false; - } - } - - return true; -} - /** * @brief 闄愬埗褰撳墠鑿滃崟鐣岄潰鏈澶氭樉绀虹殑鑿滃崟鏁扮洰 * @@ -632,7 +561,6 @@ int Menu_QueryParentMenu(MenuShow_t *ptMenuShow, uint8_t level) for (i = 0; i < ptMenuShow->itemsNum && i < MENU_MAX_NUM; i++) { - ptMenuShow->itemsView[i] = IsMenuVeiw(&pMenu[i]); ptMenuShow->pszItemsDesc[i] = (char *)pMenu[i].pszEnDesc; ptMenuShow->pItemsExData[i] = pMenu[i].pExtendData; } @@ -643,7 +571,6 @@ int Menu_QueryParentMenu(MenuShow_t *ptMenuShow, uint8_t level) for (i = 0; i < ptMenuShow->itemsNum && i < MENU_MAX_NUM; i++) { - ptMenuShow->itemsView[i] = IsMenuVeiw(&pMenu[i]); ptMenuShow->pszItemsDesc[i] = (char *)pMenu[i].pszDesc; ptMenuShow->pItemsExData[i] = pMenu[i].pExtendData; } @@ -690,7 +617,6 @@ int Menu_Task(void) for (i = 0; i < tMenuShow.itemsNum && i < MENU_MAX_NUM; i++) { - tMenuShow.itemsView[i] = IsMenuVeiw(&pMenuList[i]); tMenuShow.pszItemsDesc[i] = (char *)pMenuList[i].pszEnDesc; tMenuShow.pItemsExData[i] = pMenuList[i].pExtendData; } @@ -701,7 +627,6 @@ int Menu_Task(void) for (i = 0; i < tMenuShow.itemsNum && i < MENU_MAX_NUM; i++) { - tMenuShow.itemsView[i] = IsMenuVeiw(&pMenuList[i]); tMenuShow.pszItemsDesc[i] = (char *)pMenuList[i].pszDesc; tMenuShow.pItemsExData[i] = pMenuList[i].pExtendData; }