Remade the menu system slightly. All functions invoked from menus now use

the Menu typedef as return type, and *ALL* menus that intercept USB connect
can then return MENU_REFRESH_DIR so that the parent (any parent really) that
do file or dir-accesses knows that and can do the refresh. If no refresh
is needed by the parent, MENU_OK is returned.

Somewhat biggish commit this close to 1.3, but we need to sort out this
refresh-after-usb-connected business.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1948 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Daniel Stenberg 2002-08-23 12:32:52 +00:00
parent ad4a92eb87
commit b285076925
23 changed files with 175 additions and 89 deletions

View file

@ -15,7 +15,7 @@ OC = sh-elf-objcopy
FIRMWARE := ../firmware
INCLUDES= -I$(FIRMWARE)/include -I$(FIRMWARE) -I$(FIRMWARE)/common -I$(FIRMWARE)/drivers -I$(FIRMWARE)/malloc
INCLUDES= -I$(FIRMWARE)/include -I$(FIRMWARE) -I$(FIRMWARE)/common -I$(FIRMWARE)/drivers -I$(FIRMWARE)/malloc -I.
# Pick a target to build for
#TARGET = -DARCHOS_PLAYER=1

View file

@ -82,7 +82,7 @@ void dbg_os(void)
}
}
#else
void dbg_os(void)
Menu dbg_os(void)
{
char buf[32];
int button;
@ -109,7 +109,7 @@ void dbg_os(void)
switch(button)
{
case BUTTON_STOP:
return;
return MENU_OK;
case BUTTON_LEFT:
currval--;
@ -124,12 +124,13 @@ void dbg_os(void)
break;
}
}
return MENU_OK;
}
#endif
#ifdef HAVE_LCD_BITMAP
/* Test code!!! */
void dbg_ports(void)
Menu dbg_ports(void)
{
unsigned short porta;
unsigned short portb;
@ -199,12 +200,13 @@ void dbg_ports(void)
case BUTTON_LEFT:
charger_enable(false);
ide_power_enable(true);
return;
return MENU_OK;
}
}
return MENU_OK;
}
#else
void dbg_ports(void)
Menu dbg_ports(void)
{
unsigned short porta;
unsigned short portb;
@ -280,7 +282,7 @@ void dbg_ports(void)
switch(button)
{
case BUTTON_STOP:
return;
return MENU_OK;
case BUTTON_LEFT:
currval--;
@ -295,12 +297,13 @@ void dbg_ports(void)
break;
}
}
return MENU_OK;
}
#endif
#ifdef HAVE_RTC
/* Read RTC RAM contents and display them */
void dbg_rtc(void)
Menu dbg_rtc(void)
{
char buf[32];
unsigned char addr = 0, r, c;
@ -344,14 +347,15 @@ void dbg_rtc(void)
break;
case BUTTON_OFF:
case BUTTON_LEFT:
return;
return MENU_OK;
}
}
return MENU_OK;
}
#else
void dbg_rtc(void)
Menu dbg_rtc(void)
{
return;
return MENU_OK;
}
#endif
@ -361,7 +365,7 @@ void dbg_rtc(void)
#define NUMROWS 4
#endif
/* Read MAS registers and display them */
void dbg_mas(void)
Menu dbg_mas(void)
{
char buf[32];
unsigned int addr = 0, r, i;
@ -405,13 +409,14 @@ void dbg_mas(void)
#else
case BUTTON_DOWN:
#endif
return;
return MENU_OK;
}
}
return MENU_OK;
}
#ifdef HAVE_MAS3587F
void dbg_mas_codec(void)
Menu dbg_mas_codec(void)
{
char buf[32];
unsigned int addr = 0, r, i;
@ -442,9 +447,10 @@ void dbg_mas_codec(void)
if (addr) { addr -= 4; }
break;
case BUTTON_LEFT:
return;
return MENU_OK;
}
}
return MENU_OK;
}
#endif
@ -458,7 +464,7 @@ void dbg_mas_codec(void)
#define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
#define BAT_YSPACE (LCD_HEIGHT - 20)
void view_battery(void)
Menu view_battery(void)
{
int view = 0;
int i, x, y;
@ -579,15 +585,16 @@ void view_battery(void)
case BUTTON_LEFT:
case BUTTON_OFF:
return;
return MENU_OK;
}
}
return MENU_OK;
}
#endif
#ifdef HAVE_MAS3507D
void dbg_mas_info(void)
Menu dbg_mas_info(void)
{
int button;
char buf[32];
@ -721,7 +728,7 @@ void dbg_mas_info(void)
switch(button)
{
case BUTTON_STOP:
return;
return MENU_OK;
case BUTTON_LEFT:
currval--;
@ -757,12 +764,14 @@ void dbg_mas_info(void)
break;
}
}
return MENU_OK;
}
#endif
void debug_menu(void)
Menu debug_menu(void)
{
int m;
Menu result;
struct menu_items items[] = {
{ "View I/O ports", dbg_ports },
@ -785,8 +794,10 @@ void debug_menu(void)
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
menu_run(m);
result = menu_run(m);
menu_exit(m);
return result;
}
#endif /* SIMULATOR */

View file

@ -19,12 +19,12 @@
#ifndef _DEBUG_MENU_H
#define _DEBUG_MENU_H
void debug_menu(void);
Menu debug_menu(void);
#ifndef SIMULATOR
extern void dbg_ports(void);
extern Menu dbg_ports(void);
#ifdef HAVE_RTC
extern void dbg_rtc(void);
extern Menu dbg_rtc(void);
#endif
#endif

View file

@ -29,11 +29,12 @@
#include "sprintf.h"
#include "sokoban.h"
extern void tetris(void);
extern Menu tetris(void);
void games_menu(void)
Menu games_menu(void)
{
int m;
Menu result;
struct menu_items items[] = {
{ "Tetris", tetris },
@ -41,10 +42,10 @@ void games_menu(void)
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
menu_run(m);
result = menu_run(m);
menu_exit(m);
return result;
}
#endif

View file

@ -19,6 +19,8 @@
#ifndef _GAMES_MENU_H
#define _GAMES_MENU_H
void games_menu(void);
#include "menu.h"
Menu games_menu(void);
#endif

View file

@ -105,7 +105,7 @@ int show_logo( void )
return 0;
}
void show_credits(void)
Menu show_credits(void)
{
int j = 0;
int btn;
@ -120,22 +120,23 @@ void show_credits(void)
btn = button_get(false);
if (btn != BUTTON_NONE && !(btn & BUTTON_REL))
return;
return MENU_OK;
}
roll_credits();
return MENU_OK;
}
#ifdef SIMULATOR
#define mp3buf 0
#define mp3end 0
extern void simulate_usb(void);
extern Menu simulate_usb(void);
#else
/* defined in linker script */
extern unsigned char mp3buf[];
extern unsigned char mp3end[];
#endif
void show_info(void)
Menu show_info(void)
{
char s[32];
int buflen = ((mp3end - mp3buf) * 100) / 0x100000;
@ -181,11 +182,14 @@ void show_info(void)
if(button_get(false) & ~BUTTON_REL)
done = true;
}
return MENU_OK;
}
void main_menu(void)
Menu main_menu(void)
{
int m;
Menu result;
/* main menu */
struct menu_items items[] = {
@ -208,11 +212,13 @@ void main_menu(void)
#ifdef HAVE_LCD_CHARCELLS
lcd_icon(ICON_PARAM, true);
#endif
menu_run(m);
result = menu_run(m);
#ifdef HAVE_LCD_CHARCELLS
lcd_icon(ICON_PARAM, false);
#endif
menu_exit(m);
settings_save();
return result;
}

View file

@ -19,7 +19,9 @@
#ifndef _MAIN_MENU_H
#define _MAIN_MENU_H
#include "menu.h"
extern int show_logo(void);
extern void main_menu(void);
extern Menu main_menu(void);
#endif

View file

@ -212,13 +212,14 @@ void menu_exit(int m)
inuse[m] = false;
}
void menu_run(int m)
Menu menu_run(int m)
{
#ifndef SIMULATOR
#ifdef HAVE_LCD_BITMAP
bool laststate;
#endif
#endif
Menu result = MENU_OK;
menu_draw(m);
@ -273,7 +274,7 @@ void menu_run(int m)
case BUTTON_MENU:
#endif
lcd_stop_scroll();
return;
return result;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_F3:
@ -298,6 +299,7 @@ void menu_run(int m)
#else
lcd_icon(ICON_PARAM, true);
#endif
result = MENU_REFRESH_DIR;
break;
#endif
@ -308,4 +310,6 @@ void menu_run(int m)
status_draw();
lcd_update();
}
return result;
}

View file

@ -22,15 +22,23 @@
#include <stdbool.h>
typedef enum {
MENU_OK,
MENU_REFRESH_DIR, /* any file/directory contents need to be re-read */
MENU_LAST /* don't use as return code, only for number of return codes
available */
} Menu;
struct menu_items {
char *desc;
void (*function) (void);
Menu (*function) (void);
};
int menu_init(struct menu_items* items, int count);
void menu_exit(int menu);
void menu_run(int menu);
void put_cursorxy(int x, int y, bool on);
Menu menu_run(int menu);
#endif /* End __MENU_H__ */

View file

@ -24,6 +24,7 @@
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#include "menu.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -33,7 +34,7 @@
#define SS_TITLE "Blank"
#define SS_TITLE_FONT 2
void blank(void)
Menu blank(void)
{
int w, h;
char *off = "[Off] to stop";
@ -76,15 +77,16 @@ void blank(void)
lcd_update();
sleep(HZ);
lcd_clear_display();
lcd_clear_display();
lcd_update();
while(1) {
if(button_get(false))
return;
while(1) {
if(button_get(false))
return MENU_OK;
sleep(HZ/10);
}
}
return MENU_OK;
}
#endif

View file

@ -24,6 +24,7 @@
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#include "menu.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -83,7 +84,7 @@ static void loopit(void)
}
void bounce(void)
Menu bounce(void)
{
int w, h;
char *off = "[Off] to stop";
@ -126,6 +127,8 @@ void bounce(void)
lcd_update();
sleep(HZ);
loopit();
return MENU_OK;
}
#endif

View file

@ -25,6 +25,7 @@
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#include "menu.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -82,7 +83,7 @@ static void ss_loop(void)
}
}
void boxes(void)
Menu boxes(void)
{
int w, h;
char *off = "[Off] to stop";
@ -125,6 +126,8 @@ void boxes(void)
lcd_update();
sleep(HZ/2);
ss_loop();
return MENU_OK;
}
#endif

View file

@ -20,7 +20,9 @@
#ifndef __BOXES_H__
#define __BOXES_H__
void boxes(void);
#include "menu.h"
Menu boxes(void);
#endif /* __BOXES_H__ */

View file

@ -23,6 +23,7 @@
#include "lcd.h"
#include "button.h"
#include "kernel.h"
#include "menu.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -1334,7 +1335,7 @@ void sokoban_loop(void) {
}
void sokoban(void)
Menu sokoban(void)
{
int w, h;
int len = strlen(SOKOBAN_TITLE);
@ -1371,4 +1372,6 @@ void sokoban(void)
sleep(HZ*2);
lcd_clear_display();
sokoban_loop();
return MENU_OK;
}

View file

@ -20,10 +20,12 @@
#ifndef __SOKOBAN__
#define __SOKOBAN__
#include "menu.h"
void load_level(int);
void update_screen(void);
void sokoban_loop(void);
void sokoban(void);
Menu sokoban(void);
#endif /*__SOKOBAN__ */

View file

@ -27,6 +27,7 @@
#include "button.h"
#include "kernel.h"
#include <string.h>
#include "menu.h"
#ifdef SIMULATOR
#include <stdio.h>
@ -388,7 +389,7 @@ void init_tetris(void)
next_f = 0;
}
void tetris(void)
Menu tetris(void)
{
init_tetris();
@ -400,6 +401,8 @@ void tetris(void)
next_f = t_rand(block_frames[next_b]);
new_block();
game_loop();
return MENU_OK;
}
#endif

View file

@ -30,12 +30,13 @@
#include "sprintf.h"
#include "boxes.h"
extern void bounce(void);
extern void blank(void);
extern Menu bounce(void);
extern Menu blank(void);
void screensavers_menu(void)
Menu screensavers_menu(void)
{
int m;
Menu result;
struct menu_items items[] = {
{ "Boxes", boxes },
@ -44,8 +45,10 @@ void screensavers_menu(void)
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
menu_run(m);
result = menu_run(m);
menu_exit(m);
return result;
}
#endif

View file

@ -19,7 +19,7 @@
#ifndef _SCREENSAVERS_MENU_H
#define _SCREENSAVERS_MENU_H
void screensavers_menu(void);
Menu screensavers_menu(void);
#endif

View file

@ -36,39 +36,45 @@
#include "powermgmt.h"
#include "rtc.h"
static void show_hidden_files(void)
static Menu show_hidden_files(void)
{
set_bool( "[Show hidden files]", &global_settings.show_hidden_files );
return MENU_OK;
}
static void contrast(void)
static Menu contrast(void)
{
set_int( "[Contrast]", "", &global_settings.contrast,
lcd_set_contrast, 1, 0, MAX_CONTRAST_SETTING );
return MENU_OK;
}
static void shuffle(void)
static Menu shuffle(void)
{
set_bool( "[Shuffle]", &global_settings.playlist_shuffle );
return MENU_OK;
}
static void mp3_filter(void)
static Menu mp3_filter(void)
{
set_bool( "[MP3/M3U filter]", &global_settings.mp3filter );
return MENU_OK;
}
static void sort_case(void)
static Menu sort_case(void)
{
set_bool( "[Sort case sensitive]", &global_settings.sort_case );
return MENU_OK;
}
static void resume(void)
static Menu resume(void)
{
char* names[] = { "off", "ask", "on " };
set_option( "[Resume]", &global_settings.resume, names, 3 );
return MENU_OK;
}
static void backlight_timer(void)
static Menu backlight_timer(void)
{
char* names[] = { "off", "on ",
"1s ", "2s ", "3s ", "4s ", "5s ",
@ -77,15 +83,17 @@ static void backlight_timer(void)
"60s", "90s"};
set_option("[Backlight]", &global_settings.backlight, names, 19 );
backlight_time(global_settings.backlight);
return MENU_OK;
}
static void scroll_speed(void)
static Menu scroll_speed(void)
{
set_int("Scroll speed indicator...", "", &global_settings.scroll_speed,
&lcd_scroll_speed, 1, 1, 20 );
return MENU_OK;
}
static void wps_set(void)
static Menu wps_set(void)
{
#ifdef HAVE_LCD_BITMAP
char* names[] = { "ID3 Tags", "File ", "Parse " };
@ -102,18 +110,20 @@ static void wps_set(void)
#endif
#endif
return MENU_OK;
}
#ifdef HAVE_CHARGE_CTRL
static void deep_discharge(void)
static Menu deep_discharge(void)
{
set_bool( "[Deep discharge]", &global_settings.discharge );
charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
return MENU_OK;
}
#endif
#ifdef HAVE_RTC
static void timedate_set(void)
static Menu timedate_set(void)
{
int timedate[7]; /* hour,minute,second,year,month,day,dayofweek */
@ -150,24 +160,28 @@ static void timedate_set(void)
rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0xf8)); /* dayofweek */
rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */
}
return MENU_OK;
}
#endif
static void ff_rewind(void)
static Menu ff_rewind(void)
{
set_int("[FF/Rewind Step Size]", "s", &global_settings.ff_rewind,
NULL, 1, 1, 999 );
return MENU_OK;
}
void settings_menu(void)
Menu settings_menu(void)
{
int m;
Menu result;
struct menu_items items[] = {
{ "Shuffle", shuffle },
{ "MP3/M3U filter", mp3_filter },
{ "Sort mode", sort_case },
{ "Backlight Timer", backlight_timer },
{ "Contrast", contrast },
{ "Contrast", contrast },
{ "Scroll speed", scroll_speed },
{ "While Playing", wps_set },
#ifdef HAVE_CHARGE_CTRL
@ -183,7 +197,7 @@ void settings_menu(void)
bool old_shuffle = global_settings.playlist_shuffle;
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
menu_run(m);
result = menu_run(m);
menu_exit(m);
if (old_shuffle != global_settings.playlist_shuffle)
@ -197,4 +211,5 @@ void settings_menu(void)
sort_playlist();
}
}
return result;
}

View file

@ -19,6 +19,8 @@
#ifndef _SETTINGS_MENU_H
#define _SETTINGS_MENU_H
void settings_menu(void);
#include "menu.h"
Menu settings_menu(void);
#endif

View file

@ -145,48 +145,56 @@ void set_sound(char* string,
lcd_stop_scroll();
}
static void volume(void)
static Menu volume(void)
{
set_sound("Volume", &global_settings.volume, SOUND_VOLUME);
return MENU_OK;
}
static void balance(void)
static Menu balance(void)
{
set_sound("Balance", &global_settings.balance, SOUND_BALANCE);
return MENU_OK;
}
static void bass(void)
static Menu bass(void)
{
set_sound("Bass", &global_settings.bass, SOUND_BASS);
return MENU_OK;
};
static void treble(void)
static Menu treble(void)
{
set_sound("Treble", &global_settings.treble, SOUND_TREBLE);
return MENU_OK;
}
#ifdef HAVE_MAS3587F
static void loudness(void)
static Menu loudness(void)
{
set_sound("Loudness", &global_settings.loudness, SOUND_LOUDNESS);
return MENU_OK;
};
static void bass_boost(void)
static Menu bass_boost(void)
{
set_sound("Bass boost", &global_settings.bass_boost, SOUND_SUPERBASS);
return MENU_OK;
};
static void avc(void)
static Menu avc(void)
{
char* names[] = { "off", "2s ", "4s ", "8s " };
set_option("[AV decay time]", &global_settings.avc, names, 4 );
mpeg_sound_set(SOUND_AVC, global_settings.avc);
return MENU_OK;
}
#endif /* ARCHOS_RECORDER */
void sound_menu(void)
Menu sound_menu(void)
{
int m;
Menu result;
struct menu_items items[] = {
{ "Volume", volume },
{ "Bass", bass },
@ -200,6 +208,8 @@ void sound_menu(void)
};
m=menu_init( items, sizeof items / sizeof(struct menu_items) );
menu_run(m);
result = menu_run(m);
menu_exit(m);
return result;
}

View file

@ -19,6 +19,8 @@
#ifndef _SOUND_MENU_H
#define _SOUND_MENU_H
void sound_menu(void);
#include "menu.h"
Menu sound_menu(void);
#endif

View file

@ -640,13 +640,15 @@ bool dirbrowse(char *root)
bool lastfilter = global_settings.mp3filter;
bool lastsortcase = global_settings.sort_case;
bool show_hidden_files = global_settings.show_hidden_files;
Menu result;
lcd_stop_scroll();
main_menu();
result = main_menu();
/* do we need to rescan dir? */
if ( lastfilter != global_settings.mp3filter ||
lastsortcase != global_settings.sort_case ||
show_hidden_files != global_settings.show_hidden_files)
if (result == MENU_REFRESH_DIR ||
lastfilter != global_settings.mp3filter ||
lastsortcase != global_settings.sort_case ||
show_hidden_files != global_settings.show_hidden_files)
lastdir[0] = 0;
restore = true;
break;