Files
DTU-HMI/src/menu.h

57 lines
1.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#ifndef PC_HMI_MENU_H
#define PC_HMI_MENU_H
/*
* PC 端菜单模拟环境
*
* 目标:
* - 用纯 C 语言在控制台模拟嵌入式 HMI 的菜单逻辑
* - 键值映射W/S/A/D/Enter/Esc → 上/下/左/右/确认/退出
* - 结构设计尽量贴近原工程的 g_tMenuCtrl / Menu_Route / Menu_Show_Proc
*/
#include <stdint.h>
typedef struct MenuItem MenuItem;
struct MenuItem {
const char *name; /* 菜单名称 */
const char *tip; /* 底部提示信息 */
MenuItem *higher; /* 上级菜单 */
MenuItem *lower; /* 下级第一个菜单 */
MenuItem *before; /* 同级上一个 */
MenuItem *behind; /* 同级下一个 */
uint8_t level; /* 菜单级别0/1/2/... */
uint8_t pos; /* 在同级菜单中的序号(从 0 开始) */
};
typedef struct {
MenuItem *head0; /* 0 级菜单头结点 */
MenuItem *current; /* 当前选中的菜单结点 */
} MenuCtrl;
/* 初始化一棵简单的测试菜单树 */
void Menu_InitPC(MenuCtrl *ctrl);
/* 处理一帧输入,并在控制台绘制菜单 */
void Menu_LoopStep(MenuCtrl *ctrl, int key);
/* 键值定义:与嵌入式逻辑对应的抽象键 */
enum {
KEY_NONE = 0,
KEY_U,
KEY_D,
KEY_L,
KEY_R,
KEY_ENT,
KEY_ESC,
};
/* 从键盘输入字符映射到 KEY_* 抽象键W/S/A/D/Enter/Esc */
int Menu_MapKey(int ch);
#endif /* PC_HMI_MENU_H */