From 9db31cf8866ec980edb6e42cc3697afc010e61a6 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Tue, 12 Oct 2004 22:49:51 +0000 Subject: grayscale.rock, jpeg.rock and video.rock now use default_event_handler_ex(). Adapted and enabled them for Ondio. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5264 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugins/SOURCES | 6 ++-- apps/plugins/grayscale.c | 38 ++++++++++++++----------- apps/plugins/jpeg.c | 52 +++++++++++++++++++++++++++------- apps/plugins/video.c | 73 +++++++++++++++++++++++++++++++----------------- 4 files changed, 113 insertions(+), 56 deletions(-) (limited to 'apps') diff --git a/apps/plugins/SOURCES b/apps/plugins/SOURCES index d076eb373e..a36ca1a2e1 100644 --- a/apps/plugins/SOURCES +++ b/apps/plugins/SOURCES @@ -15,8 +15,11 @@ viewer.c #endif /* #if CONFIG_KEYPAD != ONDIO_PAD */ #ifdef HAVE_LCD_BITMAP /* recorder model only */ +grayscale.c +jpeg.c rockblox.c snow.c +video.c #if CONFIG_KEYPAD != ONDIO_PAD /* gradually bring in the ones not working yet */ bounce.c @@ -26,8 +29,6 @@ chip8.c clock.c cube.c flipit.c -grayscale.c -jpeg.c mandelbrot.c minesweeper.c mosaique.c @@ -40,7 +41,6 @@ sokoban.c solitaire.c splitedit.c star.c -video.c vu_meter.c wormlet.c #endif /* #if CONFIG_KEYPAD != ONDIO_PAD */ diff --git a/apps/plugins/grayscale.c b/apps/plugins/grayscale.c index 2be9cc9c23..ebfc7f59c0 100644 --- a/apps/plugins/grayscale.c +++ b/apps/plugins/grayscale.c @@ -25,6 +25,12 @@ #ifdef HAVE_LCD_BITMAP /* and also not for the Player */ #include "gray.h" +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define GRAYSCALE_SHIFT BUTTON_ON +#elif CONFIG_KEYPAD == ONDIO_PAD +#define GRAYSCALE_SHIFT BUTTON_MENU +#endif /******************************* Globals ***********************************/ static struct plugin_api* rb; /* global api struct pointer */ @@ -34,6 +40,15 @@ static unsigned int gbuf_size = 0; /**************************** main function ********************************/ +void cleanup(void *parameter) +{ + (void)parameter; + + gray_release_buffer(); /* switch off overlay and deinitialize */ + /* restore normal backlight setting */ + rb->backlight_set_timeout(rb->global_settings->backlight_timeout); +} + /* this is only a demo of what the framework can do */ int main(void) { @@ -193,21 +208,17 @@ int main(void) button = rb->button_get(true); - if (button == SYS_USB_CONNECTED) - { - gray_release_buffer(); /* switch off overlay and deinitialize */ - /* restore normal backlight setting */ - rb->backlight_set_timeout(rb->global_settings->backlight_timeout); + if (rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; - } - if (button & BUTTON_ON) + if (button & GRAYSCALE_SHIFT) black_border = true; if (button & BUTTON_REPEAT) scroll_amount = 4; - switch(button & ~(BUTTON_ON | BUTTON_REPEAT)) + switch(button & ~(GRAYSCALE_SHIFT | BUTTON_REPEAT)) { case BUTTON_LEFT: @@ -231,9 +242,7 @@ int main(void) case BUTTON_OFF: - gray_release_buffer(); /* switch off overlay and deinitialize */ - /* restore normal backlight setting */ - rb->backlight_set_timeout(rb->global_settings->backlight_timeout); + cleanup(NULL); return PLUGIN_OK; } } @@ -243,7 +252,6 @@ int main(void) enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - int ret; /* this macro should be called as the first thing you do in the plugin. it test that the api version and model the plugin was compiled for matches the machine it is running on */ @@ -255,11 +263,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) /* This plugin uses the grayscale framework, so initialize */ gray_init(api); - ret = main(); - - if (ret == PLUGIN_USB_CONNECTED) - rb->usb_screen(); - return ret; + return main(); } #endif // #ifdef HAVE_LCD_BITMAP diff --git a/apps/plugins/jpeg.c b/apps/plugins/jpeg.c index 4e47d9faf2..7d8fab7456 100644 --- a/apps/plugins/jpeg.c +++ b/apps/plugins/jpeg.c @@ -29,6 +29,16 @@ #ifdef HAVE_LCD_BITMAP /* and also not for the Player */ #include "gray.h" +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define JPEG_ZOOM_IN BUTTON_PLAY +#define JPEG_ZOOM_OUT BUTTON_ON +#elif CONFIG_KEYPAD == ONDIO_PAD +#define JPEG_ZOOM_PRE BUTTON_MENU +#define JPEG_ZOOM_IN (BUTTON_MENU | BUTTON_REL) +#define JPEG_ZOOM_OUT (BUTTON_MENU | BUTTON_REPEAT) +#endif + /******************************* Globals ***********************************/ static struct plugin_api* rb; @@ -1494,9 +1504,19 @@ int root_size; #define ZOOM_IN 100 // return codes for below function #define ZOOM_OUT 101 +/* switch off overlay, for handling SYS_ events */ +void cleanup(void *parameter) +{ + (void)parameter; + + gray_show_display(false); +} + /* interactively scroll around the image */ int scroll_bmp(struct t_disp* pdisp) { + int lastbutton = 0; + /*empty the button queue first, to avoid unwanted scrolling */ while(rb->button_get(false) != BUTTON_NONE); @@ -1506,13 +1526,15 @@ int scroll_bmp(struct t_disp* pdisp) int move; button = rb->button_get(true); - - if (button == SYS_USB_CONNECTED) + + if (rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) return PLUGIN_USB_CONNECTED; - switch(button & ~(BUTTON_REPEAT)) + switch(button) { case BUTTON_LEFT: + case BUTTON_LEFT | BUTTON_REPEAT: move = MIN(10, pdisp->x); if (move > 0) { @@ -1527,6 +1549,7 @@ int scroll_bmp(struct t_disp* pdisp) break; case BUTTON_RIGHT: + case BUTTON_RIGHT | BUTTON_REPEAT: move = MIN(10, pdisp->width - pdisp->x - LCD_WIDTH); if (move > 0) { @@ -1541,6 +1564,7 @@ int scroll_bmp(struct t_disp* pdisp) break; case BUTTON_UP: + case BUTTON_UP | BUTTON_REPEAT: move = MIN(8, pdisp->y); if (move > 0) { @@ -1558,6 +1582,7 @@ int scroll_bmp(struct t_disp* pdisp) break; case BUTTON_DOWN: + case BUTTON_DOWN | BUTTON_REPEAT: move = MIN(8, pdisp->height - pdisp->y - LCD_HEIGHT); if (move > 0) { @@ -1574,17 +1599,28 @@ int scroll_bmp(struct t_disp* pdisp) } break; - case BUTTON_PLAY: + case JPEG_ZOOM_IN: +#ifdef JPEG_ZOOM_PRE + if (lastbutton != JPEG_ZOOM_PRE) + break; +#endif return ZOOM_IN; break; - case BUTTON_ON: + case JPEG_ZOOM_OUT: +#ifdef JPEG_ZOOM_PRE + if (lastbutton != JPEG_ZOOM_PRE) + break; +#endif return ZOOM_OUT; break; case BUTTON_OFF: return PLUGIN_OK; } /* switch */ + + if (button != BUTTON_NONE) + lastbutton = button; } /* while (true) */ } @@ -1913,7 +1949,6 @@ int main(char* filename) enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - int ret; /* this macro should be called as the first thing you do in the plugin. it test that the api version and model the plugin was compiled for matches the machine it is running on */ @@ -1923,11 +1958,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) /* This plugin uses the grayscale framework, so initialize */ gray_init(api); - ret = main((char*)parameter); - if (ret == PLUGIN_USB_CONNECTED) - rb->usb_screen(); - return ret; + return main((char*)parameter); } #endif /* #ifdef HAVE_LCD_BITMAP */ diff --git a/apps/plugins/video.c b/apps/plugins/video.c index c1ce149ea3..63d03312b9 100644 --- a/apps/plugins/video.c +++ b/apps/plugins/video.c @@ -32,6 +32,14 @@ #ifndef SIMULATOR // not for simulator by now #ifdef HAVE_LCD_BITMAP // and definitely not for the Player, haha +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define VIDEO_STOP_SEEK BUTTON_PLAY +#define VIDEO_RESUME BUTTON_PLAY +#elif CONFIG_KEYPAD == ONDIO_PAD +#define VIDEO_STOP_SEEK BUTTON_MENU +#define VIDEO_RESUME BUTTON_RIGHT +#endif /****************** constants ******************/ #define INT_MAX ((int)(~(unsigned)0 >> 1)) @@ -274,6 +282,7 @@ void ChangeVolume(int delta) } +#if CONFIG_KEYPAD == RECORDER_PAD // helper function to change the LCD contrast by a certain amount, +/- void ChangeContrast(int delta) { @@ -301,6 +310,7 @@ void ChangeContrast(int delta) } } } +#endif // sync the video to the current audio @@ -440,6 +450,7 @@ int WaitForButton(void) do { button = rb->button_get(true); + rb->default_event_handler(button); } while ((button & BUTTON_REL) && button != SYS_USB_CONNECTED); return button; @@ -459,7 +470,7 @@ bool WantResume(int fd) rb->lcd_update(); button = WaitForButton(); - return (button == BUTTON_PLAY); + return (button == VIDEO_RESUME); } @@ -523,6 +534,23 @@ int SeekTo(int fd, int nPos) return 0; } +// called from default_event_handler_ex() or at end of playback +void Cleanup(void *fd) +{ + rb->close(*(int*)fd); // close the file + + if (gPlay.bHasVideo) + rb->plugin_unregister_timer(); // stop video ISR, now I can use the display again + + if (gPlay.bHasAudio) + rb->mp3_play_stop(); // stop audio ISR + + // restore normal backlight setting + rb->backlight_set_timeout(rb->global_settings->backlight_timeout); + + // restore normal contrast + rb->lcd_set_contrast(rb->global_settings->contrast); +} // returns >0 if continue, =0 to stop, <0 to abort (USB) int PlayTick(int fd) @@ -631,6 +659,11 @@ int PlayTick(int fd) filepos -= Available(gBuf.pReadVideo); // take video position else filepos -= Available(gBuf.pReadAudio); // else audio + + if (rb->default_event_handler_ex(button, Cleanup, &fd) + == SYS_USB_CONNECTED) + retval = -1; // signal "aborted" to caller + // SYS_USB_CONNECTED won't be catched again by the switch() switch (button) { // set exit conditions @@ -642,12 +675,10 @@ int PlayTick(int fd) rb->lseek(fd, 0, SEEK_SET); // save resume position rb->write(fd, &gFileHdr, sizeof(gFileHdr)); } - retval = 0; // signal "stop" to caller - break; - case SYS_USB_CONNECTED: - retval = -1; // signal "abort" to caller + Cleanup(&fd); + retval = 0; // signal "stopped" to caller break; - case BUTTON_PLAY: + case VIDEO_STOP_SEEK: if (gPlay.bSeeking) { gPlay.bSeeking = false; @@ -714,6 +745,7 @@ int PlayTick(int fd) else gPlay.nSeekAcc++; break; +#if CONFIG_KEYPAD == RECORDER_PAD case BUTTON_F1: // debug key case BUTTON_F1 | BUTTON_REPEAT: DrawBuf(); // show buffer status @@ -730,6 +762,7 @@ int PlayTick(int fd) if (gPlay.bHasVideo) ChangeContrast(1); break; +#endif } } /* if (button != BUTTON_NONE) */ @@ -832,7 +865,13 @@ int main(char* filename) gFileHdr.video_frametime = FREQ / FPS; gFileHdr.bps_peak = gFileHdr.bps_average = LCD_WIDTH * LCD_HEIGHT * FPS; } - +#if FREQ == 12000000 +/* temporary sync fix for Ondio, as .rvf is tailored to the recorder CPU freq + * 625 / 576 == 12000000 / 11059200 */ + else + gFileHdr.video_frametime = (gFileHdr.video_frametime * 625) / 576; +#endif + // continue buffer init: align the end, calc low water, read sizes gBuf.granularity = gFileHdr.blocksize; while (gBuf.granularity % 512) // common multiple of sector size @@ -877,20 +916,6 @@ int main(char* filename) retval = PlayTick(fd); } while (retval > 0); - rb->close(fd); // close the file - - if (gPlay.bHasVideo) - rb->plugin_unregister_timer(); // stop video ISR, now I can use the display again - - if (gPlay.bHasAudio) - rb->mp3_play_stop(); // stop audio ISR - - // restore normal backlight setting - rb->backlight_set_timeout(rb->global_settings->backlight_timeout); - - // restore normal contrast - rb->lcd_set_contrast(rb->global_settings->contrast); - if (retval < 0) // aborted? { return PLUGIN_USB_CONNECTED; @@ -930,7 +955,6 @@ int main(char* filename) enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { - int ret; /* this macro should be called as the first thing you do in the plugin. it test that the api version and model the plugin was compiled for matches the machine it is running on */ @@ -945,10 +969,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) } // now go ahead and have fun! - ret = main((char*) parameter); - if (ret==PLUGIN_USB_CONNECTED) - rb->usb_screen(); - return ret; + return main((char*) parameter); } #endif // #ifdef HAVE_LCD_BITMAP -- cgit v1.2.3