Menu.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include "Menu.h"
  2. #define uchar u8
  3. #define code const
  4. typedef struct
  5. {
  6.  uchar KeyStateIndex ; //当前状态索引号
  7.  uchar KeyDnState ; //按下 “向下” 键时转向的状态索引号
  8.  uchar KeyUpState ; //按下 “向上” 键时转向的状态索引号
  9.  uchar KeyCrState ; //按下 “回车” 键时转向的状态索引号
  10.  uchar KeyBackState ; //按下 “退回” 键时转向的状态索引号
  11.  void ( *CurrentOperate ) ( ) ; //当前状态应该执行的功能操作
  12. } KbdTabStruct ;
  13. #define SIZE_OF_KEYBD_MENU 55    //菜单总长度
  14. KbdTabStruct code KeyTab[SIZE_OF_KEYBD_MENU] =
  15. {
  16. /*
  17.  {0 ,0 ,0 ,1 ,0 , ( *MainJob1) } ,
  18.  {1 ,7 ,2 ,8 ,0 , ( *Dsp Point) } , //第一层
  19.  {2 ,1 ,3 ,8 ,0 , ( *DspCurve) ) , //第一层
  20.  {3 ,2 ,4 ,36 ,0 , ( *Dsp Kout) } ,   //第一层
  21.  {4 ,3 ,5 ,50 ,0 , ( *DisCloseDown) } , //第一层
  22.  {5 ,4 ,6 ,8 ,0 , ( *ModifyPoint) } , //第一层
  23.  {6 ,5 ,7 ,52 ,0 , ( *SetCloseDown) } , //第一层
  24.  {7 ,6 ,1 ,0 ,0 , ( *Cancel) } , //第一层
  25. // ....
  26. // ....
  27.  {52 ,53 ,53 ,0 ,1 , ( *OkSetCloseDown1) } ,
  28.  {53 ,52 ,52 ,0 ,1 , ( *OkSetCloseDown2) } ,
  29.  {54 ,0 ,0 ,0 ,0 , ( *Disable) } ,
  30. */
  31. };
  32. uchar KeyFuncIndex = 0; //当前画面索引号
  33. /*
  34. 1.由当前画面的[按键],找到下个画面
  35. 2.在下个画面,执行对应程序
  36. */
  37. void GetKeylnput ( void )
  38. {
  39. void *KeyFuncPtr = NULL;
  40. switch ( status & 0xf0 )
  41. {
  42. case 0xe0 : //回车键,找出新的菜单状态编号
  43. KeyFuncIndex = KeyTab[ KeyFuncIndex ].KeyCrState ;
  44. break ;
  45. case 0xb0 : //向下键,找出新的菜单状态编号
  46. KeyFuncIndex = KeyTab[ KeyFuncIndex ].KeyDn2State ;
  47. break ;
  48. case 0xd0 : //向上键,找出新的菜单状态编号
  49. KeyFuncIndex = KeyTab[ KeyFuncIndex ].KeyUp2State ;
  50. break ;
  51. case 0x70 : //回退键,找出新的菜单状态编号
  52. KeyFuncIndex = KeyTab[ KeyFuncIndex ].KeyBack2State ;
  53. break ;
  54. case 0 ;
  55. return;
  56.    //错误的处理
  57. break ;
  58. }
  59. KeyFuncPtr = KeyTab[ KeyFuncIndex ].CurrentOperate ;
  60. ( *KeyFuncPtr ) () ; //执行当前按键的操作
  61. }