Files
smart-home-control-system/include/shs/menu.h
T
sambu 578a770737 chore(M0): 建立 CLion/CMake 工程骨架与测试框架
- CMake 多目标工程:shs_core 静态库 + smart_home 可执行 + shs_tests 测试
- CMakePresets.json:debug/release/asan/coverage 四个预设(debug 告警即错误)
- 自研零依赖测试框架 tests/framework/test_framework.h + 运行器(套件过滤、CTest 集成)
- 工具:tools/header_check.sh 头文件独立编译检查(接口冻结门)
- 已实现公共层:errors / string_utils / num_utils,main 启动自检
- 实测:debug 预设 0 告警、ctest 3/3 通过(45 项断言)
2026-09-14 19:34:18 +08:00

51 lines
2.1 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.
/**
* @file menu.h
* @brief 控制台菜单:渲染、选择与命令分发
*
* 教材对应:项目一(输出格式)·项目三 任务五「switch 分支——主菜单功能选择与跳转」·
* 项目四(输入校验循环)·项目七(函数指针表)
*/
#ifndef SHS_MENU_H
#define SHS_MENU_H
#include "shs/common.h"
#include "shs/errors.h"
#include "shs/system.h"
/** 菜单项:编号 + 标题 + 处理函数(项目七 函数指针) */
typedef struct {
int id; /**< 菜单编号 */
const char *label; /**< 菜单标题 */
shs_err_t (*action)(SmartHomeSystem *sys); /**< 处理函数;项目十的集成入口 */
const char *chapter; /**< 对应教材项目(知识点溯源) */
} MenuItem;
/** 主菜单项数量 */
int menu_item_count(void);
/** 取第 index 个菜单项(越界返回 NULL) */
const MenuItem *menu_item_at(int index);
/** 渲染主菜单文本 */
shs_err_t menu_render(const SmartHomeSystem *sys, char *buf, size_t buf_size);
/** 按编号分发(switch 演示),返回处理函数的执行结果 */
shs_err_t menu_dispatch(SmartHomeSystem *sys, int choice);
/** 读取一行用户选择并转成整数(项目四 do-while + 输入校验) */
int menu_read_choice(const char *prompt);
/* 各菜单项处理函数(供菜单表与测试直接调用) */
shs_err_t menu_action_list_devices(SmartHomeSystem *sys);
shs_err_t menu_action_toggle_device(SmartHomeSystem *sys);
shs_err_t menu_action_dim_light(SmartHomeSystem *sys);
shs_err_t menu_action_lock(SmartHomeSystem *sys);
shs_err_t menu_action_sensors(SmartHomeSystem *sys);
shs_err_t menu_action_ac_mode(SmartHomeSystem *sys);
shs_err_t menu_action_scene(SmartHomeSystem *sys);
shs_err_t menu_action_schedule(SmartHomeSystem *sys);
shs_err_t menu_action_report(SmartHomeSystem *sys);
shs_err_t menu_action_logs(SmartHomeSystem *sys);
shs_err_t menu_action_protocol(SmartHomeSystem *sys);
shs_err_t menu_action_save_load(SmartHomeSystem *sys);
shs_err_t menu_action_self_test(SmartHomeSystem *sys);
shs_err_t menu_action_about(SmartHomeSystem *sys);
#endif /* SHS_MENU_H */