summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/menu.c96
-rw-r--r--apps/menu.h5
2 files changed, 60 insertions, 41 deletions
diff --git a/apps/menu.c b/apps/menu.c
index 36cb6152fb..027f1fcbea 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -16,48 +16,66 @@
16 * KIND, either express or implied. 16 * KIND, either express or implied.
17 * 17 *
18 ****************************************************************************/ 18 ****************************************************************************/
19 19#include <stdbool.h>
20#include "lcd.h" 20#include "lcd.h"
21#include "menu.h" 21#include "menu.h"
22#include "button.h" 22#include "button.h"
23#include "kernel.h" 23#include "kernel.h"
24#include "debug.h" 24#include "debug.h"
25 25
26/* Global values for menuing */ 26struct menu {
27static int menu_top; 27 int menu_top;
28static int menu_bottom; 28 int menu_bottom;
29static int cursor; 29 int cursor;
30static struct menu_items* items; 30 struct menu_items* items;
31static int itemcount; 31 int itemcount;
32};
33
34#define MAX_MENUS 4
35
36static struct menu menus[MAX_MENUS];
37static bool inuse[MAX_MENUS] = { false };
32 38
33/* 39/*
34 * Move the cursor to a particular id, 40 * Move the cursor to a particular id,
35 * target: where you want it to be 41 * target: where you want it to be
36 */ 42 */
37static void put_cursor(int target) 43static void put_cursor(int m, int target)
38{ 44{
39 lcd_puts(0, cursor, " "); 45 lcd_puts(0, menus[m].cursor, " ");
40 cursor = target; 46 menus[m].cursor = target;
41 lcd_puts(0, cursor, "-"); 47 lcd_puts(0, menus[m].cursor, "-");
42} 48}
43 49
44/* We call the function pointer related to the current cursor position */ 50int menu_init(struct menu_items* mitems, int count)
45static void execute_menu_item(void)
46{ 51{
47 /* call the proper function for this line */ 52 int i;
48 items[cursor].function(); 53
54 for ( i=0; i<MAX_MENUS; i++ ) {
55 if ( !inuse[i] ) {
56 inuse[i] = true;
57 break;
58 }
59 }
60 if ( i == MAX_MENUS ) {
61 DEBUGF("Out of menus!\n");
62 return -1;
63 }
64 menus[i].items = mitems;
65 menus[i].itemcount = count;
66 menus[i].menu_top = 0;
67 menus[i].menu_bottom = count-1;
68 menus[i].cursor = 0;
69
70 return i;
49} 71}
50 72
51void menu_init(struct menu_items* mitems, int count) 73void menu_exit(int m)
52{ 74{
53 items = mitems; 75 inuse[m] = false;
54 itemcount = count;
55 menu_top = items[0].id;
56 menu_bottom = count-1;
57 cursor = menu_top;
58} 76}
59 77
60static void menu_draw(void) 78static void menu_draw(int m)
61{ 79{
62 int i = 0; 80 int i = 0;
63 81
@@ -66,23 +84,23 @@ static void menu_draw(void)
66 lcd_setmargins(0,0); 84 lcd_setmargins(0,0);
67 lcd_setfont(0); 85 lcd_setfont(0);
68#endif 86#endif
69 for (i = 0; i < itemcount; i++) { 87 for (i = 0; i < menus[m].itemcount; i++) {
70 lcd_puts(1, i, items[i].desc); 88 lcd_puts(1, i, menus[m].items[i].desc);
71 if (i < menu_top) 89 if (i < menus[m].menu_top)
72 menu_top = i; 90 menus[m].menu_top = i;
73 if (i > menu_bottom) 91 if (i > menus[m].menu_bottom)
74 menu_bottom = i; 92 menus[m].menu_bottom = i;
75 } 93 }
76 94
77 lcd_puts(0, cursor, "-"); 95 lcd_puts(0, menus[m].cursor, "-");
78 lcd_update(); 96 lcd_update();
79} 97}
80 98
81void menu_run(void) 99void menu_run(int m)
82{ 100{
83 int key; 101 int key;
84 102
85 menu_draw(); 103 menu_draw(m);
86 104
87 while(1) { 105 while(1) {
88 key = button_get(); 106 key = button_get();
@@ -97,12 +115,12 @@ void menu_run(void)
97#else 115#else
98 case BUTTON_LEFT: 116 case BUTTON_LEFT:
99#endif 117#endif
100 if (cursor == menu_top) { 118 if (menus[m].cursor == menus[m].menu_top) {
101 /* wrap around to menu bottom */ 119 /* wrap around to menu bottom */
102 put_cursor(menu_bottom); 120 put_cursor(m, menus[m].menu_bottom);
103 } else { 121 } else {
104 /* move up */ 122 /* move up */
105 put_cursor(cursor-1); 123 put_cursor(m, menus[m].cursor-1);
106 } 124 }
107 break; 125 break;
108 126
@@ -111,12 +129,12 @@ void menu_run(void)
111#else 129#else
112 case BUTTON_RIGHT: 130 case BUTTON_RIGHT:
113#endif 131#endif
114 if (cursor == menu_bottom) { 132 if (menus[m].cursor == menus[m].menu_bottom) {
115 /* wrap around to menu top */ 133 /* wrap around to menu top */
116 put_cursor(menu_top); 134 put_cursor(m, menus[m].menu_top);
117 } else { 135 } else {
118 /* move down */ 136 /* move down */
119 put_cursor(cursor+1); 137 put_cursor(m, menus[m].cursor+1);
120 } 138 }
121 break; 139 break;
122 140
@@ -127,10 +145,10 @@ void menu_run(void)
127 /* Erase current display state */ 145 /* Erase current display state */
128 lcd_clear_display(); 146 lcd_clear_display();
129 147
130 execute_menu_item(); 148 menus[m].items[menus[m].cursor].function();
131 149
132 /* Return to previous display state */ 150 /* Return to previous display state */
133 menu_draw(); 151 menu_draw(m);
134 break; 152 break;
135 153
136#ifdef HAVE_RECORDER_KEYPAD 154#ifdef HAVE_RECORDER_KEYPAD
diff --git a/apps/menu.h b/apps/menu.h
index 5aafe9bf9a..accfbda267 100644
--- a/apps/menu.h
+++ b/apps/menu.h
@@ -26,7 +26,8 @@ struct menu_items {
26 void (*function) (void); 26 void (*function) (void);
27}; 27};
28 28
29void menu_init(struct menu_items* items, int count); 29int menu_init(struct menu_items* items, int count);
30void menu_run(void); 30void menu_exit(int menu);
31void menu_run(int menu);
31 32
32#endif /* End __MENU_H__ */ 33#endif /* End __MENU_H__ */