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

View file

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

View file

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

View file

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

View file

@ -232,3 +232,14 @@ bool clean_shutdown(void)
#endif #endif
return false; 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 settings_parseline(char* line, char** name, char** value);
bool clean_shutdown(void); bool clean_shutdown(void);
int default_event_handler(int button);
#endif #endif

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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