原始版本
This commit is contained in:
125
Menu/include/menu_pack.h
Normal file
125
Menu/include/menu_pack.h
Normal file
@ -0,0 +1,125 @@
|
||||
#ifndef _MENU_PACK_HANDLER_H_
|
||||
#define _MENU_PACK_HANDLER_H_
|
||||
|
||||
#include <board.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "menu_pack_load.h"
|
||||
#include "menu_pack_key.h"
|
||||
|
||||
#define DEFAULT_EMPTY_STRING " "
|
||||
#define DEFAULT_ENGINEER_PASSWORD 2008
|
||||
|
||||
#ifndef ARRAY_SIZE
|
||||
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#endif
|
||||
|
||||
typedef enum EMenuPackCommand
|
||||
{
|
||||
MENU_PACK_KEY_PRESS = 0,
|
||||
MENU_PACK_BEFORE_ENTER_SUB,
|
||||
MENU_PACK_AFTER_EXIT_SUB
|
||||
} EMenuPackCommand;
|
||||
|
||||
typedef struct TMenuPackLevel
|
||||
{
|
||||
int8_t menu_index;
|
||||
int8_t item_select;
|
||||
int8_t item_select_adjust;
|
||||
int8_t item_display_start;
|
||||
int8_t select_row;
|
||||
} TMenuPackLevel;
|
||||
|
||||
typedef struct TCommRegisterInfo
|
||||
{
|
||||
uint32_t reg_addr;
|
||||
uint8_t reg_count;
|
||||
int8_t bit;
|
||||
bool is_float;
|
||||
bool is_big_endian;
|
||||
} TCommRegisterInfo;
|
||||
|
||||
int32_t MenuPack_SearchCommIndex(TMenuPackFileInfo *pinfo, TCommRegisterInfo *pstcCommReg);
|
||||
void MenuPack_ProcessFunc(EMenuPackCommand cmd, const struct TMenuItemInfo *pmenu_info, int key);
|
||||
void MenuPack_DispMenu(const TMenuPackFileInfo *pinfo);
|
||||
void MenuPack_ModifyMenu(const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info);
|
||||
void MenuPack_ProcessMenu(const TMenuPackFileInfo *pinfo, int key);
|
||||
|
||||
void MenuPack_ToUpperLayer(const TMenuPackFileInfo *pinfo, int key);
|
||||
void MenuPack_EnterMainMenu(const TMenuPackFileInfo *pinfo);
|
||||
void MenuPack_QuitToMainMenu(const TMenuPackFileInfo *pinfo);
|
||||
|
||||
|
||||
bool MenuPack_ModifyDefault(int modify_row, int modify_col, char *buf, const char *max_format, const char *min_format);
|
||||
int MenuPack_GetSelectItemIndex(const TMenuPackFileInfo *pinfo);
|
||||
const struct TMenuDescriptionItem* MenuPack_SearchMenuDescription(const TMenuPackFileInfo *pinfo);
|
||||
const struct TMenuDescriptionItem *MenuPack_MenuIndexDescription(const TMenuPackFileInfo *pinfo, int menu_index);
|
||||
|
||||
TMenuPackLevel *MenuPack_GetActiveLevel(const TMenuPackFileInfo *pinfo);
|
||||
const char *MenuPack_GetStringFromOffset(const TMenuPackFileInfo *pinfo, uint16_t offset);
|
||||
TCommRegisterInfo MenuPack_UpdateCommInfo(const char *preg_addr_key_str);
|
||||
|
||||
const struct TMenuItemInfo *MenuPack_GetSelectItem(const TMenuPackFileInfo *pinfo);
|
||||
|
||||
const char *MenuPack_GetDisplayAliasString(const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
void MenuPack_GetDisplayNormalString(const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off, char *pbuf, int buf_size);
|
||||
|
||||
int MenuPack_SearchAliasIndex(const TMenuPackFileInfo *pinfo, const char *alias_name);
|
||||
|
||||
const char *MenuPack_GetStringAlias(const TMenuPackFileInfo *pinfo, int alias_index, int16_t alias_value);
|
||||
const char *MenuPack_MenuItemGetStringAlias(const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int16_t alias_value);
|
||||
|
||||
int MenuPack_SearchMenuIndex(const TMenuPackFileInfo *pinfo, const char *pstr_menu_name);
|
||||
void MenuPack_EnterSubMenu(int sub_menu_index);
|
||||
|
||||
void MenuPack_DisplayItem(int disp_row, int disp_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
int MenuPack_ModifyItem(int modify_row, int modify_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
|
||||
void MenuPack_DisplayAlias(int disp_row, int disp_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
int MenuPack_ModifyAlias(int modify_row, int modify_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
|
||||
void MenuPack_DisplayNormal(int disp_row, int disp_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
int MenuPack_ModifyNormal(int modify_row, int modify_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int reg_addr_off);
|
||||
void MenuPack_SelectItem(const TMenuPackFileInfo *pinfo, int item_select_row);
|
||||
void MenuPack_ExecuteSelectItem(const TMenuPackFileInfo *pinfo);
|
||||
//weak function
|
||||
|
||||
void MenuPack_ModifyBufCallBack(char *buf);
|
||||
|
||||
const char *MenuPack_GetDisplayUnit(const char *punit, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info);
|
||||
bool MenuPack_CheckVisible(const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info);
|
||||
|
||||
int MenuPack_RegisterValueRead(TCommRegisterInfo *pstcCommReg, void *pbuf, int max_buf_items);
|
||||
bool MenuPack_RegisterValueWrite(TCommRegisterInfo *pstcCommReg, void *pdata);
|
||||
|
||||
void MenuPack_DisplayFlush(void);
|
||||
void MenuPack_Clear(void);
|
||||
void MenuPack_CommReinit(void);
|
||||
void MenuPack_DisplayModifyString(int modify_row, int modify_col, const char *str, int sel_bit);
|
||||
void MenuPack_AfterDisplayMenu(const TMenuPackFileInfo *pinfo, const char *pstr_action, int menu_index);
|
||||
void MenuPack_BeforeDisplayMenu(const TMenuPackFileInfo *pinfo, const char *pstr_action, int menu_index);
|
||||
|
||||
void MenuPack_DisplayDefaultAction(int disp_row,
|
||||
int disp_col,
|
||||
const TMenuPackFileInfo *pinfo,
|
||||
const struct TMenuItemInfo *pmenu_info,
|
||||
const char *pstr_action);
|
||||
|
||||
//pmenu_info may be NULL
|
||||
void MenuPack_BrotherMenuEnterCallBack(const TMenuPackFileInfo *pinfo, int brother_menu_index, int key);
|
||||
|
||||
void MenuPack_MenuItemDisplay(const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info, int disp_line);
|
||||
bool MenuPack_ActionItemModify(int modify_row, int modify_col, const TMenuPackFileInfo *pinfo, const struct TMenuItemInfo *pmenu_info);
|
||||
void MenuPack_MenuActionProcess(const TMenuPackFileInfo *pinfo, const char *pstr_action, int menu_index, int *pkey);
|
||||
bool MenuPack_InputPassword(const TMenuPackFileInfo *pinfo, uint16_t *pvalue_password);
|
||||
bool MenuPack_CheckPasswordSuccess(const TMenuPackFileInfo *pinfo);
|
||||
|
||||
int COMM_ReadRegisters(uint16_t *resp, uint16_t reg_addr, uint16_t range);
|
||||
bool COMM_WriteRegisters(uint16_t *recv, uint16_t reg_addr, uint16_t range);
|
||||
int COMM_ReadBitRegisters(uint8_t *pbuf, uint16_t reg_addr, uint16_t range);
|
||||
bool COMM_WriteBitRegisters(uint8_t *recv, uint16_t reg_addr, uint16_t range);
|
||||
|
||||
#endif /* _MAIN_H_ */
|
||||
42
Menu/include/menu_pack_key.h
Normal file
42
Menu/include/menu_pack_key.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef MENU_PACK_KEY_H
|
||||
#define MENU_PACK_KEY_H
|
||||
|
||||
|
||||
typedef enum EGUIKey
|
||||
{
|
||||
MENU_PACK_KEY_NULL = 0,
|
||||
MENU_PACK_KEY_BACKSPACE =8, /* ASCII: BACKSPACE Crtl-H */
|
||||
MENU_PACK_KEY_TAB =9, /* ASCII: TAB Crtl-I */
|
||||
MENU_PACK_KEY_BACKTAB =10,
|
||||
MENU_PACK_KEY_ENTER =13, /* ASCII: ENTER Crtl-M */
|
||||
MENU_PACK_KEY_LEFT =16,
|
||||
MENU_PACK_KEY_UP =17,
|
||||
MENU_PACK_KEY_RIGHT =18,
|
||||
MENU_PACK_KEY_DOWN =19,
|
||||
MENU_PACK_KEY_HOME =23,
|
||||
MENU_PACK_KEY_END =24,
|
||||
MENU_PACK_KEY_SHIFT =25,
|
||||
MENU_PACK_KEY_CONTROL =26,
|
||||
MENU_PACK_KEY_ESCAPE =27, /* ASCII: ESCAPE 0x1b */
|
||||
MENU_PACK_KEY_INSERT =29,
|
||||
MENU_PACK_KEY_DELETE =30,
|
||||
MENU_PACK_KEY_SPACE =32,
|
||||
MENU_PACK_KEY_PGUP =33,
|
||||
MENU_PACK_KEY_PGDOWN =34,
|
||||
MENU_PACK_KEY_RESET_OR_UP =35,
|
||||
MENU_PACK_KEY_ENTER_OR_RIGHT =37,
|
||||
MENU_PACK_KEY_DOT = '.',
|
||||
MENU_PACK_KEY_0 =0x30,
|
||||
MENU_PACK_KEY_1 =0x31,
|
||||
MENU_PACK_KEY_2 =0x32,
|
||||
MENU_PACK_KEY_3 =0x33,
|
||||
MENU_PACK_KEY_4 =0x34,
|
||||
MENU_PACK_KEY_5 =0x35,
|
||||
MENU_PACK_KEY_6 =0x36,
|
||||
MENU_PACK_KEY_7 =0x37,
|
||||
MENU_PACK_KEY_8 =0x38,
|
||||
MENU_PACK_KEY_9 =0x39,
|
||||
} EGUIKey;
|
||||
|
||||
|
||||
#endif
|
||||
236
Menu/include/menu_pack_load.h
Normal file
236
Menu/include/menu_pack_load.h
Normal file
@ -0,0 +1,236 @@
|
||||
#ifndef _MENU_PACK_LOAD_H_
|
||||
#define _MENU_PACK_LOAD_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef enum EMenuItemInfoType
|
||||
{
|
||||
MENU_ITEM_NORMAL,
|
||||
MENU_ITEM_ALIAS,
|
||||
MENU_ITEM_SUB_MENU,
|
||||
} EMenuItemInfoType;
|
||||
|
||||
struct TMenuDescriptionItem
|
||||
{
|
||||
uint16_t menu_index : 8;
|
||||
uint16_t next_menu_index : 8;
|
||||
uint16_t prev_menu_index : 8;
|
||||
uint16_t display_page : 8;
|
||||
uint16_t max_menu_item : 8;
|
||||
uint16_t action_index : 8;
|
||||
uint16_t menu_name_str_offset;
|
||||
uint16_t description_str_off;
|
||||
uint16_t display_menu_index : 8;
|
||||
uint16_t rsv : 8;
|
||||
};
|
||||
|
||||
struct TMenuDescriptionInfo
|
||||
{
|
||||
uint32_t item_count;
|
||||
struct TMenuDescriptionItem items[1];
|
||||
};
|
||||
|
||||
typedef struct TMenuItemInfoTypeCommon
|
||||
{
|
||||
uint16_t type : 2;
|
||||
uint16_t rsv : 14;
|
||||
uint16_t : 8;
|
||||
uint16_t action_index : 8;
|
||||
} TMenuItemInfoTypeCommon;
|
||||
|
||||
typedef struct TMenuItemInfoTypeAlias
|
||||
{
|
||||
uint16_t type : 2;
|
||||
uint16_t rsv : 14;
|
||||
uint16_t alias_index : 8;
|
||||
uint16_t action_index : 8;
|
||||
} TMenuItemInfoTypeAlias;
|
||||
|
||||
typedef struct TMenuItemInfoTypeNormal
|
||||
{
|
||||
uint32_t type : 2;
|
||||
uint32_t scale_format_index : 8;
|
||||
uint32_t limit_index : 8;
|
||||
uint32_t unit_index : 6;
|
||||
uint32_t action_index : 8;
|
||||
} TMenuItemInfoTypeNormal;
|
||||
|
||||
typedef struct TMenuItemInfoTypeSubMenu
|
||||
{
|
||||
uint16_t type : 2;
|
||||
uint16_t rsv : 14;
|
||||
uint16_t sub_menu_index : 8;
|
||||
uint16_t action_index : 8;
|
||||
} TMenuItemInfoTypeSubMenu;
|
||||
|
||||
typedef enum EMenuProperty
|
||||
{
|
||||
MENU_PROP_READ_ONLY = 0,
|
||||
MENU_PROP_USER,
|
||||
MENU_PROP_ENGINEER,
|
||||
} EMenuProperty;
|
||||
|
||||
//每个菜单项12字节
|
||||
struct TMenuItemInfo
|
||||
{
|
||||
uint16_t comm_str_offset;
|
||||
uint16_t name_offset;
|
||||
uint16_t comm_group_index : 8;
|
||||
uint16_t menu_property : 8; //EMenuProperty
|
||||
uint16_t remap_addr;
|
||||
union {
|
||||
TMenuItemInfoTypeCommon common;
|
||||
TMenuItemInfoTypeAlias alias;
|
||||
TMenuItemInfoTypeNormal normal;
|
||||
TMenuItemInfoTypeSubMenu sub_menu;
|
||||
} info;
|
||||
};
|
||||
|
||||
struct TMenuPack2
|
||||
{
|
||||
uint32_t item_count;
|
||||
struct TMenuItemInfo items[1];
|
||||
};
|
||||
|
||||
struct TMenuPackItem
|
||||
{
|
||||
uint16_t menu_start_index;
|
||||
uint16_t menu_items;
|
||||
};
|
||||
|
||||
struct TMenuPack
|
||||
{
|
||||
uint16_t item_count;
|
||||
uint16_t top_menu_index;
|
||||
struct TMenuPackItem items[1];
|
||||
};
|
||||
|
||||
struct TCommItem
|
||||
{
|
||||
uint32_t reg_start;
|
||||
uint16_t reg_count;
|
||||
uint16_t cycle_time;
|
||||
uint16_t mqtt_menu_index;
|
||||
uint16_t rsv[1];
|
||||
};
|
||||
|
||||
struct TCommPack
|
||||
{
|
||||
uint32_t item_count;
|
||||
struct TCommItem items[1];
|
||||
};
|
||||
|
||||
struct TValueLimitItem
|
||||
{
|
||||
uint16_t min_string_off;
|
||||
uint16_t max_string_off;
|
||||
};
|
||||
|
||||
struct TValueLimitTable
|
||||
{
|
||||
uint32_t limit_count;
|
||||
struct TValueLimitItem items[1];
|
||||
};
|
||||
|
||||
struct TAliasTable2Item
|
||||
{
|
||||
int16_t value;
|
||||
uint16_t alias_string_off;
|
||||
};
|
||||
|
||||
struct TAliasPack2
|
||||
{
|
||||
uint32_t table_count;
|
||||
struct TAliasTable2Item items[1];
|
||||
};
|
||||
|
||||
struct TAliasTableItem
|
||||
{
|
||||
int16_t start_index;
|
||||
uint16_t alias_item_nums;
|
||||
};
|
||||
|
||||
struct TAliasPack
|
||||
{
|
||||
uint32_t table_count;
|
||||
struct TAliasTableItem items[1];
|
||||
};
|
||||
|
||||
struct TUnitPack
|
||||
{
|
||||
uint32_t unit_count;
|
||||
uint16_t uint_string_off[1];
|
||||
};
|
||||
|
||||
struct TActionPack
|
||||
{
|
||||
uint32_t action_count;
|
||||
uint16_t action_string_off[1];
|
||||
};
|
||||
|
||||
struct TScaleFormatItem
|
||||
{
|
||||
uint16_t scale_string_off;
|
||||
uint16_t format_string_off;
|
||||
};
|
||||
|
||||
struct TScaleFormatPack
|
||||
{
|
||||
uint32_t scale_format_count;
|
||||
struct TScaleFormatItem items[1];
|
||||
};
|
||||
|
||||
struct TStringPack
|
||||
{
|
||||
uint32_t table_string_size;
|
||||
uint8_t table_string[1];
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char file_version[8];
|
||||
uint32_t header_size;
|
||||
uint32_t menu_pack_offset;
|
||||
uint32_t menu_pack2_offset;
|
||||
uint32_t menu_description_offset;
|
||||
uint32_t alias_pack_offset;
|
||||
uint32_t alias_pack2_offset;
|
||||
uint32_t scale_format_table_offset;
|
||||
uint32_t unit_table_offset;
|
||||
uint32_t limit_table_offset;
|
||||
uint32_t comm_table_offset;
|
||||
uint32_t action_table_offset;
|
||||
uint32_t string_table_offset;
|
||||
uint32_t rsv[3];
|
||||
uint32_t data_size;
|
||||
uint32_t data_crc;
|
||||
uint32_t header_crc;
|
||||
} TMenuPackFileHead;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const TMenuPackFileHead *pstcPackHeader;
|
||||
struct TMenuPack *pastcMenuPack;
|
||||
struct TMenuPack2 *pastMenuPack2;
|
||||
struct TMenuDescriptionInfo *pastcMenuDescriptionInfo;
|
||||
struct TAliasPack *pastcAliasPack;
|
||||
struct TAliasPack2 *pastcAliasPack2;
|
||||
struct TUnitPack *pastcUnitPack;
|
||||
struct TScaleFormatPack *pastcFormatPack;
|
||||
struct TValueLimitTable *pastcLimitPack;
|
||||
struct TCommPack *pastcCommPack;
|
||||
struct TActionPack *pastcActionPack;
|
||||
struct TStringPack *pastcStringPack;
|
||||
} TMenuPackFileInfo;
|
||||
|
||||
extern TMenuPackFileInfo g_stcMenuPack;
|
||||
|
||||
uint32_t file_crc32(const uint8_t *data, size_t len);
|
||||
|
||||
bool App_LoadMenuPackInfoBuf(const uint8_t *pbuf, int buf_size);
|
||||
bool App_LoadMenuPackInfo(const char *file_name);
|
||||
void App_UpdateMenuPackPtr(const TMenuPackFileHead *pstcPackHeader);
|
||||
|
||||
#endif /* _MAIN_H_ */
|
||||
71
Menu/include/menu_pack_port.h
Normal file
71
Menu/include/menu_pack_port.h
Normal file
@ -0,0 +1,71 @@
|
||||
#ifndef MENU_PACK_PORT_H
|
||||
#define MENU_PACK_PORT_H
|
||||
|
||||
#include <board.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MENU_PACK_TFT_PORT 1
|
||||
#define MENU_DISPLAY_MAX_COL 2
|
||||
|
||||
#define MENU_TITLE_LINE -1
|
||||
#define MENU_PREV_TITLE_LINE -2
|
||||
#define MENU_NEXT_TITLE_LINE -3
|
||||
|
||||
|
||||
int MenuPack_GetMaxRow(void);
|
||||
int MenuPack_GetDispCount(void);
|
||||
|
||||
#ifndef min
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
#define MenuPack_BIG_ENDIAN(data) (((data & 0xFF) << 8) | ((data >> 8) & 0xFF))
|
||||
//#define MAX_CURVE_NUMS 8
|
||||
//#define CURVE_DISPLAY_WIDTH 420
|
||||
//#define MAX_CURVE_BUF_SIZE 0x800
|
||||
|
||||
int MenuPack_WaitKey(int delay_ms);
|
||||
void MenuPack_DisplayStringPos(int disp_line, int disp_col, const char *str);
|
||||
void MenuPack_DisplayStringPosSelect(int disp_line, int disp_col, const char *str);
|
||||
void MenuPack_DisplayStringPosModifing(int disp_line, int disp_col, const char *str, int select);
|
||||
void MenuPack_GotoLine(int disp_line, int disp_col);
|
||||
|
||||
void MenuPack_DisplayString(const char *str);
|
||||
void MenuPack_DisplayStringSelect(const char *str);
|
||||
void MenuPack_DisplayStringModifing(const char *str, int select);
|
||||
void MenuPack_GetDisplayString(char *buf, int scale, int value, const char *lead_str, const char *unit);
|
||||
void MenuPack_DisplayTitleString(const char *str);
|
||||
void MenuPack_DisplayPrevTitleString(const char *str);
|
||||
void MenuPack_DisplayNextTitleString(const char *str);
|
||||
|
||||
void MenuPack_AddrDisplayString(unsigned short addr, const char * pstr);
|
||||
void MenuPack_AddrDisplayAsciiString(int addr, const char *str);
|
||||
|
||||
void MenuPack_AddDecShift(int32_t v, uint8_t Len, uint8_t Shift, char**ps);
|
||||
|
||||
|
||||
void MenuPack_DisplayVoltage(char * lead_str, char * pbuf, int value);
|
||||
void MenuPack_DisplayResistor(char * lead_str, char * pbuf, int value);
|
||||
void MenuPack_DisplayLeakUO(char *lead_str,char *pbuf, int value);
|
||||
void MenuPack_DisplayLeakIO(char * lead_str, char * pbuf, int value);
|
||||
void MenuPack_DisplayCurrent(char * lead_str, char * pbuf, int circuit_id, int value);
|
||||
void MenuPack_DisplaySignalCurrent(char * lead_str, char * pbuf, int value);
|
||||
void MenuPack_DisplayTemperature(char * lead_str, char * pbuf, int value);
|
||||
void MenuPack_DisplayAngle(char * lead_str, char * pbuf, int value);
|
||||
|
||||
void MenuPack_DisplayValue(int addr, int value, int len, int shift);
|
||||
void MenuPack_DisplayValue16(int addr, short value);
|
||||
void MenuPack_DisplayValueBuf(int addr, const short *pvalue, int items);
|
||||
void MenuPack_DisplayBuf(int addr, void *pbuf, int size);
|
||||
|
||||
void MenuPack_DisplayPage(int page);
|
||||
|
||||
int MenuPack_GetDisplayPage(void);
|
||||
void MenuPack_MenuClear(void);
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user