2002-05-17 12:22:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* 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"
|
2002-05-21 14:25:45 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#include "debug.h"
|
2002-05-17 12:22:24 +00:00
|
|
|
|
|
|
|
/* Global values for menuing */
|
2002-05-21 14:25:45 +00:00
|
|
|
static int menu_top;
|
|
|
|
static int menu_bottom;
|
|
|
|
static int cursor;
|
|
|
|
static struct menu_items* items;
|
|
|
|
static int itemcount;
|
2002-05-17 12:22:24 +00:00
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
/*
|
|
|
|
* Move the cursor to a particular id,
|
|
|
|
* target: where you want it to be
|
|
|
|
*/
|
2002-05-23 14:11:42 +00:00
|
|
|
static void put_cursor(int target)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-21 14:25:45 +00:00
|
|
|
lcd_puts(0, cursor, " ");
|
|
|
|
cursor = target;
|
|
|
|
lcd_puts(0, cursor, "-");
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* We call the function pointer related to the current cursor position */
|
2002-05-23 14:11:42 +00:00
|
|
|
static void execute_menu_item(void)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
|
|
|
/* call the proper function for this line */
|
|
|
|
items[cursor].function();
|
|
|
|
}
|
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
void menu_init(struct menu_items* mitems, int count)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-21 14:25:45 +00:00
|
|
|
items = mitems;
|
|
|
|
itemcount = count;
|
|
|
|
menu_top = items[0].id;
|
|
|
|
menu_bottom = count-1;
|
2002-05-17 12:22:24 +00:00
|
|
|
cursor = menu_top;
|
|
|
|
}
|
|
|
|
|
2002-05-23 14:11:42 +00:00
|
|
|
static void menu_draw(void)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
|
2002-05-21 15:04:23 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
lcd_setmargins(0,0);
|
|
|
|
lcd_setfont(0);
|
|
|
|
#endif
|
2002-05-21 14:25:45 +00:00
|
|
|
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;
|
|
|
|
}
|
2002-05-17 12:22:24 +00:00
|
|
|
|
2002-05-23 14:11:42 +00:00
|
|
|
lcd_puts(0, cursor, "-");
|
2002-05-21 14:25:45 +00:00
|
|
|
lcd_update();
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
void menu_run(void)
|
2002-05-18 11:41:37 +00:00
|
|
|
{
|
2002-05-21 14:25:45 +00:00
|
|
|
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
|
2002-05-23 14:11:42 +00:00
|
|
|
if (cursor == menu_top) {
|
2002-05-21 14:25:45 +00:00
|
|
|
/* wrap around to menu bottom */
|
2002-05-23 14:11:42 +00:00
|
|
|
put_cursor(menu_bottom);
|
2002-05-21 14:25:45 +00:00
|
|
|
} else {
|
|
|
|
/* move up */
|
2002-05-23 14:11:42 +00:00
|
|
|
put_cursor(cursor-1);
|
2002-05-21 14:25:45 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_DOWN:
|
2002-05-18 11:41:37 +00:00
|
|
|
#else
|
2002-05-21 14:25:45 +00:00
|
|
|
case BUTTON_RIGHT:
|
2002-05-18 11:41:37 +00:00
|
|
|
#endif
|
2002-05-23 14:11:42 +00:00
|
|
|
if (cursor == menu_bottom) {
|
2002-05-21 14:25:45 +00:00
|
|
|
/* wrap around to menu top */
|
2002-05-23 14:11:42 +00:00
|
|
|
put_cursor(menu_top);
|
2002-05-21 14:25:45 +00:00
|
|
|
} else {
|
|
|
|
/* move down */
|
2002-05-23 14:11:42 +00:00
|
|
|
put_cursor(cursor+1);
|
2002-05-21 14:25:45 +00:00
|
|
|
}
|
|
|
|
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;
|
2002-05-21 08:47:34 +00:00
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
}
|
2002-05-18 11:41:37 +00:00
|
|
|
}
|