First step in revamping the USB event handling, paving the way for the upcoming SYS_POWER_OFF event

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4951 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2004-07-26 16:06:59 +00:00
parent 3d91885718
commit ade5d7b848
16 changed files with 169 additions and 122 deletions

View file

@ -45,6 +45,7 @@
#include "kernel.h"
#include "sprintf.h"
#include "talk.h"
#include "misc.h"
#define MAX_BOOKMARKS 10
#define MAX_BOOKMARK_SIZE 350
@ -277,12 +278,10 @@ bool bookmark_autobookmark(void)
done = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
#ifdef HAVE_LCD_CHARCELLS
status_set_param(true);
#endif
return false;
default:
if(default_event_handler(key) == SYS_USB_CONNECTED)
return false;
break;
}
}
return true;
@ -511,25 +510,23 @@ bool bookmark_autoload(char* file)
while(!done)
{
button_clear_queue();
/* Wait for a key to be pushed */
while (button_get(false)); /* clear button queue */
key = button_get(true);
switch(key)
{
default:
return false;
#ifdef HAVE_LCD_BITMAP
case BUTTON_DOWN:
return bookmark_load(global_bookmark_file_name, false);
#endif
case BUTTON_PLAY:
return bookmark_load(global_bookmark_file_name, true);
case SYS_USB_CONNECTED:
usb_screen();
#ifdef HAVE_LCD_CHARCELLS
status_set_param(true);
#endif
return true;
default:
if(default_event_handler(key) == SYS_USB_CONNECTED)
return true;
return false;
}
}
return true;
@ -690,12 +687,6 @@ static char* select_bookmark(char* bookmark_file_name)
while (button_get(false)); /* clear button queue */
break;
case SYS_USB_CONNECTED:
usb_screen();
#ifdef HAVE_LCD_CHARCELLS
status_set_param(true);
#endif
return NULL;
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
bookmark_id--;
@ -726,6 +717,10 @@ static char* select_bookmark(char* bookmark_file_name)
case BUTTON_STOP:
return NULL;
#endif
default:
if(default_event_handler(key) == SYS_USB_CONNECTED)
return NULL;
break;
}
}

View file

@ -46,6 +46,7 @@
#include "dir.h"
#include "panic.h"
#include "screens.h"
#include "misc.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
#include "peakmeter.h"
@ -520,10 +521,11 @@ bool dbg_partitions(void)
if (partition > 3)
partition = 0;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
}
return false;

View file

@ -249,9 +249,10 @@ bool show_info(void)
state = 1;
break;
#endif
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(key) == SYS_USB_CONNECTED)
return true;
break;
}
}

View file

@ -34,6 +34,7 @@
#include "screens.h"
#include "talk.h"
#include "lang.h"
#include "misc.h"
#ifdef HAVE_LCD_BITMAP
#include "icons.h"
@ -373,12 +374,10 @@ int menu_show(int m)
exit = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
#ifdef HAVE_LCD_CHARCELLS
status_set_param(false);
#endif
return MENU_ATTACHED_USB;
default:
if(default_event_handler(key) == SYS_USB_CONNECTED)
return MENU_ATTACHED_USB;
break;
}
status_draw(false);

View file

@ -232,3 +232,14 @@ bool clean_shutdown(void)
#endif
return false;
}
int default_event_handler(int button)
{
switch(button)
{
case SYS_USB_CONNECTED:
usb_screen();
return SYS_USB_CONNECTED;
}
return 0;
}

View file

@ -40,5 +40,6 @@ void screen_dump(void);
bool settings_parseline(char* line, char** name, char** value);
bool clean_shutdown(void);
int default_event_handler(int button);
#endif

View file

@ -32,6 +32,7 @@
#include "tree.h"
#include "onplay.h"
#include "talk.h"
#include "misc.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
@ -1045,15 +1046,17 @@ bool playlist_viewer_ex(char* filename)
update = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
ret = true;
goto exit;
break;
case BUTTON_NONE:
status_draw(false);
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
{
ret = true;
goto exit;
}
break;
}
if (update && !exit)

View file

@ -28,6 +28,7 @@
#include "status.h"
#include "talk.h"
#include "settings.h"
#include "misc.h"
#define KEYBOARD_LINES 4
#define KEYBOARD_PAGES 3
@ -89,6 +90,7 @@ int kbd_input(char* text, int buflen)
char outline[256];
char c = 0;
struct font* font = font_get(FONT_SYSFIXED);
int button;
lcd_setfont(FONT_SYSFIXED);
font_w = font->maxwidth;
@ -193,8 +195,9 @@ int kbd_input(char* text, int buflen)
/* The default action is to redraw */
redraw = true;
switch ( button_get_w_tmo(HZ/2) ) {
button = button_get_w_tmo(HZ/2);
switch ( button ) {
case BUTTON_OFF:
/* abort */
@ -309,15 +312,16 @@ int kbd_input(char* text, int buflen)
kbd_spellchar(text[editpos]);
break;
case SYS_USB_CONNECTED:
usb_screen();
lcd_setfont(FONT_SYSFIXED);
break;
case BUTTON_NONE:
status_draw(false);
redraw = false;
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
lcd_setfont(FONT_SYSFIXED);
break;
}
}
lcd_setfont(FONT_UI);

View file

@ -416,13 +416,17 @@ bool radio_screen(void)
/* Only accept USB connection when not recording */
if(mpeg_status() != MPEG_STATUS_RECORD)
{
usb_screen();
default_event_handler(SYS_USB_CONNECTED);
fmradio_set_status(0);
screen_freeze = true; /* Cosmetic: makes sure the
radio screen doesn't redraw */
done = true;
}
break;
default:
default_event_handler(button);
break;
}
peak_meter_peek();

View file

@ -437,11 +437,15 @@ bool recording_screen(void)
/* Only accept USB connection when not recording */
if(mpeg_status() != MPEG_STATUS_RECORD)
{
usb_screen();
default_event_handler(SYS_USB_CONNECTED);
done = true;
been_in_usb_mode = true;
}
break;
default:
default_event_handler(button);
break;
}
peak_meter_peek();
@ -622,6 +626,7 @@ bool f2_rec_screen(void)
bool used = false;
int w, h;
char buf[32];
int button;
lcd_setfont(FONT_SYSFIXED);
lcd_getstringsize("A",&w,&h);
@ -671,7 +676,8 @@ bool f2_rec_screen(void)
lcd_update();
switch (button_get(true)) {
button = button_get(true);
switch (button) {
case BUTTON_LEFT:
case BUTTON_F2 | BUTTON_LEFT:
global_settings.rec_quality++;
@ -706,9 +712,10 @@ bool f2_rec_screen(void)
used = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
}
@ -735,6 +742,7 @@ bool f3_rec_screen(void)
bool exit = false;
bool used = false;
int w, h;
int button;
char *src_str[] =
{
str(LANG_RECORDING_SRC_MIC),
@ -760,7 +768,8 @@ bool f3_rec_screen(void)
lcd_update();
switch (button_get(true)) {
button = button_get(true);
switch (button) {
case BUTTON_LEFT:
case BUTTON_F3 | BUTTON_LEFT:
global_settings.rec_source++;
@ -779,9 +788,10 @@ bool f3_rec_screen(void)
used = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
}

View file

@ -288,6 +288,7 @@ int charging_screen(void)
2 if USB was connected */
int on_screen(void)
{
int button;
static int pitch = 1000;
bool exit = false;
bool used = false;
@ -329,7 +330,8 @@ int on_screen(void)
/* use lastbutton, so the main loop can decide whether to
exit to browser or not */
switch (button_get(true)) {
button = button_get(true);
switch (button) {
case BUTTON_UP:
case BUTTON_ON | BUTTON_UP:
case BUTTON_ON | BUTTON_UP | BUTTON_REPEAT:
@ -407,9 +409,10 @@ int on_screen(void)
used = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return 2;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return 2;
break;
}
}
@ -606,10 +609,11 @@ bool quick_screen(int context, int button)
case BUTTON_OFF | BUTTON_REPEAT:
return false;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(key) == SYS_USB_CONNECTED)
return true;
break;
}
}
@ -1082,9 +1086,10 @@ bool set_time_screen(char* string, struct tm *tm)
tm->tm_year = -1;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if (default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
}
@ -1112,6 +1117,9 @@ bool shutdown_screen(void)
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
/* Return if any other button was pushed, or if there
was a timeout. We ignore RELEASE events, since we may
have been called by a button down event, and the user might

View file

@ -1362,10 +1362,10 @@ bool set_int(char* string,
done = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
if(*variable > max )
*variable = max;
@ -1492,9 +1492,10 @@ bool set_option(char* string, void* variable, enum optiontype type,
done = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
if ( function && button != BUTTON_NONE) {

View file

@ -43,6 +43,7 @@
#include "screens.h"
#include "talk.h"
#include "timefuncs.h"
#include "misc.h"
#ifdef HAVE_LCD_BITMAP
#include "peakmeter.h"
#endif
@ -1037,6 +1038,7 @@ static bool reset_settings(void)
{
bool done=false;
int line;
int button;
lcd_clear_display();
@ -1052,7 +1054,8 @@ static bool reset_settings(void)
lcd_update();
while(!done) {
switch(button_get(true)) {
button = button_get(true);
switch(button) {
case BUTTON_PLAY:
settings_reset();
settings_apply();
@ -1071,9 +1074,9 @@ static bool reset_settings(void)
done = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
}
}

View file

@ -33,6 +33,7 @@
#include "lang.h"
#include "sprintf.h"
#include "talk.h"
#include "misc.h"
static char *fmt[] =
{
@ -56,6 +57,7 @@ bool set_sound(char* string,
char str[32];
int talkunit = UNIT_INT;
int steps;
int button;
unit = mpeg_sound_unit(setting);
numdec = mpeg_sound_numdecimals(setting);
@ -99,7 +101,8 @@ bool set_sound(char* string,
lcd_update();
changed = false;
switch( button_get_w_tmo(HZ/2) ) {
button = button_get_w_tmo(HZ/2);
switch( button ) {
#ifdef HAVE_RECORDER_KEYPAD
case BUTTON_UP:
case BUTTON_UP | BUTTON_REPEAT:
@ -136,9 +139,10 @@ bool set_sound(char* string,
done = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
if (changed) {
mpeg_sound_set(setting, *variable);

View file

@ -56,6 +56,7 @@
#include "action.h"
#include "talk.h"
#include "filetypes.h"
#include "misc.h"
#ifdef HAVE_LCD_BITMAP
#include "widgets.h"
@ -599,7 +600,7 @@ static bool ask_resume(bool ask_once)
#endif
if (usb_detect()) {
usb_screen();
default_event_handler(SYS_USB_CONNECTED);
return false;
}
@ -635,13 +636,8 @@ static bool ask_resume(bool ask_once)
case BUTTON_ON | BUTTON_REPEAT:
break;
#endif
case SYS_USB_CONNECTED:
usb_screen();
stop = true;
break;
default:
default_event_handler(button);
stop = true;
break;
}
@ -940,6 +936,7 @@ static bool dirbrowse(char *root, int *dirfilter)
#ifndef SIMULATOR
if (boot_changed) {
bool stop = false;
int button;
lcd_clear_display();
lcd_puts(0,0,str(LANG_BOOT_CHANGED));
@ -950,18 +947,15 @@ static bool dirbrowse(char *root, int *dirfilter)
lcd_update();
#endif
while (!stop) {
switch (button_get(true)) {
button = button_get(true);
switch (button) {
case BUTTON_PLAY:
rolo_load("/" BOOTFILE);
stop = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
stop = true;
break;
default:
default_event_handler(button);
stop = true;
break;
}
@ -1372,11 +1366,6 @@ static bool dirbrowse(char *root, int *dirfilter)
#endif
break;
case SYS_USB_CONNECTED:
usb_screen();
reload_root = true;
break;
case BUTTON_NONE:
if (thumbnail_time != -1 &&
TIME_AFTER(current_tick, thumbnail_time))
@ -1393,6 +1382,11 @@ static bool dirbrowse(char *root, int *dirfilter)
}
status_draw(false);
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
reload_root = true;
break;
}
if ( button )

View file

@ -48,6 +48,8 @@
#endif
#include "lang.h"
#include "bookmark.h"
#include "misc.h"
#define FF_REWIND_MAX_PERCENT 3 /* cap ff/rewind step size at max % of file */
/* 3% of 30min file == 54s step size */
#define MIN_FF_REWIND_STEP 500
@ -296,9 +298,9 @@ bool browse_id3(void)
exit = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return true;
break;
}
}
@ -419,11 +421,12 @@ static bool ffwd_rew(int button)
exit = true;
break;
case SYS_USB_CONNECTED:
status_set_ffmode(0);
usb_screen();
usb = true;
exit = true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED) {
status_set_ffmode(0);
usb = true;
exit = true;
}
break;
}
if (!exit)
@ -511,10 +514,12 @@ static bool menu(void)
while (button_get(false)); /* clear button queue */
break;
case SYS_USB_CONNECTED:
usb_screen();
keys_locked = false;
return true;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED) {
keys_locked = false;
return true;
}
break;
}
if (keys_locked) {
@ -754,19 +759,20 @@ int wps_show(void)
if (button && ignore_keyup)
{
ignore_keyup = false;
if (button & BUTTON_REL && button != SYS_USB_CONNECTED)
/* Negative events are system events */
if (button >= 0 && button & BUTTON_REL )
continue;
}
/* ignore non-remote buttons when keys are locked */
if (keys_locked &&
! ((button < 0) ||
#ifdef HAVE_RECORDER_KEYPAD
! ((button & BUTTON_F1) ||
(button & BUTTON_F1) ||
#else
! ((button & BUTTON_MENU) ||
(button & BUTTON_MENU) ||
#endif
(button == BUTTON_NONE) ||
(button == SYS_USB_CONNECTED)
(button == BUTTON_NONE)
#ifdef BUTTON_REMOTE
|| (button & BUTTON_REMOTE)
#endif
@ -970,13 +976,14 @@ int wps_show(void)
exit = true;
break;
case SYS_USB_CONNECTED:
usb_screen();
return SYS_USB_CONNECTED;
case BUTTON_NONE: /* Timeout */
update_track = true;
break;
default:
if(default_event_handler(button) == SYS_USB_CONNECTED)
return SYS_USB_CONNECTED;
break;
}
if (update_track)