00001 /* 00002 * File: menu.h 00003 * Purpose: Menu functions header 00004 * Author: Peter Ivanov 00005 * Modified by: 00006 * Created: 2007-05-19 11:31:29 00007 * Last modify: 2007-10-21 11:31:45 ivanovp {Time-stamp} 00008 * Copyright: (C) Peter Ivanov, 2007 00009 * Licence: GPL 00010 */ 00011 /** 00012 * \file menu.h 00013 * \brief Menu functions header 00014 * \author Peter Ivanov 00015 */ 00016 #ifndef __INCLUDE_MENU_H 00017 #define __INCLUDE_MENU_H 00018 00019 #include <sys/types.h> 00020 00021 typedef struct menuPoint_t menuPoint_t; 00022 00023 /** 00024 * Struct for storing a menu point. 00025 * 00026 * @author Peter Ivanov 00027 */ 00028 struct menuPoint_t 00029 { 00030 /** 00031 * Title of menu to display. Must be seven characters long! 00032 */ 00033 char* menuTitle; 00034 00035 /** 00036 * Sub-menu to invoke if menu is selected. 00037 * You should set only one option of subMenu and menuHandlerCallback! 00038 */ 00039 menuPoint_t* subMenu; 00040 00041 /** 00042 * Function to call if menu is selected. 00043 * You should set only one option of subMenu and menuHandlerCallback! 00044 */ 00045 void (*menuHandlerCallback) (); 00046 }; 00047 00048 /// Maximum level of menu depth 00049 #define MENU_MAX_LEVEL 4 00050 /// Maximum number of menu items on a level 00051 #define MENU_MAX_MENU_ITEMS 255 00052 00053 extern menuPoint_t* currentMenu; 00054 extern uint8_t currentMenuNumber; ///< number of selected menu item 00055 extern uint8_t currentMenuSize; ///< number of menu items in actual menu point 00056 extern int8_t currentMenuLevel; 00057 extern menuPoint_t* parentMenu[MENU_MAX_LEVEL]; 00058 extern uint8_t parentMenuNumber[MENU_MAX_LEVEL]; 00059 00060 /** 00061 * Initialize menu system. After this you should call MENU_handler 00062 * periodically. 00063 * Example: 00064 <pre> 00065 menuPoint_t rootMenu[] = 00066 { 00067 //1234567 sub-menu callback function 00068 {"NRFTEST", NULL, rf24lTest}, 00069 {"IR TEST", NULL, irTest}, 00070 {"SET CLK", setClockMenu, NULL}, 00071 {"SET ALM", setAlarmMenu, NULL}, 00072 {NULL, NULL, NULL} // end of menu 00073 }; 00074 00075 int main () 00076 { 00077 // ... 00078 MENU_init (rootMenu); 00079 } 00080 </pre> 00081 * 00082 * @author Peter Ivanov 00083 * 00084 * @param rootMenu Pointer to root menu. 00085 */ 00086 void MENU_init (menuPoint_t* rootMenu); 00087 00088 /** 00089 * Internally used function to print the actual menu item. 00090 * 00091 * @author Peter Ivanov 00092 */ 00093 void MENU_showCurrentMenuItem (); 00094 00095 /** 00096 * Internally used function to count the size of a menu. 00097 * 00098 * @author Peter Ivanov 00099 * 00100 * @param menu Pointer to menu. 00101 * @return Number of menu elements. 00102 */ 00103 uint8_t MENU_getMenuSize (menuPoint_t* menu); 00104 00105 /** 00106 * This function handles the events which comes from keyboard. 00107 * Before using this function, you should initialize the menu system. 00108 * @see MENU_init 00109 * 00110 * Example: 00111 <pre> 00112 while (1) 00113 { 00114 buttonHandler (); 00115 if (buttonPressed) 00116 { 00117 MENU_handler (buttonPressed); 00118 } 00119 // ... 00120 } 00121 </pre> 00122 * 00123 * @author Peter Ivanov 00124 * 00125 * @param buttonPressed The buttons which are pressed meanwhile. 00126 */ 00127 void MENU_handler (uint8_t buttonPressed); 00128 00129 #endif // __INCLUDE_MENU_H
1.5.1