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
|
/***************************************************************************
* __________ __ ___.
* 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 <stdbool.h>
#include "lcd.h"
#include "menu.h"
#include "button.h"
#include "kernel.h"
#include "debug.h"
struct menu {
int top;
int cursor;
struct menu_items* items;
int itemcount;
};
#define MAX_MENUS 4
#ifdef HAVE_LCD_BITMAP
#define MENU_LINES 6
#else
#define MENU_LINES 2
#endif
static struct menu menus[MAX_MENUS];
static bool inuse[MAX_MENUS] = { false };
static void menu_draw(int m)
{
int i = 0;
lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(0,0);
lcd_setfont(0);
#endif
for (i = menus[m].top;
(i < menus[m].itemcount) && (i<menus[m].top+MENU_LINES);
i++) {
lcd_puts(1, i-menus[m].top, menus[m].items[i].desc);
}
lcd_puts(0, menus[m].cursor - menus[m].top, "-");
lcd_update();
}
/*
* Move the cursor to a particular id,
* target: where you want it to be
*/
static void put_cursor(int m, int target)
{
lcd_puts(0, menus[m].cursor - menus[m].top, " ");
if ( target < menus[m].top ) {
menus[m].top--;
menu_draw(m);
}
else if ( target > MENU_LINES-1 ) {
menus[m].top++;
menu_draw(m);
}
menus[m].cursor = target;
lcd_puts(0, menus[m].cursor - menus[m].top, "-");
}
int menu_init(struct menu_items* mitems, int count)
{
int i;
for ( i=0; i<MAX_MENUS; i++ ) {
if ( !inuse[i] ) {
inuse[i] = true;
break;
}
}
if ( i == MAX_MENUS ) {
DEBUGF("Out of menus!\n");
return -1;
}
menus[i].items = mitems;
menus[i].itemcount = count;
menus[i].top = 0;
menus[i].cursor = 0;
return i;
}
void menu_exit(int m)
{
inuse[m] = false;
}
void menu_run(int m)
{
menu_draw(m);
while(1) {
switch( button_get(true) ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
#else
case BUTTON_LEFT:
#endif
if (menus[m].cursor == 0) {
/* wrap around to menu bottom */
put_cursor(m, menus[m].itemcount-1);
} else {
/* move up */
put_cursor(m, menus[m].cursor-1);
}
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_DOWN:
#else
case BUTTON_RIGHT:
#endif
if (menus[m].cursor == menus[m].itemcount-1) {
/* wrap around to menu top */
put_cursor(m, 0);
} else {
/* move down */
put_cursor(m, menus[m].cursor+1);
}
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_RIGHT:
#endif
case BUTTON_PLAY:
/* Erase current display state */
lcd_clear_display();
menus[m].items[menus[m].cursor].function();
/* Return to previous display state */
menu_draw(m);
break;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_LEFT:
#else
case BUTTON_STOP:
#endif
return;
default:
break;
}
lcd_update();
}
}
|