diff options
author | Jens Arnold <amiconn@rockbox.org> | 2004-10-18 21:45:00 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2004-10-18 21:45:00 +0000 |
commit | e35a658ded457698aca2401b699e743a3011cfce (patch) | |
tree | cb89b7785ef2c72f7a293fe165a4d3b76e38227f /apps/plugins/oscillograph.c | |
parent | d24766675db5faddb67810ca67b37491d49c2313 (diff) |
Plugin rework 2: (all) Compile-time keyboard configuration, for Ondio adaption. (all) Now using the default event handler, standard placement is now in switch() default case. (minesweeper,pong,snake,snake2) added USB handling. (mandelbrot,mosaique) Fixed return value. (minesweeper) fast moving with button repeat. (oscillograph) Fixed cleanup in USB case.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5304 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/oscillograph.c')
-rw-r--r-- | apps/plugins/oscillograph.c | 76 |
1 files changed, 57 insertions, 19 deletions
diff --git a/apps/plugins/oscillograph.c b/apps/plugins/oscillograph.c index a34aa8bfa9..5beeb8891b 100644 --- a/apps/plugins/oscillograph.c +++ b/apps/plugins/oscillograph.c @@ -29,6 +29,28 @@ #define MAX_PEAK 0x8000 +/* variable button definitions */ +#if CONFIG_KEYPAD == RECORDER_PAD +#define OSCILLOGRAPH_QUIT BUTTON_OFF +#define OSCILLOGRAPH_SPEED_UP BUTTON_UP +#define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN +#define OSCILLOGRAPH_ROLL BUTTON_F1 +#define OSCILLOGRAPH_MODE BUTTON_F2 +#define OSCILLOGRAPH_SPEED_RESET BUTTON_F3 +#define OSCILLOGRAPH_PAUSE BUTTON_PLAY + +#elif CONFIG_KEYPAD == ONDIO_PAD +#define OSCILLOGRAPH_QUIT BUTTON_OFF +#define OSCILLOGRAPH_SPEED_UP BUTTON_UP +#define OSCILLOGRAPH_SPEED_DOWN BUTTON_DOWN +#define OSCILLOGRAPH_ROLL BUTTON_RIGHT +#define OSCILLOGRAPH_MODE BUTTON_MENU +#define OSCILLOGRAPH_SPEED_RESET BUTTON_LEFT + +#endif + +/* global api struct pointer */ +static struct plugin_api* rb; /* number of ticks between two volume samples */ static int speed = 1; /* roll == true -> lcd rolls */ @@ -37,12 +59,26 @@ static bool roll = true; static int drawMode = DRAW_MODE_FILLED; /** + * cleanup on return / usb + */ +void cleanup(void *parameter) +{ + (void)parameter; + + /* restore to default roll position. + Looks funny if you forget to do this... */ + rb->lcd_roll(0); + rb->lcd_update(); +} + +/** * Displays a vertically scrolling oscillosgraph using * hardware scrolling of the display. The user can change * speed */ -enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) +enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { + int button; /* stores current volume value left */ int left; /* stores current volume value right */ @@ -57,8 +93,9 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) bool exit = false; - TEST_PLUGIN_API(rb); + TEST_PLUGIN_API(api); (void)parameter; + rb = api; /* the main loop */ while (!exit) { @@ -135,28 +172,31 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) it must be ensured that at least 1 is passed. */ /* react to user input */ - switch (rb->button_get_w_tmo(MAX(speed, 1))) { - case BUTTON_UP: + button = rb->button_get_w_tmo(MAX(speed, 1)); + switch (button) { + case OSCILLOGRAPH_SPEED_UP: speed++; draw = true; break; - case BUTTON_DOWN: + case OSCILLOGRAPH_SPEED_DOWN: speed--; draw = true; break; - case BUTTON_PLAY: +#ifdef OSCILLOGRAPH_PAUSE + case OSCILLOGRAPH_PAUSE: /* pause the demo */ rb->button_get(true); break; +#endif - case BUTTON_F1: + case OSCILLOGRAPH_ROLL: /* toggle rolling */ roll = !roll; break; - case BUTTON_F2: + case OSCILLOGRAPH_MODE: /* step through the display modes */ drawMode ++; drawMode = drawMode % DRAW_MODE_COUNT; @@ -170,18 +210,20 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) rb->lcd_roll(0); break; - case BUTTON_F3: + case OSCILLOGRAPH_SPEED_RESET: speed = 1; draw = true; break; - case BUTTON_OFF: + case OSCILLOGRAPH_QUIT: exit = true; break; - case SYS_USB_CONNECTED: - rb->usb_screen(); - return PLUGIN_USB_CONNECTED; + default: + if (rb->default_event_handler_ex(button, cleanup, NULL) + == SYS_USB_CONNECTED) + return PLUGIN_USB_CONNECTED; + break; } if (draw) { @@ -191,14 +233,10 @@ enum plugin_status plugin_start(struct plugin_api* rb, void* parameter) rb->lcd_update_rect(0, (y + LCD_HEIGHT - 8) % LCD_HEIGHT, LCD_WIDTH, 8); } - } + } } - /* restore to default roll position. - Looks funny if you forget to do this... */ - rb->lcd_roll(0); - rb->lcd_update(); - + cleanup(NULL); /* standard return */ return PLUGIN_OK; } |