From dc010201a5020b8b468a1a24a8fafb45a8986530 Mon Sep 17 00:00:00 2001 From: Teruaki Kawashima Date: Fri, 18 Dec 2009 14:17:28 +0000 Subject: make sure plugin reset backlight setting before exit. do code polish. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24076 a1c6a512-1295-4272-9138-f99709370657 --- apps/misc.c | 70 ++++++++++++++++++++--------------------- apps/plugins/SOURCES | 2 +- apps/plugins/blackjack.c | 2 +- apps/plugins/mosaique.c | 12 +++---- apps/plugins/robotfindskitten.c | 2 +- apps/plugins/rocklife.c | 23 ++++++++------ apps/plugins/starfield.c | 5 +-- apps/plugins/text_editor.c | 4 +-- apps/plugins/viewer.c | 24 +++++++------- 9 files changed, 73 insertions(+), 71 deletions(-) diff --git a/apps/misc.c b/apps/misc.c index 939de440b6..8f6da8b5e5 100644 --- a/apps/misc.c +++ b/apps/misc.c @@ -124,7 +124,7 @@ char *output_dyn_value(char *buf, int buf_size, int value, snprintf(tbuf, sizeof(tbuf), "%01d", fraction / 100); else snprintf(tbuf, sizeof(tbuf), "%02d", fraction / 10); - + if (buf) { if (strlen(tbuf)) @@ -168,7 +168,7 @@ int read_line(int fd, char* buffer, int buffer_size) { int count = 0; int num_read = 0; - + errno = 0; while (count < buffer_size) @@ -177,9 +177,9 @@ int read_line(int fd, char* buffer, int buffer_size) if (1 != read(fd, &c, 1)) break; - + num_read++; - + if ( c == '\n' ) break; @@ -201,15 +201,15 @@ int fast_readline(int fd, char *buf, int buf_size, void *parameters, char *p, *next; int rc, pos = 0; int count = 0; - + while ( 1 ) { next = NULL; - + rc = read(fd, &buf[pos], buf_size - pos - 1); if (rc >= 0) buf[pos+rc] = '\0'; - + if ( (p = strchr(buf, '\r')) != NULL) { *p = '\0'; @@ -217,17 +217,17 @@ int fast_readline(int fd, char *buf, int buf_size, void *parameters, } else p = buf; - + if ( (p = strchr(p, '\n')) != NULL) { *p = '\0'; next = ++p; } - + rc = callback(count, buf, parameters); if (rc < 0) return rc; - + count++; if (next) { @@ -237,7 +237,7 @@ int fast_readline(int fd, char *buf, int buf_size, void *parameters, else break ; } - + return 0; } @@ -338,7 +338,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) splashf(0, "%s %s", str(LANG_WARNING_BATTERY_EMPTY), str(LANG_SHUTTINGDOWN)); } - + if (global_settings.fade_on_stop && (audio_stat & AUDIO_STATUS_PLAY)) { @@ -371,7 +371,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter) #endif #if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC - audio_close_recording(); + audio_close_recording(); #endif if(global_settings.talk_menu) @@ -461,11 +461,11 @@ static bool waiting_to_resume_play = false; static long play_resume_tick; static void car_adapter_mode_processing(bool inserted) -{ +{ if (global_settings.car_adapter_mode) { if(inserted) - { + { /* * Just got plugged in, delay & resume if we were playing */ @@ -598,7 +598,7 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame case SYS_CHARGER_CONNECTED: car_adapter_mode_processing(true); return SYS_CHARGER_CONNECTED; - + case SYS_CHARGER_DISCONNECTED: car_adapter_mode_processing(false); return SYS_CHARGER_DISCONNECTED; @@ -634,12 +634,12 @@ long default_event_handler_ex(long event, void (*callback)(void *), void *parame return SYS_PHONE_UNPLUGGED; #endif #ifdef IPOD_ACCESSORY_PROTOCOL - case SYS_IAP_PERIODIC: - iap_periodic(); - return SYS_IAP_PERIODIC; - case SYS_IAP_HANDLEPKT: - iap_handlepkt(); - return SYS_IAP_HANDLEPKT; + case SYS_IAP_PERIODIC: + iap_periodic(); + return SYS_IAP_PERIODIC; + case SYS_IAP_HANDLEPKT: + iap_handlepkt(); + return SYS_IAP_HANDLEPKT; #endif } return 0; @@ -772,7 +772,7 @@ char* strrsplt(char* str, int c) { s = str; } - + return s; } @@ -857,14 +857,14 @@ void format_time(char* buf, int buf_size, long t) { if ( t < 3600000 ) { - snprintf(buf, buf_size, "%d:%02d", - (int) (t / 60000), (int) (t % 60000 / 1000)); - } + snprintf(buf, buf_size, "%d:%02d", + (int) (t / 60000), (int) (t % 60000 / 1000)); + } else { - snprintf(buf, buf_size, "%d:%02d:%02d", - (int) (t / 3600000), (int) (t % 3600000 / 60000), - (int) (t % 60000 / 1000)); + snprintf(buf, buf_size, "%d:%02d:%02d", + (int) (t / 3600000), (int) (t % 3600000 / 60000), + (int) (t % 60000 / 1000)); } } @@ -895,7 +895,7 @@ int open_utf8(const char* pathname, int flags) read(fd, bom, BOM_SIZE); /* check for BOM */ if(memcmp(bom, BOM, BOM_SIZE)) - lseek(fd, 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); } return fd; } @@ -908,8 +908,8 @@ int open_utf8(const char* pathname, int flags) static int hex2dec(int c) { - return (((c) >= '0' && ((c) <= '9')) ? (c) - '0' : - (toupper(c)) - 'A' + 10); + return (((c) >= '0' && ((c) <= '9')) ? (c) - '0' : + (toupper(c)) - 'A' + 10); } int hex_to_rgb(const char* hex, int* color) @@ -986,7 +986,7 @@ const char* parse_list(const char *fmt, uint32_t *set_vals, *s = p; while (*p && *p != sep) - p++; + p++; set = (s[0][0]!='-') && (s[0][1]!=sep) ; break; @@ -1007,9 +1007,9 @@ const char* parse_list(const char *fmt, uint32_t *set_vals, } else { - *d = *p++ - '0'; + *d = *p++ - '0'; while (isdigit(*p)) - *d = (*d * 10) + (*p++ - '0'); + *d = (*d * 10) + (*p++ - '0'); set = true; if (is_negative) *d *= -1; diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index 76a0b575b7..a3ce60fbf8 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -64,7 +64,7 @@ rockblox1d.c brickmania.c calendar.c maze.c -mazezam.c +mazezam.c text_editor.c wavview.c robotfindskitten.c diff --git a/apps/plugins/blackjack.c b/apps/plugins/blackjack.c index 3854799fc3..315f21f27b 100644 --- a/apps/plugins/blackjack.c +++ b/apps/plugins/blackjack.c @@ -136,7 +136,7 @@ enum { #define BJACK_LEFT BUTTON_LEFT #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD -#define BJACK_SELECT_NAME "PLAY" +#define BJACK_SELECT_NAME "SELECT" #define BJACK_STAY_NAME "REC" #define BJACK_RESUME_NAME "DOWN" #define BJACK_QUIT_NAME "POWER" diff --git a/apps/plugins/mosaique.c b/apps/plugins/mosaique.c index 51005fdabd..0f3e9ffc08 100644 --- a/apps/plugins/mosaique.c +++ b/apps/plugins/mosaique.c @@ -208,20 +208,20 @@ enum plugin_status plugin_start(const void* parameter) x = 2*GFX_WIDTH-x; sx=-sx; } - + if (x<0) { x = -x; sx = -sx; } - + y+=sy; if (y>GFX_HEIGHT) { y = 2*GFX_HEIGHT-y; sy=-sy; } - + if (y<0) { y = -y; @@ -235,7 +235,7 @@ enum plugin_status plugin_start(const void* parameter) MYLCD(update)(); rb->sleep(HZ/timer); - + button = rb->button_get(false); switch (button) { @@ -254,7 +254,7 @@ enum plugin_status plugin_start(const void* parameter) if (timer>20) timer=5; break; - + case MOSAIQUE_RESTART: sx = rb->rand() % (GFX_HEIGHT/2) + 1; @@ -278,5 +278,3 @@ enum plugin_status plugin_start(const void* parameter) } } } - - diff --git a/apps/plugins/robotfindskitten.c b/apps/plugins/robotfindskitten.c index a2bff3bfbe..5cd0e465f8 100644 --- a/apps/plugins/robotfindskitten.c +++ b/apps/plugins/robotfindskitten.c @@ -676,7 +676,7 @@ static void play_game() { int old_x = robot.x; int old_y = robot.y; - int input = 0; /* Not sure what a reasonable initial value is */ + int input = BUTTON_NONE; #ifdef __PLUGINLIB_ACTIONS_H__ const struct button_mapping *plugin_contexts[] = {generic_directions, generic_actions}; #endif diff --git a/apps/plugins/rocklife.c b/apps/plugins/rocklife.c index 5258121ea3..35c848de1d 100644 --- a/apps/plugins/rocklife.c +++ b/apps/plugins/rocklife.c @@ -131,7 +131,7 @@ static bool load_cellfile(const char *file, char *pgrid){ fd = rb->open(file, O_RDONLY); if (fd<0) return false; - + init_grid(pgrid); char c; @@ -143,7 +143,7 @@ static bool load_cellfile(const char *file, char *pgrid){ ymid = (GRID_H>>1) - 2; comment = false; - while (true) { + while (true) { nc = rb->read(fd, &c, 1); if (nc <= 0) break; @@ -343,7 +343,7 @@ static inline bool check_cell(unsigned char *n) /* now we build the number of non-zero neighbours :-P */ alive_cells = 8 - empty_cells; - + if (n[4]) { /* If the cell is alive, it stays alive iff it has 2 or 3 alive neighbours */ result = (alive_cells==2 || alive_cells==3); @@ -468,6 +468,7 @@ enum plugin_status plugin_start(const void* parameter) int button = 0; int quit = 0; int stop = 0; + int usb = 0; int pattern = 0; char *pgrid; char *pnext_grid; @@ -488,8 +489,7 @@ enum plugin_status plugin_start(const void* parameter) pgrid = (char *)grid_a; pnext_grid = (char *)grid_b; - init_grid(pgrid); - + init_grid(pgrid); if( parameter == NULL ) { @@ -544,6 +544,11 @@ enum plugin_status plugin_start(const void* parameter) stop = 1; break; default: + if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { + stop = 1; + quit = 1; + usb = 1; + } break; } rb->yield(); @@ -562,12 +567,12 @@ enum plugin_status plugin_start(const void* parameter) break; case ROCKLIFE_QUIT: /* quit plugin */ - quit=true; - return PLUGIN_OK; + quit = 1; break; default: if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { - return PLUGIN_USB_CONNECTED; + quit = 1; + usb = 1; } break; } @@ -575,5 +580,5 @@ enum plugin_status plugin_start(const void* parameter) } backlight_use_settings(); /* backlight control in lib/helper.c */ - return PLUGIN_OK; + return usb? PLUGIN_USB_CONNECTED: PLUGIN_OK; } diff --git a/apps/plugins/starfield.c b/apps/plugins/starfield.c index 4a680ee91b..0da3305a6f 100644 --- a/apps/plugins/starfield.c +++ b/apps/plugins/starfield.c @@ -482,8 +482,6 @@ int plugin_main(void) #endif case(STARFIELD_QUIT): case(SYS_USB_CONNECTED): - /* Turn on backlight timeout (revert to settings) */ - backlight_use_settings(); /* backlight control in lib/helper.c*/ return PLUGIN_OK; break; } @@ -502,6 +500,9 @@ enum plugin_status plugin_start(const void* parameter) ret = plugin_main(); + /* Turn on backlight timeout (revert to settings) */ + backlight_use_settings(); /* backlight control in lib/helper.c*/ + return ret; } diff --git a/apps/plugins/text_editor.c b/apps/plugins/text_editor.c index a8c8c2d836..4d5812ba2c 100644 --- a/apps/plugins/text_editor.c +++ b/apps/plugins/text_editor.c @@ -86,7 +86,7 @@ char* _do_action(int action, char* str, int line) break; case ACTION_REMOVE: if (line > line_count) - return 0; + return NULL; len = rb->strlen(&buffer[c])+1; rb->memmove(&buffer[c],&buffer[c+len],char_count-c-len); char_count -= len; @@ -225,7 +225,7 @@ enum { }; int do_item_menu(int cur_sel, char* copy_buffer) { - int ret = 0; + int ret = MENU_RET_NO_UPDATE; MENUITEM_STRINGLIST(menu, "Line Options", NULL, "Cut/Delete", "Copy", "Insert Above", "Insert Below", diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c index a212885540..88b43c30b3 100644 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -1,12 +1,11 @@ /*************************************************************************** - * * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * + * $Id$ * * Copyright (C) 2002 Gilles Roux, 2003 Garrett Derner * @@ -432,7 +431,6 @@ struct preferences { } scroll_mode; int autoscroll_speed; - }; struct preferences prefs; @@ -1226,7 +1224,7 @@ static void viewer_load_settings(void) /* same name as global, but not the same int settings_fd, i; struct bookmark_file_data *data; struct bookmarked_file_info this_bookmark; - + /* read settings file */ settings_fd=rb->open(SETTINGS_FILE, O_RDONLY); if ((settings_fd >= 0) && (rb->filesize(settings_fd) == sizeof(struct preferences))) @@ -1271,7 +1269,7 @@ static void viewer_load_settings(void) /* same name as global, but not the same file_pos = screen_pos - screen_top; screen_top_ptr = buffer + screen_top; break; - } + } } this_bookmark.file_position = file_pos; @@ -1284,16 +1282,16 @@ static void viewer_load_settings(void) /* same name as global, but not the same if (i >= data->bookmarked_files_count) { if (i < MAX_BOOKMARKED_FILES) - data->bookmarked_files_count++; - else + data->bookmarked_files_count++; + else i = MAX_BOOKMARKED_FILES-1; - } + } /* write bookmark file with spare slot in first position to be filled in by viewer_save_settings */ settings_fd = rb->open(BOOKMARKS_FILE, O_WRONLY|O_CREAT); if (settings_fd >=0 ) - { + { /* write count */ rb->write (settings_fd, &data->bookmarked_files_count, sizeof(signed int)); @@ -1336,7 +1334,7 @@ static void viewer_save_settings(void)/* same name as global, but not the same f rb->close(settings_fd); } } - + /* save the bookmark if the position has changed */ if (file_pos + screen_top_ptr - buffer != start_position) { @@ -1559,11 +1557,11 @@ enum plugin_status plugin_start(const void* file) } viewer_load_settings(); /* load the preferences and bookmark */ - + #if LCD_DEPTH > 1 rb->lcd_set_backdrop(NULL); #endif - + viewer_draw(col); while (!done) { @@ -1577,7 +1575,7 @@ enum plugin_status plugin_start(const void* file) old_tick = *rb->current_tick; } } - + button = rb->button_get_w_tmo(HZ/10); switch (button) { case VIEWER_MENU: -- cgit v1.2.3