ucos ii下液晶菜单的设计
时间:10-02
整理:3721RD
点击:
最近公司里的废弃电路板比较多就是拿回来自己折腾玩了,
以前大学的时候用51做过数字万年历,但是51那可怜的资源真是设计起来麻烦的要死,现在在ARM7
上搞,简直很随意了。
其实原理也很简单没啥技术含量,纯属娱乐,就当做对ucos ii的学习了。
- #include "Menu.h"
- //Common
- //extern const stStateInfo NormalClock;
- const stMenuList *pMenuListEntry = NULL;
- //Home
- const char clockStr[] = {
- MENU_ZH_CODE_START, 43,
- MENU_ZH_CODE_START, 44,
- };
- static const stHomeIcon clockIcon = {
- BMP_ICON_ID_CLOCK,
- {clockStr, sizeof(clockStr)},
- &NormalClock,
- 0x00000000,
- };
- const char calendarStr[] = {
- MENU_ZH_CODE_START, 0,
- MENU_ZH_CODE_START, 45,
- };
- static const stHomeIcon calendarIcon = {
- BMP_ICON_ID_CALENDAR,
- {calendarStr, sizeof(calendarStr)},
- &NormalClock,
- 0x00000000,
- };
- const char gameStr[] = {
- MENU_ZH_CODE_START, 46,
- MENU_ZH_CODE_START, 47,
- };
- static const stHomeIcon gameIcon = {
- BMP_ICON_ID_GAME,
- {gameStr, sizeof(gameStr)},
- &NormalClock,
- 0x00000000,
- };
- const char settingStr[] = {
- MENU_ZH_CODE_START, 48,
- MENU_ZH_CODE_START, 49,
- };
- static const stHomeIcon settingIcon = {
- BMP_ICON_ID_SETTING,
- {settingStr, sizeof(settingStr)},
- &Menu,
- (INT32U)&MenuSetList,
- };
- const char systemStr[] = {
- MENU_ZH_CODE_START, 50,
- MENU_ZH_CODE_START, 51,
- };
- static const stHomeIcon systemIcon = {
- BMP_ICON_ID_SYSTEM,
- {systemStr, sizeof(systemStr)},
- &NormalClock,
- 0x00000000,
- };
- const stHomeIcon *HomeIcon[] = {
- &clockIcon,
- &calendarIcon,
- &gameIcon,
- &settingIcon,
- &systemIcon,
- };
- const INT8U HomeIconTotalNum = sizeof(HomeIcon) / sizeof(stHomeIcon *);
- //Set menu
- static INT8U menuSetInputData[2] = {1, 1};
- #define MENU_SET_ITEM_ID 0u
- #define MENU_SET_TIME_ITEM_ID MENU_SET_ITEM_ID + 0u
- static const char menuSetTimeStr[] = {
- MENU_ZH_CODE_START, 43,
- MENU_ZH_CODE_START, 56,
- MENU_ZH_CODE_START, 48,
- MENU_ZH_CODE_START, 49
- };
- const stMenuItem MenuSetTime = {
- 0u,
- MENU_SET_TIME_ITEM_ID,
- {menuSetTimeStr, sizeof(menuSetTimeStr)},
- &NormalClock,
- };
- #define MENU_SET_DATE_ITEM_ID MENU_SET_TIME_ITEM_ID + 1u
- static const char menuSetDateStr[] = {
- MENU_ZH_CODE_START, 0,
- MENU_ZH_CODE_START, 13,
- MENU_ZH_CODE_START, 48,
- MENU_ZH_CODE_START, 49
- };
- const stMenuItem MenuSetDate = {
- 0u,
- MENU_SET_DATE_ITEM_ID,
- {menuSetDateStr, sizeof(menuSetDateStr)},
- &SetDate,
- };
- #define MENU_SYSTEM_SET_ITEM_ID MENU_SET_DATE_ITEM_ID + 1u
- static const char menuSystemSetStr[] = {
- MENU_ZH_CODE_START, 50,
- MENU_ZH_CODE_START, 51,
- MENU_ZH_CODE_START, 48,
- MENU_ZH_CODE_START, 49
- };
- const stMenuItem MenuSystemSet = {
- 3u,
- MENU_SYSTEM_SET_ITEM_ID,
- {menuSystemSetStr, sizeof(menuSystemSetStr)},
- &MenuSystemSetList,
- };
- const stMenuItem *menuSetListGroup[] = {
- &MenuSetTime,
- &MenuSetDate,
- &MenuSystemSet,
- };
- const stMenuList MenuSetList = {
- sizeof(menuSetListGroup) / sizeof(stMenuItem *),
- menuSetInputData,
- &settingIcon.str,
- NULL,
- NULL,
- menuSetListGroup,
- };
- //System set menu
- static INT8U menuSystemSetInputData[2] = {1, 1};
- #define MENU_SET_SYSTEM_ID 0u
- #define MENU_BACK_LIGHT_TIME_ITEM_ID MENU_SET_SYSTEM_ID + 0u
- static const char menuBackLightTimeStr[] = {
- MENU_ZH_CODE_START, 57,
- MENU_ZH_CODE_START, 58,
- MENU_ZH_CODE_START, 43,
- MENU_ZH_CODE_START, 56
- };
- const stMenuItem MenuBackLightTime = {
- 0u,
- MENU_BACK_LIGHT_TIME_ITEM_ID,
- {menuBackLightTimeStr, sizeof(menuBackLightTimeStr)},
- &NormalClock,
- };
- #define MENU_MENU_OVERTIME_ITEM_ID MENU_BACK_LIGHT_TIME_ITEM_ID + 0u
- static const char menuOvertimeStr[] = {
- MENU_ZH_CODE_START, 59,
- MENU_ZH_CODE_START, 60,
- MENU_ZH_CODE_START, 61,
- MENU_ZH_CODE_START, 43,
- MENU_ZH_CODE_START, 43,
- MENU_ZH_CODE_START, 56
- };
- const stMenuItem MenuOvertime = {
- 0u,
- MENU_MENU_OVERTIME_ITEM_ID,
- {menuOvertimeStr, sizeof(menuOvertimeStr)},
- &NormalClock,
- };
- #define MENU_LCD_CONTRAST_ITEM_ID MENU_MENU_OVERTIME_ITEM_ID + 0u
- static const char menuLcdContrastStr[] = {
- 'L',
- 'C',
- 'D',
- MENU_ZH_CODE_START, 64,
- MENU_ZH_CODE_START, 65,
- MENU_ZH_CODE_START, 66
- };
- const stMenuItem MenuLcdContrast = {
- 0u,
- MENU_LCD_CONTRAST_ITEM_ID,
- {menuLcdContrastStr, sizeof(menuLcdContrastStr)},
- &NormalClock,
- };
- const stMenuItem *menuSystemSetListGroup[] = {
- &MenuBackLightTime,
- &MenuOvertime,
- &MenuLcdContrast,
- };
- const stMenuList MenuSystemSetList = {
- sizeof(menuSystemSetListGroup) / sizeof(stMenuItem *),
- menuSystemSetInputData,
- &MenuSystemSet.itemName,
- &MenuSystemSet,
- &MenuSetList,
- menuSystemSetListGroup,
- };
- #ifndef MENU_H_
- #define MENU_H_
- #include "Platform.h"
- #include "ucos_ii.h"
- #include "State.h"
- #define MENU_ZH_CODE_START 0xA1
- #define HOME_ICON_ID_TYPE INT8U
- struct ST_MENU_ITEM;
- struct ST_MENU_ITEM_STR;
- struct ST_MENU_LIST;
- typedef struct ST_MENU_ITEM_STR{
- const char *pstr;
- INT8U len;
- }stMenuItemStr;
- typedef struct ST_MENU_LIST {
- INT8U itemNum;
- INT8U *pdata;
- const stMenuItemStr *pname;
- const struct ST_MENU_ITEM *pparentItem;
- const struct ST_MENU_LIST *pparentItemList;
- const struct ST_MENU_ITEM **pItem;
- }stMenuList;
- typedef struct ST_MENU_ITEM {
- INT8U subItemNum;
- INT8U thisItemID;
- stMenuItemStr itemName;
- const void *pData;
- }stMenuItem;
- typedef struct {
- const HOME_ICON_ID_TYPE iconID;
- const stMenuItemStr str;
- const struct ST_STATE_INFO *pstate;
- INT32U data;
- }stHomeIcon;
- extern const stMenuList MenuSetList;
- extern const stMenuList MenuSystemSetList;
- extern const stMenuList *pMenuListEntry;
- extern const stHomeIcon *HomeIcon[];
- extern const INT8U HomeIconTotalNum;
- #endif /* MENU_H_ */
- #include "State.h"
- #include "CalendarCalculated.h"
- //NormalClock data
- void State_NormalClock(void *ptr);
- const stStateInfo NormalClock = {
- 0x00000000,
- State_NormalClock,
- NULL,
- };
- //Home data
- void State_Home(void *ptr);
- static INT8U homeInputData[2] = {1, 1};
- const stStateInfo Home = {
- 0x00000000,
- State_Home,
- homeInputData,
- };
- //Power off data
- void State_PowerOff(void *ptr);
- static INT32U lastStateAddr = 0;
- const stStateInfo PowerOff = {
- 0x00000000,
- State_PowerOff,
- &lastStateAddr,
- };
- //Menu data
- void State_Menu(void *ptr);
- const stStateInfo Menu = {
- (INT32U)&pMenuListEntry,
- State_Menu,
- NULL,
- };
- //Set date
- void State_SetDate(void *ptr);
- const stStateInfo SetDate = {
- (INT32U)&pMenuListEntry,
- State_SetDate,
- (void *)&MenuSetList,
- };
- //Common data
- const stStateInfo *pState = &NormalClock;
- static void (*pTimeAction)(void);
- OS_EVENT *pStateQ;
- static stStateMsg stateMsg[STATE_MSG_SIZE];
- void *StateMsg[STATE_MSG_SIZE];
- static void __defaultEventProcess(INT8U *pexitFlag, stMSG *pmsg, void *ptr);
- //NormalClock
- static void __lunarCalendarDisplay(void)
- {
- INT8U x = 48;
- switch (lunaCalendarData.month)
- {
- case 1:
- LCD_PutZH16x16(x, 4, 17, 1);
- break;
- case 2:
- LCD_PutZH16x16(x, 4, 2, 1);
- break;
- case 3:
- LCD_PutZH16x16(x, 4, 3, 1);
- break;
- case 4:
- LCD_PutZH16x16(x, 4, 4, 1);
- break;
- case 5:
- LCD_PutZH16x16(x, 4, 5, 1);
- break;
- case 6:
- LCD_PutZH16x16(x, 4, 6, 1);
- break;
- case 7:
- LCD_PutZH16x16(x, 4, 7, 1);
- break;
- case 8:
- LCD_PutZH16x16(x, 4, 8, 1);
- break;
- case 9:
- LCD_PutZH16x16(x, 4, 9, 1);
- break;
- case 10:
- LCD_PutZH16x16(x, 4, 10, 1);
- break;
- case 11:
- LCD_PutZH16x16(x, 4, 10, 1);
- x += 16;
- LCD_PutZH16x16(x, 4, 1, 1);
- break;
- case 12:
- LCD_PutZH16x16(x, 4, 10, 1);
- x += 16;
- LCD_PutZH16x16(x, 4, 2, 1);
- break;
- default:
- break;
- }
- x += 16;
- LCD_PutZH16x16(x, 4, 19, 1);
- if(lunaCalendarData.day < 11)
- {
- //初
- x += 16;
- LCD_PutZH16x16(x, 4, 18, 1);
- x += 16;
- LCD_PutZH16x16(x, 4, lunaCalendarData.day, 1);
- }
- else if(lunaCalendarData.day < 20)
- {
- //十
- x += 16;
- LCD_PutZH16x16(x, 4, 10, 1);
- x += 16;
- LCD_PutZH16x16(x, 4, lunaCalendarData.day % 10, 1);
- }
- else if(lunaCalendarData.day < 30)
- {
- //廿
- x += 16;
- LCD_PutZH16x16(x, 4, 11, 1);
- x += 16;
- if(lunaCalendarData.day % 10)
- LCD_PutZH16x16(x, 4, lunaCalendarData.day % 10, 1);
- else
- LCD_PutZH16x16(x, 4, 10, 1);
- }
- else
- {
- //三十
- x += 16;
- LCD_PutZH16x16(x, 4, 3, 1);
- x += 16;
- LCD_PutZH16x16(x, 4, 10, 1);
- }
- x += 16;
- if(x < 128)
- {
- LCD_PutMiddleString(x, 4, " ", 1);
- }
- x = 64;
- LCD_PutZH16x16(x, 2, lunaCalendarData.tianGan + 20, 1);
- x += 16;
- LCD_PutZH16x16(x, 2, lunaCalendarData.diZhi + 30, 1);
- }
- static void __NormalClock_TimeAction(void)
- {
- INT8U err, x = 0;
- INT8U h = 0;
- INT8U m = 0;
- INT8U s = 0;
- INT8U d = 0;
- INT8U month = 0;
- INT8U date = 0;
- INT8U year = 0;
- stStateMsg *pStateMsg;
- while(1)
- {
- pStateMsg = (stStateMsg *)OSQPend(pStateQ, 10, &err);
- switch(err)
- {
- case OS_ERR_NONE:
- switch(pStateMsg->cmd)
- {
- case NORMAL_CLOCK_TIMEUPDATE:
- x = 0;
- LCD_PutLargeNumber(x, 0, ((h >> 4) & 0x0f), 1);
- x += 12;
- LCD_PutLargeNumber(x, 0, (h & 0x0f), 1);
- x += 12;
- if(s % 2)
- LCD_PutLargeNumber(x, 0, 10, 1);
- else
- LCD_PutLargeNumber(x, 0, 11, 1);
- x += 12;
- LCD_PutLargeNumber(x, 0, ((m >> 4) & 0x0f), 1);
- x += 12;
- LCD_PutLargeNumber(x, 0, (m & 0x0f), 1);
- break;
- case NORMAL_CLOCK_DATEUPDATE:
- x = 0;
- LCD_PutSmallChar(x, 3, '2', 1);
- x += 6;
- LCD_PutSmallChar(x, 3, '0', 1);
- x += 6;
- LCD_PutSmallChar(x, 3, '0' + ((year >> 4) & 0x0f), 1);
- x += 6;
- LCD_PutSmallChar(x, 3, '0' + (year & 0x0f), 1);
- x += 12;
- LCD_PutSmallChar(x, 3, '0' + ((month >> 4) & 0x0f), 1);
- x += 6;
- LCD_PutSmallChar(x, 3, '0' + (month & 0x0f), 1);
- x += 12;
- LCD_PutSmallChar(x, 3, '0' + ((date >> 4) & 0x0f), 1);
- x += 6;
- LCD_PutSmallChar(x, 3, '0' + (date & 0x0f), 1);
- if(d == 7)
- LCD_PutZH16x16(96, 0, 0, 1);
- else
- LCD_PutZH16x16(96, 0, d, 1);
- solaCalendarToLunarCalendar(
- ((year >> 4) & 0x0f) * 10 +
- (year & 0x0f) + 2000,
- ((month >> 4) & 0x0f) * 10 +
- (month & 0x0f),
- ((date >> 4) & 0x0f) * 10 +
- (date & 0x0f)
- );
- __lunarCalendarDisplay();
- break;
- case NORMAL_CLOCK_INIT:
- LCD_Clear(0);
- LCD_PutSmallChar(24, 3, '/', 1);
- LCD_PutSmallChar(42, 3, '/', 1);
- LCD_PutZH16x16(64, 0, 12, 1);
- LCD_PutZH16x16(80, 0, 13, 1);
- LCD_PutZH16x16(96, 2, 20, 1);
- LCD_PutBmp(48, 6, BMP_BUTTON_ID_HOME, 1);
- LCD_PutBmp(48, 7, BMP_BUTTON_ID_LAMP, 1);
- DS1337_Getc(RTC_HOUR, &h);
- DS1337_Getc(RTC_MIN, &m);
- DS1337_Getc(RTC_SEC, &s);
- DS1337_Getc(RTC_MONTH, &month);
- DS1337_Getc(RTC_DATE, &date);
- DS1337_Getc(RTC_YEAR, &year);
- DS1337_Getc(RTC_DAY, &d);
- if((h < 6) || (h > 18))
- {
- LCD_PutBmp(0, 4, BMP_PIC_ID_NIGHT, 1);
- }
- else if((h >= 6) && (h < 10))
- {
- LCD_PutBmp(0, 4, BMP_PIC_ID_MORNING, 1);
- }
- else if((h >= 10) && (h < 14))
- {
- LCD_PutBmp(0, 4, BMP_PIC_ID_NOON, 1);
- }
- else
- {
- LCD_PutBmp(0, 4, BMP_PIC_ID_AFTERNOON, 1);
- }
- pStateMsg = &stateMsg[1];
- pStateMsg->cmd = NORMAL_CLOCK_TIMEUPDATE;
- OSQPost(pStateQ, (void *)pStateMsg);
- pStateMsg = &stateMsg[2];
- pStateMsg->cmd = NORMAL_CLOCK_DATEUPDATE;
- OSQPost(pStateQ, (void *)pStateMsg);
- break;
- case NORMAL_CLOCK_PICUPDATE:
- LCD_PutBmp(0, 4, (INT8U)(INT32U)pStateMsg->pData, 1);
- break;
- case STATE_EXIT:
- return;
- default:
- break;
- }
- break;
- case OS_ERR_TIMEOUT:
- {
- INT8U tmpSec = s, tmpDate = date, tmpHour = h;
- DS1337_Getc(RTC_HOUR, &h);
- DS1337_Getc(RTC_MIN, &m);
- DS1337_Getc(RTC_SEC, &s);
- DS1337_Getc(RTC_MONTH, &month);
- DS1337_Getc(RTC_DATE, &date);
- DS1337_Getc(RTC_YEAR, &year);
- if(s != tmpSec)
- {
- pStateMsg = &stateMsg[1];
- pStateMsg->cmd = NORMAL_CLOCK_TIMEUPDATE;
- OSQPost(pStateQ, (void *)pStateMsg);
- }
- if(date != tmpDate)
- {
- pStateMsg = &stateMsg[2];
- pStateMsg->cmd = NORMAL_CLOCK_DATEUPDATE;
- OSQPost(pStateQ, (void *)pStateMsg);
- }
- if((tmpHour != h) &&
- ((h == 0x06) || (h == 0x10) || (h == 0x14) || (h == 0x18))
- )
- {
- pStateMsg = &stateMsg[3];
- pStateMsg->cmd = NORMAL_CLOCK_PICUPDATE;
- switch(h)
- {
- case 0x06:
- pStateMsg->pData = (void *)BMP_PIC_ID_MORNING;
- break;
- case 0x10:
- pStateMsg->pData = (void *)BMP_PIC_ID_NOON;
- break;
- case 0x14:
- pStateMsg->pData = (void *)BMP_PIC_ID_AFTERNOON;
- break;
- case 0x18:
- pStateMsg->pData = (void *)BMP_PIC_ID_NIGHT;
- break;
- default:
- pStateMsg->pData = (void *)BMP_PIC_ID_MORNING;
- break;
- }
- OSQPost(pStateQ, (void *)pStateMsg);
- }
- }
- break;
- default:
- OSTimeDly(10);
- break;
- }
- }
- }
- static void __NormalClock_EventProcess(void *ptr)
- {
- INT8U err, exitFlag = 1u;
- stMSG *pmsg;
- stStateMsg *pStateMsg = &stateMsg[0];
- while(exitFlag)
- {
- pmsg = (stMSG *)OSMboxPend(pMsgEvent, 0, &err);
- switch(pmsg->keyValue)
- {
- case KEY_VAL_LEFT:
- break;
- case KEY_VAL_RIGHT:
- break;
- case KEY_VAL_UP:
- pState = &Home;
- ((INT8U *)pState->pdata)[0] = 1;
- ((INT8U *)pState->pdata)[1] = 1;
- pStateMsg->cmd = STATE_EXIT;
- OSQPost(pStateQ, (void *)pStateMsg);
- return;
- case KEY_VAL_DOWN | KEY_VAL_LONG:
- case KEY_VAL_DOWN:
- FLASH_POWER? FLASH_POWER_OFF : FLASH_POWER_ON;
- break;
- default:
- __defaultEventProcess(&exitFlag, pmsg, ptr);
- break;
- }
- }
- }
- void State_NormalClock(void *ptr)
- {
- stStateMsg *pStateMsg = &stateMsg[0];
- pTimeAction = __NormalClock_TimeAction;
- pStateMsg->cmd = NORMAL_CLOCK_INIT;
- OSQPost(pStateQ, (void *)pStateMsg);
- __NormalClock_EventProcess(ptr);
- }
- //Home
- static void __Home_TimeAction(void)
- {
- INT8U err, x = 0;
- INT8U h = 0;
- INT8U m = 0;
- INT8U s = 0;
- stStateMsg *pStateMsg;
- INT8U iconIndex, dspIndex;
- INT8U dspMaxIndex = HomeIconTotalNum > 4 ? 4 : HomeIconTotalNum;
- while(1)
- {
- pStateMsg = (stStateMsg *)OSQPend(pStateQ, 10, &err);
- switch(err)
- {
- case OS_ERR_NONE:
- switch(pStateMsg->cmd)
- {
- case HOME_INIT:
- LCD_Clear(0);
- LCD_PutBmp(0, 6, BMP_BUTTON_ID_ENTER, 1);
- LCD_PutBmp(48, 6, BMP_BUTTON_ID_UP, 1);
- LCD_PutBmp(48, 7, BMP_BUTTON_ID_DOWN, 1);
- LCD_PutBmp(96, 6, BMP_BUTTON_ID_BACK, 1);
- DS1337_Getc(RTC_HOUR, &h);
- DS1337_Getc(RTC_MIN, &m);
- DS1337_Getc(RTC_SEC, &s);
- dspIndex = ((INT8U *)pStateMsg->pData)[0];
- iconIndex = ((INT8U *)pStateMsg->pData)[1];
- pStateMsg = &stateMsg[1];
- pStateMsg->cmd = HOME_ICONUPDATE;
- pStateMsg->pData = (void *)&iconIndex;
- OSQPost(pStateQ, (void *)pStateMsg);
- pStateMsg = &stateMsg[2];
- pStateMsg->cmd = HOME_TIMEUPDATE;
- OSQPost(pStateQ, (void *)pStateMsg);
- break;
- case HOME_ICONMOVELEFT:
- iconIndex = (*(INT8U *)pStateMsg->pData);
- if(iconIndex == HomeIconTotalNum)
- dspIndex = dspMaxIndex;
- else if(dspIndex > 1)
- dspIndex--;
- pStateMsg = &stateMsg[1];
- pStateMsg->cmd = HOME_ICONUPDATE;
- pStateMsg->pData = (void *)&iconIndex;
- OSQPost(pStateQ, (void *)pStateMsg);
- break;
- case HOME_ICONMOVERIGHT:
- iconIndex = (*(INT8U *)pStateMsg->pData);
- if(iconIndex == 1)
- dspIndex = 1;
- else if(dspIndex < dspMaxIndex)
- dspIndex++;
- &nbs