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
|
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2002-05-21 14:25:45 +00:00
|
|
|
lcd_puts(0, cursor, "-");
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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();
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void menu_draw(void)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
redraw_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
|
|
|
|
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:
|
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-21 14:25:45 +00:00
|
|
|
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;
|
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
|
|
|
}
|