优化整定一版

This commit is contained in:
冯佳
2025-12-18 23:56:36 +08:00
parent e5eaf2172f
commit e36b4e0e27
16 changed files with 2619 additions and 504 deletions

View File

@ -5,68 +5,58 @@
#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 菜单核心上下文(全局,仅内部访问
*/
extern MenuCoreCtx s_menu_core_ctx;
/**
* @brief 参数管理上下文(启用参数时有效,全局)
* @brief 参数管理上下文(启用参数时有效
*/
#if MENU_CONFIG_ENABLE_PARAM
typedef struct {
uint16_t id; ///< 参数ID
MenuParamType type; ///< 参数类型
float min_val; ///< 最小值
float max_val; ///< 最大值
float scale; ///< 缩放因子
union { ///< 共用体:减少内存占用
int8_t i8;
uint8_t u8;
int16_t i16;
uint16_t u16;
int32_t i32;
uint32_t u32;
float f;
} value; ///< 当前值
union { ///< 默认值
int8_t i8;
uint8_t u8;
int16_t i16;
uint16_t u16;
int32_t i32;
uint32_t u32;
float f;
} default_val;
bool is_registered; ///< 是否已注册
} MenuParam;
extern MenuParam s_menu_params[MENU_CONFIG_MAX_PARAMS];
MenuParam params[MENU_CONFIG_MAX_PARAMS]; ///< 参数数组
uint16_t count; ///< 已注册参数数量
} MenuParamCtx;
#endif // MENU_CONFIG_ENABLE_PARAM
/**
* @brief 多语言上下文(启用多语言时有效,全局
* @brief 多语言上下文(启用多语言时有效)
*/
#if MENU_CONFIG_ENABLE_LANG
typedef struct {
const char* str; ///< 语言字符串
uint16_t str_id; ///< 字符串ID
uint8_t lang_id; ///< 语言ID
} MenuLangStr;
extern MenuLangStr s_menu_lang_strs[MENU_CONFIG_MAX_NODES * MENU_CONFIG_MAX_LANGS];
extern uint8_t s_current_lang_id;
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映射时有效,全局
* @brief Modbus映射上下文启用Modbus映射时有效
*/
#if MENU_CONFIG_ENABLE_MODBUS_MAP
extern ModbusMapInternal s_menu_modbus_maps[MENU_CONFIG_MAX_MODBUS_MAPS];
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