Files
menu/internal/menu_data.h
2025-12-18 23:56:36 +08:00

62 lines
1.9 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_data.h
* @brief 菜单组件共享全局变量(用户无需关心,内部仅通过接口访问)
*/
#ifndef MENU_DATA_H
#define MENU_DATA_H
#include "../api/menu.h"
#include "menu_core.h"
#include "menu_modbus.h"
#include "menu_param.h"
/************************** 共享上下文结构(替代全局变量) **************************/
/**
* @brief 参数管理上下文(启用参数时有效)
*/
#if MENU_CONFIG_ENABLE_PARAM
typedef struct {
MenuParam params[MENU_CONFIG_MAX_PARAMS]; ///< 参数数组
uint16_t count; ///< 已注册参数数量
} MenuParamCtx;
#endif // MENU_CONFIG_ENABLE_PARAM
/**
* @brief 多语言上下文(启用多语言时有效)
*/
#if MENU_CONFIG_ENABLE_LANG
typedef struct {
MenuLangStr strs[MENU_CONFIG_MAX_NODES * MENU_CONFIG_MAX_LANGS]; ///< 语言字符串数组
uint8_t count; ///< 已注册字符串数量
uint8_t current_lang_id; ///< 当前语言ID
} MenuLangCtx;
#endif // MENU_CONFIG_ENABLE_LANG
/**
* @brief Modbus映射上下文启用Modbus映射时有效
*/
#if MENU_CONFIG_ENABLE_MODBUS_MAP
typedef struct {
ModbusMapInternal maps[MENU_CONFIG_MAX_MODBUS_MAPS]; ///< Modbus映射数组
uint16_t count; ///< 已注册映射数量
} MenuModbusCtx;
#endif // MENU_CONFIG_ENABLE_MODBUS_MAP
/**
* @brief 菜单组件全局上下文(替代所有全局变量)
*/
struct MenuGlobalCtx {
MenuCoreCtx core; ///< 核心上下文
#if MENU_CONFIG_ENABLE_PARAM
MenuParamCtx param; ///< 参数上下文
#endif
#if MENU_CONFIG_ENABLE_LANG
MenuLangCtx lang; ///< 多语言上下文
#endif
#if MENU_CONFIG_ENABLE_MODBUS_MAP
MenuModbusCtx modbus; ///< Modbus映射上下文
#endif
bool is_initialized; ///< 是否已初始化
};
#endif // MENU_DATA_H