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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2002-05-26 17:03:17 +00:00
|
|
|
#include <stdbool.h>
|
2002-05-17 12:22:24 +00:00
|
|
|
#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
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
struct menu {
|
2002-05-28 15:35:33 +00:00
|
|
|
int top;
|
2002-05-26 17:03:17 +00:00
|
|
|
int cursor;
|
|
|
|
struct menu_items* items;
|
|
|
|
int itemcount;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_MENUS 4
|
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#define MENU_LINES 6
|
|
|
|
#else
|
|
|
|
#define MENU_LINES 2
|
|
|
|
#endif
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
static struct menu menus[MAX_MENUS];
|
|
|
|
static bool inuse[MAX_MENUS] = { false };
|
2002-05-17 12:22:24 +00:00
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
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);
|
|
|
|
}
|
2002-05-30 08:06:42 +00:00
|
|
|
|
|
|
|
/* place the cursor */
|
|
|
|
lcd_puts(0, menus[m].cursor - menus[m].top, "-");
|
|
|
|
|
2002-05-28 15:35:33 +00:00
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
2002-05-21 14:25:45 +00:00
|
|
|
/*
|
|
|
|
* Move the cursor to a particular id,
|
|
|
|
* target: where you want it to be
|
|
|
|
*/
|
2002-05-26 17:03:17 +00:00
|
|
|
static void put_cursor(int m, int target)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-30 08:06:42 +00:00
|
|
|
bool do_update = true;
|
|
|
|
|
|
|
|
lcd_puts(0, menus[m].cursor - menus[m].top, " ");
|
|
|
|
menus[m].cursor = target;
|
2002-05-28 15:35:33 +00:00
|
|
|
|
|
|
|
if ( target < menus[m].top ) {
|
|
|
|
menus[m].top--;
|
|
|
|
menu_draw(m);
|
2002-05-30 08:06:42 +00:00
|
|
|
do_update = false;
|
2002-05-28 15:35:33 +00:00
|
|
|
}
|
2002-05-29 14:25:06 +00:00
|
|
|
else if ( target-menus[m].top > MENU_LINES-1 ) {
|
2002-05-28 15:35:33 +00:00
|
|
|
menus[m].top++;
|
|
|
|
menu_draw(m);
|
2002-05-30 08:06:42 +00:00
|
|
|
do_update = false;
|
2002-05-28 15:35:33 +00:00
|
|
|
}
|
2002-05-30 08:06:42 +00:00
|
|
|
|
|
|
|
if (do_update) {
|
|
|
|
lcd_puts(0, menus[m].cursor - menus[m].top, "-");
|
|
|
|
lcd_update();
|
|
|
|
}
|
|
|
|
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
int menu_init(struct menu_items* mitems, int count)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
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;
|
2002-05-28 15:35:33 +00:00
|
|
|
menus[i].top = 0;
|
2002-05-26 17:03:17 +00:00
|
|
|
menus[i].cursor = 0;
|
|
|
|
|
|
|
|
return i;
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
void menu_exit(int m)
|
2002-05-17 12:22:24 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
inuse[m] = false;
|
2002-05-17 12:22:24 +00:00
|
|
|
}
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
void menu_run(int m)
|
2002-05-18 11:41:37 +00:00
|
|
|
{
|
2002-05-26 17:03:17 +00:00
|
|
|
menu_draw(m);
|
2002-05-21 14:25:45 +00:00
|
|
|
|
|
|
|
while(1) {
|
2002-05-28 12:10:12 +00:00
|
|
|
switch( button_get(true) ) {
|
2002-05-21 14:25:45 +00:00
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_UP:
|
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#endif
|
2002-05-29 14:25:06 +00:00
|
|
|
if (menus[m].cursor) {
|
2002-05-21 14:25:45 +00:00
|
|
|
/* move up */
|
2002-05-26 17:03:17 +00:00
|
|
|
put_cursor(m, menus[m].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-29 14:25:06 +00:00
|
|
|
if (menus[m].cursor < menus[m].itemcount-1) {
|
2002-05-21 14:25:45 +00:00
|
|
|
/* move down */
|
2002-05-26 17:03:17 +00:00
|
|
|
put_cursor(m, menus[m].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();
|
|
|
|
|
2002-05-26 17:03:17 +00:00
|
|
|
menus[m].items[menus[m].cursor].function();
|
2002-05-21 14:25:45 +00:00
|
|
|
|
|
|
|
/* Return to previous display state */
|
2002-05-26 17:03:17 +00:00
|
|
|
menu_draw(m);
|
2002-05-21 14:25:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
2002-05-29 12:28:08 +00:00
|
|
|
case BUTTON_MENU:
|
2002-05-21 14:25:45 +00:00
|
|
|
#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
|
|
|
}
|