📄 menu.c
字号:
/******************** (C) COPYRIGHT 2007 STMicroelectronics ********************
* File Name : menu.c
* Author : MCD Application Team
* Version : V1.1
* Date : 11/26/2007
* Description : This file includes the menu navigation driver for the
* STM3210B-EVAL demonstration.
********************************************************************************
* THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* Private typedef -----------------------------------------------------------*/
typedef void (* tMenuFunc)(void);
typedef struct sMenuItem * tMenuItem;
typedef struct sMenu * tMenu;
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
u8 MenuItemIndex = 0, nMenuLevel = 0;
u8 ItemNumb[MAX_MENU_LEVELS];
tMenuItem psMenuItem, psCurrentMenuItem;
tMenu psPrevMenu[MAX_MENU_LEVELS];
tMenu psCurrentMenu;
struct sMenuItem
{
u8* pszTitle;
tMenuFunc pfMenuFunc;
tMenuFunc pfUpDownMenuFunc;
tMenu psSubMenu;
};
struct sMenu
{
u8* pszTitle;
tMenuItem psItems;
u8 nItems;
};
uc32 IconsAddr[8] = {0x00622200, 0x00624D00, 0x00627800, 0x0062A300, 0x0062CE00,
0x0062F900, 0x00632400, 0x00634F00};
uc32 SlideAddr[14] = {0x00414400, 0x00439D00, 0x0045F600, 0x00484F00, 0x004AA800,
0x004D0100, 0x004F5A00, 0x0051B300, 0x00540C00, 0x00566500,
0x0058BE00, 0x005B1700, 0x005D7000, 0x005FC900};
uc32 SlidesSpeech[14] = {0x004142A2, 0x003D0147, 0x00373C6A, 0x00360218, 0x0031C734,
0x0029C386, 0x00251239, 0x001F9F2A, 0x0019AF3A, 0x00174BD4,
0x00115BE8, 0x000DF1D8, 0x0007ABCE, 0x0003C091};
uc32 DelayTiming[14] = {2530, 3430, 730, 2515, 4765, 2790, 3240, 3530, 1420, 3530,
2030, 3730, 2330, 2130};
u8 SlidesCheck[6] = {0x42, 0x4D, 0x42, 0x58, 0x02, 0x00};
u8 Icons64Check[6] = {0x42, 0x4D, 0x42, 0x2A, 0x00, 0x00};
u8 Icons128Check[6] = {0x42, 0x4D, 0x42, 0x80, 0x00, 0x00};
/*------------------------------ Menu level 4 -------------------------------*/
/*------------------------------ Menu level 3 -------------------------------*/
struct sMenuItem STOPMenuItems[] = {{" Exit: EXTI ", EnterSTOPMode_EXTI, IdleFunc},
{" Exit: RTC Alarm ", EnterSTOPMode_RTCAlarm, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu STOPMenu = {" STOP Mode ", STOPMenuItems, countof(STOPMenuItems)};
struct sMenuItem STANDBYMenuItems[] = {{" Exit: Wakeup Pin ", EnterSTANDBYMode_WAKEUP, IdleFunc},
{" Exit: RTC Alarm ", EnterSTANDBYMode_RTCAlarm, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu STANDBYMenu = {" STANDBY Mode ", STANDBYMenuItems, countof(STANDBYMenuItems)};
struct sMenuItem SettingTimeMenuItems[] = { {" Adjust ", Time_Adjust, IdleFunc},
{" Show ", Time_Show, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu TimeMenu = {" Time ", SettingTimeMenuItems, countof(SettingTimeMenuItems)};
struct sMenuItem SettingDateMenuItems[] = { {" Adjust ", Date_Adjust, IdleFunc},
{" Show ", Date_Show, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu DateMenu = {" Date ", SettingDateMenuItems, countof(SettingDateMenuItems)};
struct sMenuItem SettingAlarmMenuItems[] = { {" Adjust ", Alarm_Adjust, IdleFunc},
{" Show ", Alarm_Show, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu AlarmMenu = {" Alarm ", SettingAlarmMenuItems, countof(SettingAlarmMenuItems)};
/*------------------------------ Menu level 2 -------------------------------*/
struct sMenuItem AboutMenuItems[] = {{" About ", AboutFunc, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu AboutMenu = {" About ", AboutMenuItems, countof(AboutMenuItems)};
struct sMenuItem HelpMenuItems[] = {{" Start ", HelpFunc, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu HelpMenu = {" Help ", HelpMenuItems, countof(HelpMenuItems)};
struct sMenuItem FunnyMenuItems[] = {{" Start ", FunnyCircles, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu FunnyMenu = {" Funny ", FunnyMenuItems, countof(FunnyMenuItems)};
struct sMenuItem USBMA3SMenuItems[] = {{" Start ", Mass_Storage_Start, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu USBMA3SMenu = {" USB Mass Storage ", USBMA3SMenuItems, countof(USBMA3SMenuItems)};
struct sMenuItem TempSensorMenuItems[] = {{" Temperature ", Thermometer_Temperature, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu TempSensorMenu = {" Thermometer ", TempSensorMenuItems, countof(TempSensorMenuItems)};
struct sMenuItem LowPowerMenuItems[] = {{" STOP ", IdleFunc, IdleFunc, &STOPMenu},
{" STANDBY ", IdleFunc, IdleFunc, &STANDBYMenu},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu LowPowerMenu = {" Low Power Mode ", LowPowerMenuItems, countof(LowPowerMenuItems)};
struct sMenuItem CalendarMenuItems[] = {{" Time ", IdleFunc, IdleFunc, &TimeMenu},
{" Date ", IdleFunc, IdleFunc, &DateMenu},
{" Alarm ", IdleFunc, IdleFunc, &AlarmMenu},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu CalendarMenu = {" Calendar ", CalendarMenuItems, countof(CalendarMenuItems)};
struct sMenuItem ProdPresMenuItems[] = {{" Start ", ProductPres, IdleFunc},
{" Return ", ReturnFunc, IdleFunc}};
struct sMenu ProdPresMenu = {"Product Presentation", ProdPresMenuItems, countof(ProdPresMenuItems)};
/*------------------------------ Menu level 1 -------------------------------*/
struct sMenuItem MainMenuItems[] = {
{"Product Presentation", IdleFunc, IdleFunc, &ProdPresMenu},
{" Calendar ", IdleFunc, IdleFunc, &CalendarMenu},
{" Low Power Mode ", IdleFunc, IdleFunc, &LowPowerMenu},
{" Thermometer ", IdleFunc, IdleFunc, &TempSensorMenu},
{" USB Mass Storage ", IdleFunc, IdleFunc, &USBMA3SMenu},
{" Funny ", IdleFunc, IdleFunc, &FunnyMenu},
{" Help ", IdleFunc, IdleFunc, &HelpMenu},
{" About ", IdleFunc, IdleFunc, &AboutMenu}};
struct sMenu MainMenu = {" Main menu ", MainMenuItems, countof(MainMenuItems)};
/* Private function prototypes -----------------------------------------------*/
static u8 Buffercmp(u8* pBuffer1, u8* pBuffer2, u16 BufferLength);
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name : Menu_Init
* Description : Initializes the navigation menu.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void Menu_Init(void)
{
psCurrentMenu = &MainMenu;
psPrevMenu[nMenuLevel] = psCurrentMenu;
psMenuItem = MainMenuItems;
}
/*******************************************************************************
* Function Name : DisplayMenu
* Description : Displays the current menu.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DisplayMenu(void)
{
u32 Line = 0, index = 0;
tMenuItem psMenuItem2;
/* Set the Back Color */
LCD_SetBackColor(Blue);
/* Set the Text Color */
LCD_SetTextColor(White);
/* Clear the LCD Screen */
LCD_Clear(White);
LCD_DisplayStringLine(Line, psCurrentMenu->pszTitle);
Line += 24;
/* Set the Back Color */
LCD_SetBackColor(White);
/* Set the Text Color */
LCD_SetTextColor(Blue);
while(!(index >= (psCurrentMenu->nItems)))
{
psMenuItem2 = &(psCurrentMenu->psItems[index]);
LCD_DisplayStringLine(Line, psMenuItem2->pszTitle);
index++;
Line += 24;
}
/* Set the Back Color */
LCD_SetBackColor(Green);
/* Set the Text Color */
LCD_SetTextColor(White);
/* Get the current menu */
psMenuItem = &(psCurrentMenu->psItems[MenuItemIndex]);
LCD_DisplayStringLine(((MenuItemIndex + 1) * 24), psMenuItem->pszTitle);
}
/*******************************************************************************
* Function Name : SelFunc
* Description : This function is executed when "SEL" push-buttton is pressed.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void SelFunc(void)
{
psCurrentMenuItem = psMenuItem;
if(psMenuItem->psSubMenu != '\0')
{
/* Update the current Item by the submenu */
MenuItemIndex = 0;
psCurrentMenu = psMenuItem->psSubMenu;
psMenuItem = &(psCurrentMenu->psItems)[MenuItemIndex];
DisplayMenu();
nMenuLevel++;
psPrevMenu[nMenuLevel] = psCurrentMenu;
}
psCurrentMenuItem->pfMenuFunc();
}
/*******************************************************************************
* Function Name : UpFunc
* Description : This function is executed when any of "UP" push-butttons
* is pressed.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void UpFunc(void)
{
/* Set the Back Color */
LCD_SetBackColor(White);
/* Set the Text Color */
LCD_SetTextColor(Blue);
psMenuItem = &psCurrentMenu->psItems[MenuItemIndex];
LCD_DisplayStringLine(((MenuItemIndex + 1) * 24), psMenuItem->pszTitle);
if(MenuItemIndex > 0)
{
MenuItemIndex--;
}
else
{
MenuItemIndex = psCurrentMenu->nItems - 1;
}
/* Set the Back Color */
LCD_SetBackColor(Green);
/* Set the Text Color */
LCD_SetTextColor(White);
psMenuItem = &psCurrentMenu->psItems[MenuItemIndex];
LCD_DisplayStringLine(((MenuItemIndex + 1) * 24), psMenuItem->pszTitle);
ItemNumb[nMenuLevel] = MenuItemIndex;
}
/*******************************************************************************
* Function Name : DownFunc
* Description : This function is executed when any of "Down" push-butttons
* is pressed.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DownFunc(void)
{
/* Set the Back Color */
LCD_SetBackColor(White);
/* Set the Text Color */
LCD_SetTextColor(Blue);
psMenuItem = &psCurrentMenu->psItems[MenuItemIndex];
LCD_DisplayStringLine(((MenuItemIndex + 1) * 24), psMenuItem->pszTitle);
/* Test on the MenuItemIndex value before incrementing it */
if(MenuItemIndex >= ((psCurrentMenu->nItems)-1))
{
MenuItemIndex = 0;
}
else
{
MenuItemIndex++;
}
/* Set the Back Color */
LCD_SetBackColor(Green);
/* Set the Text Color */
LCD_SetTextColor(White);
/* Get the current menu */
psMenuItem = &(psCurrentMenu->psItems[MenuItemIndex]);
LCD_DisplayStringLine(((MenuItemIndex + 1) * 24), psMenuItem->pszTitle);
ItemNumb[nMenuLevel] = MenuItemIndex;
}
/*******************************************************************************
* Function Name : ReturnFunc
* Description : This function is executed when the "RETURN" menu is selected.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ReturnFunc(void)
{
psMenuItem->pfUpDownMenuFunc();
if(nMenuLevel == 0)
{
nMenuLevel++;
}
psCurrentMenu = psPrevMenu[nMenuLevel-1];
psMenuItem = &psCurrentMenu->psItems[0];
ItemNumb[nMenuLevel] = 0;
MenuItemIndex = 0;
nMenuLevel--;
if(nMenuLevel != 0)
{
DisplayMenu();
}
else
{
ShowMenuIcons();
}
}
/*******************************************************************************
* Function Name : ReadKey
* Description : Reads key from demoboard.
* Input : None
* Output : None
* Return : Return RIGHT, LEFT, SEL, UP, DOWN or NOKEY
*******************************************************************************/
u8 ReadKey(void)
{
/* "right" key is pressed */
if(!GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_0))
{
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_0) == Bit_RESET);
return RIGHT;
}
/* "left" key is pressed */
if(!GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_1))
{
while(GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_1) == Bit_RESET);
return LEFT;
}
/* "up" key is pressed */
if(!GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_8))
{
while(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_8) == Bit_RESET);
return UP;
}
/* "down" key is pressed */
if(!GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_14))
{
while(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_14) == Bit_RESET);
return DOWN;
}
/* "sel" key is pressed */
if(!GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_12))
{
while(GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_12) == Bit_RESET);
return SEL;
}
/* No key is pressed */
else
{
return NOKEY;
}
}
/*******************************************************************************
* Function Name : IdleFunc
* Description : Idle function.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void IdleFunc(void)
{
/* Nothing to execute: return */
return;
}
/*******************************************************************************
* Function Name : DisplayIcons
* Description : Display menu icons.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void DisplayIcons(void)
{
u32 i = 0, j = 0, l = 0, iconline = 0, iconcolumn = 0;
iconline = 98;
iconcolumn = 286;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
LCD_SetDisplayWindow(iconline, iconcolumn, 64, 84);
LCD_DrawBMP(IconsAddr[l]);
iconcolumn -= 85;
l++;
if(l == 8)
{
return;
}
}
iconline += 65;
iconcolumn = 286;
}
}
/*******************************************************************************
* Function Name : ShowMenuIcons
* Description : Show the main menu icon.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void ShowMenuIcons(void)
{
u32 MyKey = 0, i = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -