From ade5d7b848bf9c0d46bb14c85528453f969c9429 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Mon, 26 Jul 2004 16:06:59 +0000 Subject: [PATCH] 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 --- apps/bookmark.c | 37 +++++++++++++---------------- apps/debug_menu.c | 10 ++++---- apps/main_menu.c | 7 +++--- apps/menu.c | 11 ++++----- apps/misc.c | 11 +++++++++ apps/misc.h | 1 + apps/playlist_viewer.c | 15 +++++++----- apps/recorder/keyboard.c | 18 ++++++++------ apps/recorder/radio.c | 6 ++++- apps/recorder/recording.c | 28 +++++++++++++++------- apps/screens.c | 30 +++++++++++++++--------- apps/settings.c | 15 ++++++------ apps/settings_menu.c | 11 +++++---- apps/sound_menu.c | 12 ++++++---- apps/tree.c | 30 ++++++++++-------------- apps/wps.c | 49 ++++++++++++++++++++++----------------- 16 files changed, 169 insertions(+), 122 deletions(-) diff --git a/apps/bookmark.c b/apps/bookmark.c index 993ea7e0ca..8d60de28fe 100644 --- a/apps/bookmark.c +++ b/apps/bookmark.c @@ -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; } } diff --git a/apps/debug_menu.c b/apps/debug_menu.c index b89b4e4ce3..f7a96dcd3d 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -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; diff --git a/apps/main_menu.c b/apps/main_menu.c index 991a1681de..b3c70a2c13 100644 --- a/apps/main_menu.c +++ b/apps/main_menu.c @@ -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; } } diff --git a/apps/menu.c b/apps/menu.c index 72e4289fc5..5e8a51200a 100644 --- a/apps/menu.c +++ b/apps/menu.c @@ -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); diff --git a/apps/misc.c b/apps/misc.c index 16719ad13a..6d45a64023 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -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; +} diff --git a/apps/misc.h b/apps/misc.h index 7815bd2183..097b6cce60 100644 --- a/apps/misc.h +++ b/apps/misc.h @@ -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 diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index 4b9a3e3752..e5d95495fa 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -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) diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index 32a1d8b735..0331a5711d 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c @@ -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); diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 36847236e1..e26ac5bdc8 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -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(); diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c index a077c957a7..242351a0d6 100644 --- a/apps/recorder/recording.c +++ b/apps/recorder/recording.c @@ -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; } } diff --git a/apps/screens.c b/apps/screens.c index 4d48372890..80b8484e35 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -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 diff --git a/apps/settings.c b/apps/settings.c index 31d9232851..83d69710df 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -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) { diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 5da733c1df..1141361281 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -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; } } diff --git a/apps/sound_menu.c b/apps/sound_menu.c index 4c9087e5f5..6f62ce2417 100644 --- a/apps/sound_menu.c +++ b/apps/sound_menu.c @@ -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); diff --git a/apps/tree.c b/apps/tree.c index 72a2261024..9ce5a9c5f0 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -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 ) diff --git a/apps/wps.c b/apps/wps.c index 8943a4d2fb..86ce4b09c1 100644 --- a/apps/wps.c +++ b/apps/wps.c @@ -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)