1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* Copyright (C) 2002 Robert E. Hak
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "lcd.h"
#include "menu.h"
#include "button.h"
#include "kernel.h"
#include "debug.h"
/* Global values for menuing */
static int menu_top;
static int menu_bottom;
static int cursor;
static struct menu_items* items;
static int itemcount;
/*
* Move the cursor to a particular id,
* target: where you want it to be
*/
void put_cursor(int target)
{
lcd_puts(0, cursor, " ");
cursor = target;
lcd_puts(0, cursor, "-");
}
int is_cursor_menu_top(void)
{
return ((cursor == menu_top) ? 1 : 0);
}
int is_cursor_menu_bottom(void)
{
return ((cursor == menu_bottom) ? 1 : 0);
}
void put_cursor_menu_top(void)
{
put_cursor(menu_top);
}
void put_cursor_menu_bottom(void)
{
put_cursor(menu_bottom);
}
void move_cursor_up(void)
{
put_cursor(cursor-1);
}
void move_cursor_down(void)
{
put_cursor(cursor+1);
}
void redraw_cursor(void)
{
lcd_puts(0, cursor, "-");
}
/* We call the function pointer related to the current cursor position */
void execute_menu_item(void)
{
/* call the proper function for this line */
items[cursor].function();
}
void menu_init(struct menu_items* mitems, int count)
{
items = mitems;
itemcount = count;
menu_top = items[0].id;
menu_bottom = count-1;
cursor = menu_top;
}
void menu_draw(void)
{
int i = 0;
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(0,0);
lcd_setfont(0);
#endif
for (i = 0; i < itemcount; i++) {
lcd_puts(1, i, items[i].desc);
if (i < menu_top)
menu_top = i;
if (i > menu_bottom)
menu_bottom = i;
}
redraw_cursor();
lcd_update();
}
void menu_run(void)
{
int key;
menu_draw();
while(1) {
key = button_get();
if(!key) {
sleep(1);
continue;
}
switch(key) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_LEFT:
#endif
if(is_cursor_menu_top()){
/* wrap around to menu bottom */
put_cursor_menu_bottom();
} else {
/* move up */
move_cursor_up();
}
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_RIGHT:
#endif
if(is_cursor_menu_bottom() ){
/* wrap around to menu top */
put_cursor_menu_top();
} else {
/* move down */
move_cursor_down();
}
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_RIGHT:
#endif
case BUTTON_PLAY:
/* Erase current display state */
lcd_clear_display();
execute_menu_item();
/* Return to previous display state */
menu_draw();
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
#endif
return;
default:
break;
}
lcd_update();
}
}
|