[8/16-bit MCU] 菜单列表和模拟时钟

[复制链接]
 楼主| lovecat2015 发表于 2015-12-30 20:17 | 显示全部楼层 |阅读模式
菜单按照结构体指针的方式实现,首先得有个结构体
  1. struct MenuItem
  2. {
  3.     unsigned char menuCount;        //?????÷
  4.     unsigned char *displayString;   //????×?·???
  5.     void  (*subs)();                //????
  6.     struct MenuItem *childernMenus; //??????
  7.     struct MenuItem *parentMenus;   //×?????
  8. }   MENU_NULL;


 楼主| lovecat2015 发表于 2015-12-30 20:18 | 显示全部楼层
然后定义一堆结构体数组
  1. struct MenuItem MainMenu[4] =   
  2. {        
  3.     {4,(unsigned char *)"1.获取CPU频率   ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  4.     {4,(unsigned char *)"2.获取时间  ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  5.     {4,(unsigned char *)"3.波特率设置  ",&NULL_Function,Baudrate,&MENU_NULL},
  6.     {4,(unsigned char *)"4.系统设置    ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  7. };
  8. struct MenuItem MailMenu[4] =   
  9. {        
  10.     {4,(unsigned char *)"1.收件箱",&NULL_Function,&MENU_NULL,&MENU_NULL},
  11.     {4,(unsigned char *)"2.发件箱",&NULL_Function,&MENU_NULL,&MENU_NULL},
  12.     {4,(unsigned char *)"3.写新邮件",&NULL_Function,Baudrate,&MENU_NULL},
  13.     {4,(unsigned char *)"4.邮箱设置",&NULL_Function,&MENU_NULL,&MENU_NULL},
  14. };
 楼主| lovecat2015 发表于 2015-12-30 20:19 | 显示全部楼层
  1. struct MenuItem CameraMenu[4] =   
  2. {        
  3.     {4,(unsigned char *)"1.拍照   ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  4.     {4,(unsigned char *)"2.摄像  ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  5.     {4,(unsigned char *)"3.曝光设置  ",&NULL_Function,Baudrate,&MENU_NULL},
  6.     {4,(unsigned char *)"4.存储设置    ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  7. };
  8. struct MenuItem TimeMenu[3] =   
  9. {        
  10.     {3,(unsigned char *)"1.设置日期和时间",&NULL_Function,&MENU_NULL,&MENU_NULL},
  11.     {3,(unsigned char *)"2.设置闹钟",&NULL_Function,&MENU_NULL,&MENU_NULL},
  12.     {3,(unsigned char *)"3.设置日期格式",&NULL_Function,&MENU_NULL,&MENU_NULL},
  13. };
 楼主| lovecat2015 发表于 2015-12-30 20:19 | 显示全部楼层
  1. struct MenuItem MusicMenu[3] =   
  2. {        
  3.     {3,(unsigned char *)"1.播放",&NULL_Function,&MENU_NULL,&MENU_NULL},
  4.     {3,(unsigned char *)"2.暂停",&NULL_Function,&MENU_NULL,&MENU_NULL},
  5.     {3,(unsigned char *)"3.歌曲列表",&NULL_Function,&MENU_NULL,&MENU_NULL},
  6. };
  7. struct MenuItem GameMenu[3] =   
  8. {        
  9.     {3,(unsigned char *)"1.俄罗斯方块",&NULL_Function,&MENU_NULL,&MENU_NULL},
  10.     {3,(unsigned char *)"2.打砖块",&NULL_Function,&MENU_NULL,&MENU_NULL},
  11.     {3,(unsigned char *)"3.贪吃蛇",&NULL_Function,&MENU_NULL,&MENU_NULL},               
  12. };
 楼主| lovecat2015 发表于 2015-12-30 20:20 | 显示全部楼层
  1. struct MenuItem SleepMenu[2] =   
  2. {        
  3.     {2,(unsigned char *)"1.进入休眠模式",&NULL_Function,&MENU_NULL,&MENU_NULL},
  4.     {2,(unsigned char *)"2.休眠设置",&NULL_Function,&MENU_NULL,&MENU_NULL},
  5. };
  6. struct MenuItem RadioMenu[3] =   
  7. {        
  8.     {3,(unsigned char *)"1.频道搜索",&NULL_Function,&MENU_NULL,&MENU_NULL},
  9.     {3,(unsigned char *)"2.上一频道",&NULL_Function,&MENU_NULL,&MENU_NULL},
  10.     {3,(unsigned char *)"3.下一频道",&NULL_Function,&MENU_NULL,&MENU_NULL},
  11. };
 楼主| lovecat2015 发表于 2015-12-30 20:20 | 显示全部楼层
  1. struct MenuItem IapMenu[2] =   
  2. {        
  3.     {2,(unsigned char *)"1.开始IAP ",&NULL_Function,&MENU_NULL,&MENU_NULL},
  4.     {2,(unsigned char *)"2.结束IAP   ",&NULL_Function,&MENU_NULL,&MENU_NULL},        
  5. };
  6. struct MenuItem AboutMenu[2] =   
  7. {        
  8.     {2,(unsigned char *)"1.我是Shower.xu",&NULL_Function,&MENU_NULL,&MENU_NULL},
  9.     {2,(unsigned char *)"2.谢谢大家",&NULL_Function,&MENU_NULL,&MENU_NULL},        
  10. };
  11. struct MenuItem *pMenuItem[10]={MainMenu,TimeMenu,MusicMenu,GameMenu,SleepMenu,RadioMenu,IapMenu,MainMenu,AboutMenu};
 楼主| lovecat2015 发表于 2015-12-30 20:21 | 显示全部楼层
菜单显示效果




下一步就是切换了
  1. void Menu2Process(void)
  2. {
  3.     if (key_status)
  4.     {
  5.         switch (key_status)
  6.         {
  7.             case KEY_UP_SHORT:
  8.                 UserChoose --;
  9.                 if (UserChoose < 0 )
  10.                 {
  11.                     UserChoose = MaxItems - 1;
  12.                 }
  13.                 break;
 楼主| lovecat2015 发表于 2015-12-30 20:22 | 显示全部楼层
  1. case KEY_DOWN_SHORT:
  2.                 UserChoose ++;
  3.                 if (UserChoose == MaxItems )
  4.                 {
  5.                     UserChoose = 0;
  6.                 }
  7.                 break;
  8.             case KEY_OK_SHORT:
  9.                 if ((MenuPoint[UserChoose].subs) != NULL_Function)
  10.                 {
  11.                             (*MenuPoint[UserChoose].subs)();
  12.                 }
  13.                 if (MenuPoint[UserChoose].childernMenus != &MENU_NULL)
  14.                 {
  15.                     MenuPoint          = MenuPoint[UserChoose].childernMenus;  
  16.                     Option                 = UserChoose;
  17.                     UserChoose          = 0;
  18.                     DisplayStart = 0;
  19.                 }
 楼主| lovecat2015 发表于 2015-12-30 20:22 | 显示全部楼层
  1. break;
  2.              case KEY_CAL_SHORT:
  3.                 if (MenuPoint[0].parentMenus != &MENU_NULL )
  4.                 {                                 
  5.                     MenuPoint          = MenuPoint[0].parentMenus;                        
  6.                     DisplayStart = 0;
  7.                     UserChoose   = Option;        
  8.                 }
  9.                                 else {Menu2Exit();return;}
  10.                 break;
  11.         }
 楼主| lovecat2015 发表于 2015-12-30 20:23 | 显示全部楼层
  1. /* 菜单选择显示样式1 */               
  2. //        if ((UserChoose < DisplayStart) || (UserChoose >= (DisplayStart + 1 )))
  3. //        {
  4. //                           DisplayStart = UserChoose;
  5. //        }
  6. /*   end  */        
  7.                                 GUI_WinFromClr(&demow);
  8.         Menu2Show();
  9.                                 /*  滚动条显示  */                                
  10.                                 GUI_ScorllBar(UserChoose,MenuPoint[0].menuCount);

  11.     }
  12. }
您需要登录后才可以回帖 登录 | 注册

本版积分规则

80

主题

816

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部