summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2004-10-12 22:49:51 +0000
committerJens Arnold <amiconn@rockbox.org>2004-10-12 22:49:51 +0000
commit9db31cf8866ec980edb6e42cc3697afc010e61a6 (patch)
treeaba8e26be12917909b215e16359bcef5caffc0d2 /apps
parent0dc52d5c362a6f416ca57f0afdbac49dc8824af2 (diff)
downloadrockbox-9db31cf8866ec980edb6e42cc3697afc010e61a6.tar.gz
rockbox-9db31cf8866ec980edb6e42cc3697afc010e61a6.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/plugins/SOURCES6
-rw-r--r--apps/plugins/grayscale.c38
-rw-r--r--apps/plugins/jpeg.c52
-rw-r--r--apps/plugins/video.c73
4 files changed, 113 insertions, 56 deletions
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
15#endif /* #if CONFIG_KEYPAD != ONDIO_PAD */ 15#endif /* #if CONFIG_KEYPAD != ONDIO_PAD */
16 16
17#ifdef HAVE_LCD_BITMAP /* recorder model only */ 17#ifdef HAVE_LCD_BITMAP /* recorder model only */
18grayscale.c
19jpeg.c
18rockblox.c 20rockblox.c
19snow.c 21snow.c
22video.c
20#if CONFIG_KEYPAD != ONDIO_PAD 23#if CONFIG_KEYPAD != ONDIO_PAD
21/* gradually bring in the ones not working yet */ 24/* gradually bring in the ones not working yet */
22bounce.c 25bounce.c
@@ -26,8 +29,6 @@ chip8.c
26clock.c 29clock.c
27cube.c 30cube.c
28flipit.c 31flipit.c
29grayscale.c
30jpeg.c
31mandelbrot.c 32mandelbrot.c
32minesweeper.c 33minesweeper.c
33mosaique.c 34mosaique.c
@@ -40,7 +41,6 @@ sokoban.c
40solitaire.c 41solitaire.c
41splitedit.c 42splitedit.c
42star.c 43star.c
43video.c
44vu_meter.c 44vu_meter.c
45wormlet.c 45wormlet.c
46#endif /* #if CONFIG_KEYPAD != ONDIO_PAD */ 46#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 @@
25#ifdef HAVE_LCD_BITMAP /* and also not for the Player */ 25#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
26#include "gray.h" 26#include "gray.h"
27 27
28/* variable button definitions */
29#if CONFIG_KEYPAD == RECORDER_PAD
30#define GRAYSCALE_SHIFT BUTTON_ON
31#elif CONFIG_KEYPAD == ONDIO_PAD
32#define GRAYSCALE_SHIFT BUTTON_MENU
33#endif
28/******************************* Globals ***********************************/ 34/******************************* Globals ***********************************/
29 35
30static struct plugin_api* rb; /* global api struct pointer */ 36static struct plugin_api* rb; /* global api struct pointer */
@@ -34,6 +40,15 @@ static unsigned int gbuf_size = 0;
34 40
35/**************************** main function ********************************/ 41/**************************** main function ********************************/
36 42
43void cleanup(void *parameter)
44{
45 (void)parameter;
46
47 gray_release_buffer(); /* switch off overlay and deinitialize */
48 /* restore normal backlight setting */
49 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
50}
51
37/* this is only a demo of what the framework can do */ 52/* this is only a demo of what the framework can do */
38int main(void) 53int main(void)
39{ 54{
@@ -193,21 +208,17 @@ int main(void)
193 208
194 button = rb->button_get(true); 209 button = rb->button_get(true);
195 210
196 if (button == SYS_USB_CONNECTED) 211 if (rb->default_event_handler_ex(button, cleanup, NULL)
197 { 212 == SYS_USB_CONNECTED)
198 gray_release_buffer(); /* switch off overlay and deinitialize */
199 /* restore normal backlight setting */
200 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
201 return PLUGIN_USB_CONNECTED; 213 return PLUGIN_USB_CONNECTED;
202 }
203 214
204 if (button & BUTTON_ON) 215 if (button & GRAYSCALE_SHIFT)
205 black_border = true; 216 black_border = true;
206 217
207 if (button & BUTTON_REPEAT) 218 if (button & BUTTON_REPEAT)
208 scroll_amount = 4; 219 scroll_amount = 4;
209 220
210 switch(button & ~(BUTTON_ON | BUTTON_REPEAT)) 221 switch(button & ~(GRAYSCALE_SHIFT | BUTTON_REPEAT))
211 { 222 {
212 case BUTTON_LEFT: 223 case BUTTON_LEFT:
213 224
@@ -231,9 +242,7 @@ int main(void)
231 242
232 case BUTTON_OFF: 243 case BUTTON_OFF:
233 244
234 gray_release_buffer(); /* switch off overlay and deinitialize */ 245 cleanup(NULL);
235 /* restore normal backlight setting */
236 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
237 return PLUGIN_OK; 246 return PLUGIN_OK;
238 } 247 }
239 } 248 }
@@ -243,7 +252,6 @@ int main(void)
243 252
244enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 253enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
245{ 254{
246 int ret;
247 /* this macro should be called as the first thing you do in the plugin. 255 /* this macro should be called as the first thing you do in the plugin.
248 it test that the api version and model the plugin was compiled for 256 it test that the api version and model the plugin was compiled for
249 matches the machine it is running on */ 257 matches the machine it is running on */
@@ -255,11 +263,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
255 /* This plugin uses the grayscale framework, so initialize */ 263 /* This plugin uses the grayscale framework, so initialize */
256 gray_init(api); 264 gray_init(api);
257 265
258 ret = main(); 266 return main();
259
260 if (ret == PLUGIN_USB_CONNECTED)
261 rb->usb_screen();
262 return ret;
263} 267}
264 268
265#endif // #ifdef HAVE_LCD_BITMAP 269#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 @@
29#ifdef HAVE_LCD_BITMAP /* and also not for the Player */ 29#ifdef HAVE_LCD_BITMAP /* and also not for the Player */
30#include "gray.h" 30#include "gray.h"
31 31
32/* variable button definitions */
33#if CONFIG_KEYPAD == RECORDER_PAD
34#define JPEG_ZOOM_IN BUTTON_PLAY
35#define JPEG_ZOOM_OUT BUTTON_ON
36#elif CONFIG_KEYPAD == ONDIO_PAD
37#define JPEG_ZOOM_PRE BUTTON_MENU
38#define JPEG_ZOOM_IN (BUTTON_MENU | BUTTON_REL)
39#define JPEG_ZOOM_OUT (BUTTON_MENU | BUTTON_REPEAT)
40#endif
41
32/******************************* Globals ***********************************/ 42/******************************* Globals ***********************************/
33 43
34static struct plugin_api* rb; 44static struct plugin_api* rb;
@@ -1494,9 +1504,19 @@ int root_size;
1494#define ZOOM_IN 100 // return codes for below function 1504#define ZOOM_IN 100 // return codes for below function
1495#define ZOOM_OUT 101 1505#define ZOOM_OUT 101
1496 1506
1507/* switch off overlay, for handling SYS_ events */
1508void cleanup(void *parameter)
1509{
1510 (void)parameter;
1511
1512 gray_show_display(false);
1513}
1514
1497/* interactively scroll around the image */ 1515/* interactively scroll around the image */
1498int scroll_bmp(struct t_disp* pdisp) 1516int scroll_bmp(struct t_disp* pdisp)
1499{ 1517{
1518 int lastbutton = 0;
1519
1500 /*empty the button queue first, to avoid unwanted scrolling */ 1520 /*empty the button queue first, to avoid unwanted scrolling */
1501 while(rb->button_get(false) != BUTTON_NONE); 1521 while(rb->button_get(false) != BUTTON_NONE);
1502 1522
@@ -1506,13 +1526,15 @@ int scroll_bmp(struct t_disp* pdisp)
1506 int move; 1526 int move;
1507 1527
1508 button = rb->button_get(true); 1528 button = rb->button_get(true);
1509 1529
1510 if (button == SYS_USB_CONNECTED) 1530 if (rb->default_event_handler_ex(button, cleanup, NULL)
1531 == SYS_USB_CONNECTED)
1511 return PLUGIN_USB_CONNECTED; 1532 return PLUGIN_USB_CONNECTED;
1512 1533
1513 switch(button & ~(BUTTON_REPEAT)) 1534 switch(button)
1514 { 1535 {
1515 case BUTTON_LEFT: 1536 case BUTTON_LEFT:
1537 case BUTTON_LEFT | BUTTON_REPEAT:
1516 move = MIN(10, pdisp->x); 1538 move = MIN(10, pdisp->x);
1517 if (move > 0) 1539 if (move > 0)
1518 { 1540 {
@@ -1527,6 +1549,7 @@ int scroll_bmp(struct t_disp* pdisp)
1527 break; 1549 break;
1528 1550
1529 case BUTTON_RIGHT: 1551 case BUTTON_RIGHT:
1552 case BUTTON_RIGHT | BUTTON_REPEAT:
1530 move = MIN(10, pdisp->width - pdisp->x - LCD_WIDTH); 1553 move = MIN(10, pdisp->width - pdisp->x - LCD_WIDTH);
1531 if (move > 0) 1554 if (move > 0)
1532 { 1555 {
@@ -1541,6 +1564,7 @@ int scroll_bmp(struct t_disp* pdisp)
1541 break; 1564 break;
1542 1565
1543 case BUTTON_UP: 1566 case BUTTON_UP:
1567 case BUTTON_UP | BUTTON_REPEAT:
1544 move = MIN(8, pdisp->y); 1568 move = MIN(8, pdisp->y);
1545 if (move > 0) 1569 if (move > 0)
1546 { 1570 {
@@ -1558,6 +1582,7 @@ int scroll_bmp(struct t_disp* pdisp)
1558 break; 1582 break;
1559 1583
1560 case BUTTON_DOWN: 1584 case BUTTON_DOWN:
1585 case BUTTON_DOWN | BUTTON_REPEAT:
1561 move = MIN(8, pdisp->height - pdisp->y - LCD_HEIGHT); 1586 move = MIN(8, pdisp->height - pdisp->y - LCD_HEIGHT);
1562 if (move > 0) 1587 if (move > 0)
1563 { 1588 {
@@ -1574,17 +1599,28 @@ int scroll_bmp(struct t_disp* pdisp)
1574 } 1599 }
1575 break; 1600 break;
1576 1601
1577 case BUTTON_PLAY: 1602 case JPEG_ZOOM_IN:
1603#ifdef JPEG_ZOOM_PRE
1604 if (lastbutton != JPEG_ZOOM_PRE)
1605 break;
1606#endif
1578 return ZOOM_IN; 1607 return ZOOM_IN;
1579 break; 1608 break;
1580 1609
1581 case BUTTON_ON: 1610 case JPEG_ZOOM_OUT:
1611#ifdef JPEG_ZOOM_PRE
1612 if (lastbutton != JPEG_ZOOM_PRE)
1613 break;
1614#endif
1582 return ZOOM_OUT; 1615 return ZOOM_OUT;
1583 break; 1616 break;
1584 1617
1585 case BUTTON_OFF: 1618 case BUTTON_OFF:
1586 return PLUGIN_OK; 1619 return PLUGIN_OK;
1587 } /* switch */ 1620 } /* switch */
1621
1622 if (button != BUTTON_NONE)
1623 lastbutton = button;
1588 } /* while (true) */ 1624 } /* while (true) */
1589} 1625}
1590 1626
@@ -1913,7 +1949,6 @@ int main(char* filename)
1913 1949
1914enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 1950enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1915{ 1951{
1916 int ret;
1917 /* this macro should be called as the first thing you do in the plugin. 1952 /* this macro should be called as the first thing you do in the plugin.
1918 it test that the api version and model the plugin was compiled for 1953 it test that the api version and model the plugin was compiled for
1919 matches the machine it is running on */ 1954 matches the machine it is running on */
@@ -1923,11 +1958,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
1923 1958
1924 /* This plugin uses the grayscale framework, so initialize */ 1959 /* This plugin uses the grayscale framework, so initialize */
1925 gray_init(api); 1960 gray_init(api);
1926 ret = main((char*)parameter);
1927 1961
1928 if (ret == PLUGIN_USB_CONNECTED) 1962 return main((char*)parameter);
1929 rb->usb_screen();
1930 return ret;
1931} 1963}
1932 1964
1933#endif /* #ifdef HAVE_LCD_BITMAP */ 1965#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 @@
32#ifndef SIMULATOR // not for simulator by now 32#ifndef SIMULATOR // not for simulator by now
33#ifdef HAVE_LCD_BITMAP // and definitely not for the Player, haha 33#ifdef HAVE_LCD_BITMAP // and definitely not for the Player, haha
34 34
35/* variable button definitions */
36#if CONFIG_KEYPAD == RECORDER_PAD
37#define VIDEO_STOP_SEEK BUTTON_PLAY
38#define VIDEO_RESUME BUTTON_PLAY
39#elif CONFIG_KEYPAD == ONDIO_PAD
40#define VIDEO_STOP_SEEK BUTTON_MENU
41#define VIDEO_RESUME BUTTON_RIGHT
42#endif
35/****************** constants ******************/ 43/****************** constants ******************/
36 44
37#define INT_MAX ((int)(~(unsigned)0 >> 1)) 45#define INT_MAX ((int)(~(unsigned)0 >> 1))
@@ -274,6 +282,7 @@ void ChangeVolume(int delta)
274} 282}
275 283
276 284
285#if CONFIG_KEYPAD == RECORDER_PAD
277// helper function to change the LCD contrast by a certain amount, +/- 286// helper function to change the LCD contrast by a certain amount, +/-
278void ChangeContrast(int delta) 287void ChangeContrast(int delta)
279{ 288{
@@ -301,6 +310,7 @@ void ChangeContrast(int delta)
301 } 310 }
302 } 311 }
303} 312}
313#endif
304 314
305 315
306// sync the video to the current audio 316// sync the video to the current audio
@@ -440,6 +450,7 @@ int WaitForButton(void)
440 do 450 do
441 { 451 {
442 button = rb->button_get(true); 452 button = rb->button_get(true);
453 rb->default_event_handler(button);
443 } while ((button & BUTTON_REL) && button != SYS_USB_CONNECTED); 454 } while ((button & BUTTON_REL) && button != SYS_USB_CONNECTED);
444 455
445 return button; 456 return button;
@@ -459,7 +470,7 @@ bool WantResume(int fd)
459 rb->lcd_update(); 470 rb->lcd_update();
460 471
461 button = WaitForButton(); 472 button = WaitForButton();
462 return (button == BUTTON_PLAY); 473 return (button == VIDEO_RESUME);
463} 474}
464 475
465 476
@@ -523,6 +534,23 @@ int SeekTo(int fd, int nPos)
523 return 0; 534 return 0;
524} 535}
525 536
537// called from default_event_handler_ex() or at end of playback
538void Cleanup(void *fd)
539{
540 rb->close(*(int*)fd); // close the file
541
542 if (gPlay.bHasVideo)
543 rb->plugin_unregister_timer(); // stop video ISR, now I can use the display again
544
545 if (gPlay.bHasAudio)
546 rb->mp3_play_stop(); // stop audio ISR
547
548 // restore normal backlight setting
549 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
550
551 // restore normal contrast
552 rb->lcd_set_contrast(rb->global_settings->contrast);
553}
526 554
527// returns >0 if continue, =0 to stop, <0 to abort (USB) 555// returns >0 if continue, =0 to stop, <0 to abort (USB)
528int PlayTick(int fd) 556int PlayTick(int fd)
@@ -631,6 +659,11 @@ int PlayTick(int fd)
631 filepos -= Available(gBuf.pReadVideo); // take video position 659 filepos -= Available(gBuf.pReadVideo); // take video position
632 else 660 else
633 filepos -= Available(gBuf.pReadAudio); // else audio 661 filepos -= Available(gBuf.pReadAudio); // else audio
662
663 if (rb->default_event_handler_ex(button, Cleanup, &fd)
664 == SYS_USB_CONNECTED)
665 retval = -1; // signal "aborted" to caller
666 // SYS_USB_CONNECTED won't be catched again by the switch()
634 667
635 switch (button) 668 switch (button)
636 { // set exit conditions 669 { // set exit conditions
@@ -642,12 +675,10 @@ int PlayTick(int fd)
642 rb->lseek(fd, 0, SEEK_SET); // save resume position 675 rb->lseek(fd, 0, SEEK_SET); // save resume position
643 rb->write(fd, &gFileHdr, sizeof(gFileHdr)); 676 rb->write(fd, &gFileHdr, sizeof(gFileHdr));
644 } 677 }
645 retval = 0; // signal "stop" to caller 678 Cleanup(&fd);
646 break; 679 retval = 0; // signal "stopped" to caller
647 case SYS_USB_CONNECTED:
648 retval = -1; // signal "abort" to caller
649 break; 680 break;
650 case BUTTON_PLAY: 681 case VIDEO_STOP_SEEK:
651 if (gPlay.bSeeking) 682 if (gPlay.bSeeking)
652 { 683 {
653 gPlay.bSeeking = false; 684 gPlay.bSeeking = false;
@@ -714,6 +745,7 @@ int PlayTick(int fd)
714 else 745 else
715 gPlay.nSeekAcc++; 746 gPlay.nSeekAcc++;
716 break; 747 break;
748#if CONFIG_KEYPAD == RECORDER_PAD
717 case BUTTON_F1: // debug key 749 case BUTTON_F1: // debug key
718 case BUTTON_F1 | BUTTON_REPEAT: 750 case BUTTON_F1 | BUTTON_REPEAT:
719 DrawBuf(); // show buffer status 751 DrawBuf(); // show buffer status
@@ -730,6 +762,7 @@ int PlayTick(int fd)
730 if (gPlay.bHasVideo) 762 if (gPlay.bHasVideo)
731 ChangeContrast(1); 763 ChangeContrast(1);
732 break; 764 break;
765#endif
733 } 766 }
734 } /* if (button != BUTTON_NONE) */ 767 } /* if (button != BUTTON_NONE) */
735 768
@@ -832,7 +865,13 @@ int main(char* filename)
832 gFileHdr.video_frametime = FREQ / FPS; 865 gFileHdr.video_frametime = FREQ / FPS;
833 gFileHdr.bps_peak = gFileHdr.bps_average = LCD_WIDTH * LCD_HEIGHT * FPS; 866 gFileHdr.bps_peak = gFileHdr.bps_average = LCD_WIDTH * LCD_HEIGHT * FPS;
834 } 867 }
835 868#if FREQ == 12000000
869/* temporary sync fix for Ondio, as .rvf is tailored to the recorder CPU freq
870 * 625 / 576 == 12000000 / 11059200 */
871 else
872 gFileHdr.video_frametime = (gFileHdr.video_frametime * 625) / 576;
873#endif
874
836 // continue buffer init: align the end, calc low water, read sizes 875 // continue buffer init: align the end, calc low water, read sizes
837 gBuf.granularity = gFileHdr.blocksize; 876 gBuf.granularity = gFileHdr.blocksize;
838 while (gBuf.granularity % 512) // common multiple of sector size 877 while (gBuf.granularity % 512) // common multiple of sector size
@@ -877,20 +916,6 @@ int main(char* filename)
877 retval = PlayTick(fd); 916 retval = PlayTick(fd);
878 } while (retval > 0); 917 } while (retval > 0);
879 918
880 rb->close(fd); // close the file
881
882 if (gPlay.bHasVideo)
883 rb->plugin_unregister_timer(); // stop video ISR, now I can use the display again
884
885 if (gPlay.bHasAudio)
886 rb->mp3_play_stop(); // stop audio ISR
887
888 // restore normal backlight setting
889 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
890
891 // restore normal contrast
892 rb->lcd_set_contrast(rb->global_settings->contrast);
893
894 if (retval < 0) // aborted? 919 if (retval < 0) // aborted?
895 { 920 {
896 return PLUGIN_USB_CONNECTED; 921 return PLUGIN_USB_CONNECTED;
@@ -930,7 +955,6 @@ int main(char* filename)
930 955
931enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 956enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
932{ 957{
933 int ret;
934 /* this macro should be called as the first thing you do in the plugin. 958 /* this macro should be called as the first thing you do in the plugin.
935 it test that the api version and model the plugin was compiled for 959 it test that the api version and model the plugin was compiled for
936 matches the machine it is running on */ 960 matches the machine it is running on */
@@ -945,10 +969,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
945 } 969 }
946 970
947 // now go ahead and have fun! 971 // now go ahead and have fun!
948 ret = main((char*) parameter); 972 return main((char*) parameter);
949 if (ret==PLUGIN_USB_CONNECTED)
950 rb->usb_screen();
951 return ret;
952} 973}
953 974
954#endif // #ifdef HAVE_LCD_BITMAP 975#endif // #ifdef HAVE_LCD_BITMAP