diff options
-rw-r--r-- | apps/action.c | 3 | ||||
-rw-r--r-- | apps/action.h | 2 | ||||
-rwxr-xr-x | apps/plugins/bubbles.c | 145 | ||||
-rw-r--r-- | apps/plugins/lib/SOURCES | 1 | ||||
-rw-r--r-- | apps/plugins/lib/pluginlib_actions.c | 46 | ||||
-rw-r--r-- | apps/plugins/lib/pluginlib_actions.h | 181 | ||||
-rw-r--r-- | apps/plugins/metronome.c | 180 |
7 files changed, 306 insertions, 252 deletions
diff --git a/apps/action.c b/apps/action.c index 0f332a29f5..07d3cb25a2 100644 --- a/apps/action.c +++ b/apps/action.c @@ -161,7 +161,8 @@ int get_action_worker(int context, int timeout, ret = do_button_check(items,button,last_button,&i); - if (context ==(int)CONTEXT_STOPSEARCHING) + if ((context ==(int)CONTEXT_STOPSEARCHING) || + items == NULL ) break; if (ret == ACTION_UNKNOWN ) diff --git a/apps/action.h b/apps/action.h index d3da152e35..b0725ddb41 100644 --- a/apps/action.h +++ b/apps/action.h @@ -210,6 +210,8 @@ enum { ACTION_KBD_MORSE_INPUT, ACTION_KBD_MORSE_SELECT, + + LAST_ACTION_PLACEHOLDER, /* custom actions should be this + something */ }; struct button_mapping { diff --git a/apps/plugins/bubbles.c b/apps/plugins/bubbles.c index 9ce6ee80c5..e5a094e053 100755 --- a/apps/plugins/bubbles.c +++ b/apps/plugins/bubbles.c @@ -21,6 +21,7 @@ #include "plugin.h" #include "xlcd.h" +#include "pluginlib_actions.h" #ifdef HAVE_LCD_BITMAP @@ -53,93 +54,6 @@ PLUGIN_HEADER #define NUM_COMPRESS 9 #define MAX_SHOTTIME 1000 -/* button definitions */ -#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_UP -#define BUBBLES_DOWN BUTTON_DOWN -#define BUBBLES_QUIT BUTTON_OFF -#define BUBBLES_START BUTTON_ON -#define BUBBLES_SELECT BUTTON_SELECT -#define BUBBLES_RESUME BUTTON_MODE - -#define BUBBLES_RC_QUIT BUTTON_RC_STOP - -#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD) -#define BUBBLES_LEFT BUTTON_SCROLL_BACK -#define BUBBLES_RIGHT BUTTON_SCROLL_FWD -#define BUBBLES_UP BUTTON_SCROLL_FWD -#define BUBBLES_DOWN BUTTON_SCROLL_BACK -#define BUBBLES_QUIT BUTTON_MENU|BUTTON_REL -#define BUBBLES_START BUTTON_PLAY|BUTTON_REL -#define BUBBLES_SELECT BUTTON_SELECT -#define BUBBLES_RESUME BUTTON_RIGHT|BUTTON_LEFT - -#elif CONFIG_KEYPAD == IAUDIO_X5_PAD -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_UP -#define BUBBLES_DOWN BUTTON_DOWN -#define BUBBLES_QUIT BUTTON_POWER -#define BUBBLES_START BUTTON_PLAY -#define BUBBLES_SELECT BUTTON_SELECT -#define BUBBLES_RESUME BUTTON_REC - -#elif CONFIG_KEYPAD == GIGABEAT_PAD -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_UP -#define BUBBLES_DOWN BUTTON_DOWN -#define BUBBLES_QUIT BUTTON_A -#define BUBBLES_START BUTTON_POWER -#define BUBBLES_SELECT BUTTON_SELECT -#define BUBBLES_RESUME BUTTON_MENU - -#elif CONFIG_KEYPAD == RECORDER_PAD -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_UP -#define BUBBLES_DOWN BUTTON_DOWN -#define BUBBLES_QUIT BUTTON_OFF -#define BUBBLES_START BUTTON_ON -#define BUBBLES_SELECT BUTTON_PLAY -#define BUBBLES_RESUME BUTTON_F1 - -#elif CONFIG_KEYPAD == ONDIO_PAD -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_RIGHT -#define BUBBLES_DOWN BUTTON_LEFT -#define BUBBLES_QUIT BUTTON_OFF -#define BUBBLES_START BUTTON_MENU -#define BUBBLES_SELECT BUTTON_UP -#define BUBBLES_RESUME BUTTON_DOWN - -#elif CONFIG_KEYPAD == SANSA_E200_PAD -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_SCROLL_UP -#define BUBBLES_DOWN BUTTON_SCROLL_DOWN -#define BUBBLES_QUIT BUTTON_POWER -#define BUBBLES_START BUTTON_PLAY -#define BUBBLES_SELECT BUTTON_SELECT -#define BUBBLES_RESUME BUTTON_DOWN - -#elif CONFIG_KEYPAD == IRIVER_H10_PAD -#define BUBBLES_LEFT BUTTON_LEFT -#define BUBBLES_RIGHT BUTTON_RIGHT -#define BUBBLES_UP BUTTON_SCROLL_UP -#define BUBBLES_DOWN BUTTON_SCROLL_DOWN -#define BUBBLES_QUIT BUTTON_POWER -#define BUBBLES_START BUTTON_PLAY -#define BUBBLES_SELECT BUTTON_REW -#define BUBBLES_RESUME BUTTON_FF - -#else - #error BUBBLES: Unsupported keypad -#endif - /* bubbles will consume height of 10*ROW_HEIGHT+2*(BUBBLE_HEIGHT-1)+BUBBLE_HEIGHT/2 */ /* 24x24 bubbles (iPod Video) */ #if (LCD_HEIGHT == 240) && (LCD_WIDTH == 320) @@ -2395,31 +2309,29 @@ static int bubbles_handlebuttons(struct game_context* bb, bool animblock, int button; int buttonres; long start; - - button = rb->button_get_w_tmo(timeout); + const struct button_mapping *plugin_contexts[] + = {generic_directions,generic_actions}; + button = pluginlib_getaction(rb,timeout,plugin_contexts,2); #ifdef HAS_BUTTON_HOLD if (rb->button_hold()) - button = BUBBLES_START; + button = PLA_START; #endif switch(button){ - case (BUBBLES_LEFT|BUTTON_REPEAT): + case PLA_LEFT_REPEAT: if(bb->angle > MIN_ANGLE) bb->angle -= 4; - case BUBBLES_LEFT: /* change angle to the left */ + case PLA_LEFT: /* change angle to the left */ if(bb->angle > MIN_ANGLE) bb->angle -= 2; break; - case (BUBBLES_RIGHT|BUTTON_REPEAT): + case PLA_RIGHT_REPEAT: if(bb->angle < MAX_ANGLE) bb->angle += 4; - case BUBBLES_RIGHT: /* change angle to the right */ + case PLA_RIGHT: /* change angle to the right */ if(bb->angle < MAX_ANGLE) bb->angle += 2; break; - case BUBBLES_SELECT: /* fire the shot */ -#if CONFIG_KEYPAD == IRIVER_H10_PAD - case BUBBLES_UP: /* easier to press on H10 */ -#endif + case PLA_FIRE: /* fire the shot */ if(!animblock) { bb->elapsedlvl += bb->elapsedshot; bb->elapsedshot = 0; @@ -2431,29 +2343,27 @@ static int bubbles_handlebuttons(struct game_context* bb, bool animblock, } break; - case BUBBLES_START: /* pause the game */ + case PLA_START: /* pause the game */ start = *rb->current_tick; rb->splash(1, true, "Paused"); - while(rb->button_get(true) != (BUBBLES_START)); + while(pluginlib_getaction(rb,TIMEOUT_BLOCK,plugin_contexts,2) + != (PLA_START)); bb->startedshot += *rb->current_tick-start; bubbles_drawboard(bb); rb->lcd_update(); break; - case BUBBLES_RESUME: /* save and end the game */ + case PLA_MENU: /* save and end the game */ if(!animblock) { rb->splash(HZ/2, true, "Saving game..."); bubbles_savegame(bb); return BB_END; } break; -#ifdef BUBBLES_RC_QUIT - case BUBBLES_RC_QUIT: -#endif - case BUBBLES_QUIT: /* end the game */ + case PLA_QUIT: /* end the game */ return BB_END; - case BUTTON_NONE: /* no button pressed */ + case ACTION_UNKNOWN: /* no button pressed */ break; default: @@ -2479,6 +2389,8 @@ static int bubbles(struct game_context* bb) { bool startgame = false; bool showscores = false; long timeout; + const struct button_mapping *plugin_contexts[] + = {generic_directions,generic_actions}; bubbles_setcolors(); @@ -2578,23 +2490,20 @@ static int bubbles(struct game_context* bb) { rb->lcd_update(); /* handle menu button presses */ - button = rb->button_get(true); + button = pluginlib_getaction(rb,timeout,plugin_contexts,2); switch(button){ - case BUBBLES_START: /* start playing */ + case PLA_START: /* start playing */ bb->level = startlevel; startgame = true; break; -#ifdef BUBBLES_RC_QUIT - case BUBBLES_RC_QUIT: -#endif - case BUBBLES_QUIT: /* quit program */ + case PLA_QUIT: /* quit program */ if(showscores) { showscores = false; break; } return BB_QUIT; - case BUBBLES_RESUME: /* resume game */ + case PLA_MENU: /* resume game */ if(!bubbles_loadgame(bb)) { rb->splash(HZ*2, true, "Nothing to resume"); } else { @@ -2602,12 +2511,12 @@ static int bubbles(struct game_context* bb) { } break; - case BUBBLES_SELECT: /* toggle high scores */ + case PLA_FIRE: /* toggle high scores */ showscores = !showscores; break; - case (BUBBLES_UP|BUTTON_REPEAT): - case BUBBLES_UP: /* increase starting level */ + case PLA_UP: /* increase starting level */ + case PLA_UP_REPEAT: if(startlevel >= bb->highlevel) { startlevel = 0; } else { @@ -2615,8 +2524,8 @@ static int bubbles(struct game_context* bb) { } break; - case (BUBBLES_DOWN|BUTTON_REPEAT): - case BUBBLES_DOWN: /* decrease starting level */ + case PLA_DOWN: /* decrease starting level */ + case PLA_DOWN_REPEAT: if(startlevel <= 0) { startlevel = bb->highlevel; } else { diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES index 6002934ac0..d57db3bbc8 100644 --- a/apps/plugins/lib/SOURCES +++ b/apps/plugins/lib/SOURCES @@ -25,3 +25,4 @@ xlcd_scroll.c bmp.c #endif #endif +pluginlib_actions.c diff --git a/apps/plugins/lib/pluginlib_actions.c b/apps/plugins/lib/pluginlib_actions.c new file mode 100644 index 0000000000..312eb61ea6 --- /dev/null +++ b/apps/plugins/lib/pluginlib_actions.c @@ -0,0 +1,46 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2006 Jonathan Gordon +* +* +* All files in this archive are subject to the GNU General Public License. +* See the file COPYING in the source tree root for full license agreement. +* +* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +* KIND, either express or implied. +* +****************************************************************************/ + +#include "plugin.h" +#include "action.h" +#include "pluginlib_actions.h" + +static struct button_mapping **plugin_context_order; +static int plugin_context_count = 0; +static int last_context = 0; /* index into plugin_context_order + of the last context returned */ + +const struct button_mapping* get_context_map(int context) +{ + (void)context; + if (last_context<plugin_context_count) + return plugin_context_order[last_context++]; + else return NULL; +} + +int pluginlib_getaction(struct plugin_api *api,int timeout, + const struct button_mapping *plugin_contexts[], + int count) +{ + plugin_context_order = (struct button_mapping **)plugin_contexts; + plugin_context_count = count; + last_context = 0; + return api->get_custom_action(CONTEXT_CUSTOM,timeout,get_context_map); +} diff --git a/apps/plugins/lib/pluginlib_actions.h b/apps/plugins/lib/pluginlib_actions.h new file mode 100644 index 0000000000..8dcd2b653d --- /dev/null +++ b/apps/plugins/lib/pluginlib_actions.h @@ -0,0 +1,181 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2006 Jonathan Gordon +* +* +* All files in this archive are subject to the GNU General Public License. +* See the file COPYING in the source tree root for full license agreement. +* +* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +* KIND, either express or implied. +* +****************************************************************************/ + +#ifndef __PLUGINLIB_ACTIONS_H__ +#define __PLUGINLIB_ACTIONS_H__ + +#include "config.h" +#include "plugin.h" +#include "action.h" + +/* PLA stands for Plugin Lib Action :P */ +enum { + PLA_UP = LAST_ACTION_PLACEHOLDER+1, + PLA_DOWN, + PLA_LEFT, + PLA_RIGHT, + PLA_UP_REPEAT, + PLA_DOWN_REPEAT, + PLA_LEFT_REPEAT, + PLA_RIGHT_REPEAT, + + PLA_QUIT, + PLA_START, + PLA_MENU, + PLA_FIRE, + PLA_FIRE_REPEAT, + + LAST_PLUGINLIB_ACTION +}; + +static const struct button_mapping generic_directions[] = +{ +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) \ + || (CONFIG_KEYPAD == IRIVER_H300_PAD) \ + || (CONFIG_KEYPAD == IAUDIO_X5_PAD) \ + || (CONFIG_KEYPAD == GIGABEAT_PAD) \ + || (CONFIG_KEYPAD == RECORDER_PAD) \ + || (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) + { PLA_UP, BUTTON_UP, BUTTON_NONE}, + { PLA_DOWN, BUTTON_DOWN, BUTTON_NONE}, + { PLA_LEFT, BUTTON_LEFT, BUTTON_NONE}, + { PLA_RIGHT, BUTTON_RIGHT, BUTTON_NONE}, + { PLA_UP_REPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_DOWN_REPEAT, BUTTON_DOWN|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_LEFT_REPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_RIGHT_REPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD) + { PLA_UP, BUTTON_SCROLL_FWD, BUTTON_NONE}, + { PLA_DOWN, BUTTON_SCROLL_BACK, BUTTON_NONE}, + { PLA_LEFT, BUTTON_SCROLL_BACK, BUTTON_NONE}, + { PLA_RIGHT, BUTTON_SCROLL_FWD, BUTTON_NONE}, + { PLA_UP_REPEAT, BUTTON_SCROLL_FWD, BUTTON_NONE}, + { PLA_DOWN_REPEAT, BUTTON_SCROLL_BACK, BUTTON_NONE}, + { PLA_LEFT_REPEAT, BUTTON_SCROLL_BACK, BUTTON_NONE}, + { PLA_RIGHT_REPEAT, BUTTON_SCROLL_FWD, BUTTON_NONE}, +#elif CONFIG_KEYPAD == ONDIO_PAD + { PLA_UP, BUTTON_RIGHT, BUTTON_NONE}, + { PLA_DOWN, BUTTON_LEFT, BUTTON_NONE}, + { PLA_LEFT, BUTTON_LEFT, BUTTON_NONE}, + { PLA_RIGHT, BUTTON_RIGHT, BUTTON_NONE}, + { PLA_UP_REPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_DOWN_REPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_LEFT_REPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_RIGHT_REPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == PLAYER_PAD + {PLA_UP, BUTTON_STOP, BUTTON_NONE}, + {PLA_DOWN, BUTTON_PLAY, BUTTON_NONE}, + {PLA_LEFT, BUTTON_LEFT, BUTTON_NONE}, + {PLA_RIGHT, BUTTON_RIGHT, BUTTON_NONE}, + {PLA_UP_REPEAT, BUTTON_STOP|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_DOWN_REPEAT, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_LEFT_REPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_RIGHT_REPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == SANSA_E200_PAD) \ + || (CONFIG_KEYPAD == IRIVER_H10_PAD) + { PLA_UP, BUTTON_SCROLL_UP, BUTTON_NONE}, + { PLA_DOWN, BUTTON_SCROLL_DOWN, BUTTON_NONE}, + { PLA_LEFT, BUTTON_LEFT, BUTTON_NONE}, + { PLA_RIGHT, BUTTON_RIGHT, BUTTON_NONE}, + { PLA_UP_REPEAT, BUTTON_SCROLL_UP|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_DOWN_REPEAT, BUTTON_SCROLL_DOWN|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_LEFT_REPEAT, BUTTON_LEFT|BUTTON_REPEAT, BUTTON_NONE}, + { PLA_RIGHT_REPEAT, BUTTON_RIGHT|BUTTON_REPEAT, BUTTON_NONE}, +#else + #error pluginlib_actions: Unsupported keypad +#endif + {CONTEXT_CUSTOM,BUTTON_NONE,BUTTON_NONE} +}; + +/* these were taken from the bubbles plugin, so may need tweaking */ +static const struct button_mapping generic_actions[] = +{ +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) + {PLA_QUIT, BUTTON_OFF, BUTTON_NONE}, + {PLA_QUIT, BUTTON_RC_STOP, BUTTON_NONE}, + {PLA_START, BUTTON_ON, BUTTON_NONE}, + {PLA_MENU, BUTTON_MODE, BUTTON_NONE}, + {PLA_FIRE, BUTTON_SELECT, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, +#elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD) + {PLA_QUIT, BUTTON_MENU|BUTTON_SELECT, BUTTON_NONE}, + {PLA_START, BUTTON_PLAY|BUTTON_REL, BUTTON_PLAY}, + {PLA_MENU, BUTTON_MENU, BUTTON_NONE}, + {PLA_FIRE, BUTTON_SELECT|BUTTON_REL, BUTTON_SELECT}, + {PLA_FIRE_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == IAUDIO_X5_PAD + {PLA_QUIT, BUTTON_POWER, BUTTON_NONE}, + {PLA_START, BUTTON_PLAY, BUTTON_NONE}, + {PLA_MENU, BUTTON_REC, BUTTON_NONE}, + {PLA_FIRE, BUTTON_SELECT, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == GIGABEAT_PAD + {PLA_QUIT, BUTTON_A, BUTTON_NONE}, + {PLA_START, BUTTON_POWER, BUTTON_NONE}, + {PLA_MENU, BUTTON_MENU, BUTTON_NONE}, + {PLA_FIRE, BUTTON_SELECT, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == RECORDER_PAD + {PLA_QUIT, BUTTON_OFF, BUTTON_NONE}, + {PLA_START, BUTTON_ON, BUTTON_NONE}, + {PLA_MENU, BUTTON_F1, BUTTON_NONE}, + {PLA_FIRE, BUTTON_PLAY, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == ONDIO_PAD + {PLA_QUIT, BUTTON_OFF, BUTTON_NONE}, + {PLA_START, BUTTON_MENU, BUTTON_NONE}, + {PLA_MENU, BUTTON_DOWN, BUTTON_NONE}, + {PLA_FIRE, BUTTON_UP, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_UP|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == PLAYER_PAD + {PLA_QUIT, BUTTON_STOP|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_START, BUTTON_PLAY|BUTTON_REPEAT, BUTTON_NONE}, + {PLA_MENU, BUTTON_MENU, BUTTON_NONE}, + {PLA_FIRE, BUTTON_ON, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_ON|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == SANSA_E200_PAD + {PLA_QUIT, BUTTON_POWER, BUTTON_NONE}, + {PLA_START, BUTTON_PLAY, BUTTON_NONE}, + {PLA_MENU, BUTTON_DOWN, BUTTON_NONE}, + {PLA_FIRE, BUTTON_SELECT, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == IRIVER_H10_PAD + {PLA_QUIT, BUTTON_POWER, BUTTON_NONE}, + {PLA_START, BUTTON_PLAY, BUTTON_NONE}, + {PLA_MENU, BUTTON_FF, BUTTON_NONE}, + {PLA_FIRE, BUTTON_REW, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_REW|BUTTON_REPEAT, BUTTON_NONE}, +#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD + {PLA_QUIT, BUTTON_EQ, BUTTON_NONE}, + {PLA_START, BUTTON_PLAY, BUTTON_NONE}, + {PLA_MENU, BUTTON_MODE, BUTTON_NONE}, + {PLA_FIRE, BUTTON_SELECT, BUTTON_NONE}, + {PLA_FIRE_REPEAT, BUTTON_SELECT|BUTTON_REPEAT, BUTTON_NONE}, +#else + #error pluginlib_actions: Unsupported keypad +#endif + {CONTEXT_CUSTOM,BUTTON_NONE,BUTTON_NONE} +}; + +int pluginlib_getaction(struct plugin_api *api,int timeout, + const struct button_mapping *plugin_contexts[], + int count); + +#endif /* __PLUGINLIB_ACTIONS_H__ */ diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index 7a975f434d..45a870b65b 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c @@ -17,100 +17,44 @@ * ****************************************************************************/ #include "plugin.h" +#include "pluginlib_actions.h" PLUGIN_HEADER -/* variable button definitions */ -#if CONFIG_KEYPAD == RECORDER_PAD -#define METRONOME_QUIT BUTTON_OFF -#define METRONOME_PLAYPAUSE BUTTON_PLAY -#define METRONOME_VOL_UP BUTTON_UP -#define METRONOME_VOL_DOWN BUTTON_DOWN -#define METRONOME_TAP BUTTON_ON -#define METRONOME_MSG_START "press play" -#define METRONOME_MSG_STOP "press pause" +#define METRONOME_QUIT PLA_QUIT +#define METRONOME_VOL_UP PLA_UP +#define METRONOME_VOL_DOWN PLA_DOWN +#define METRONOME_VOL_UP_REP PLA_UP_REPEAT +#define METRONOME_VOL_DOWN_REP PLA_DOWN_REPEAT +#define METRONOME_TAP PLA_START +enum { + METRONOME_PLAY_TAP = LAST_PLUGINLIB_ACTION+1, + METRONOME_PAUSE, + METRONOME_SYNC +}; -#elif CONFIG_KEYPAD == ONDIO_PAD -#define METRONOME_QUIT BUTTON_OFF -#define METRONOME_PLAY_TAP BUTTON_MENU -#define METRONOME_PAUSE (BUTTON_MENU | BUTTON_REPEAT) -#define METRONOME_VOL_UP BUTTON_UP -#define METRONOME_VOL_DOWN BUTTON_DOWN + +#if CONFIG_KEYPAD == ONDIO_PAD #define METRONOME_MSG_START "start: mode" #define METRONOME_MSG_STOP "pause: hold mode" - -#elif CONFIG_KEYPAD == PLAYER_PAD -#define METRONOME_QUIT BUTTON_STOP -#define METRONOME_PLAYPAUSE BUTTON_PLAY -#define METRONOME_VOL_UP (BUTTON_ON | BUTTON_RIGHT) -#define METRONOME_VOL_DOWN (BUTTON_ON | BUTTON_LEFT) -#define METRONOME_TAP BUTTON_ON - -#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) -#define METRONOME_QUIT BUTTON_OFF -#define METRONOME_PLAYPAUSE BUTTON_ON -#define METRONOME_VOL_UP BUTTON_UP -#define METRONOME_VOL_DOWN BUTTON_DOWN -#define METRONOME_TAP BUTTON_SELECT -#define METRONOME_SYNC BUTTON_REC -#define METRONOME_MSG_START "press play" -#define METRONOME_MSG_STOP "press pause" - -#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ - (CONFIG_KEYPAD == IPOD_3G_PAD) -#define METRONOME_QUIT BUTTON_MENU -#define METRONOME_PLAYPAUSE BUTTON_PLAY -#define METRONOME_VOL_UP BUTTON_SCROLL_FWD -#define METRONOME_VOL_DOWN BUTTON_SCROLL_BACK -#define METRONOME_TAP BUTTON_SELECT -#define METRONOME_MSG_START "press play" -#define METRONOME_MSG_STOP "press pause" - -#elif (CONFIG_KEYPAD == IAUDIO_X5_PAD) -#define METRONOME_QUIT BUTTON_POWER -#define METRONOME_PLAYPAUSE BUTTON_PLAY -#define METRONOME_VOL_UP BUTTON_UP -#define METRONOME_VOL_DOWN BUTTON_DOWN -#define METRONOME_TAP BUTTON_REC +static const struct button_mapping ondio_action[] = +{ + {METRONOME_PLAY_TAP, BUTTON_MENU|BUTTON_REL, BUTTON_NONE }, + {METRONOME_PAUSE, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE } +}; +#else +#define METRONOME_PLAYPAUSE PLA_FIRE #define METRONOME_MSG_START "press play" #define METRONOME_MSG_STOP "press pause" -#elif (CONFIG_KEYPAD == IRIVER_IFP7XX_PAD) -#define METRONOME_QUIT BUTTON_MODE -#define METRONOME_PLAYPAUSE BUTTON_PLAY -#define METRONOME_VOL_UP BUTTON_UP -#define METRONOME_VOL_DOWN BUTTON_DOWN -#define METRONOME_TAP BUTTON_EQ -#define METRONOME_MSG_START "press play" -#define METRONOME_MSG_STOP "press pause" +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) +static const struct button_mapping iriver_syncaction[] = +{ + {METRONOME_SYNC, BUTTON_REC, BUTTON_NONE }, +}; #endif +#endif /* #if CONFIG_KEYPAD == ONDIO_PAD */ -#if CONFIG_REMOTE_KEYPAD == H100_REMOTE -#define METRONOME_R_QUIT BUTTON_RC_STOP -#define METRONOME_R_PLAYPAUSE BUTTON_RC_ON -#define METRONOME_R_VOL_UP BUTTON_RC_VOL_UP -#define METRONOME_R_VOL_DOWN BUTTON_RC_VOL_DOWN -#define METRONOME_R_TAP BUTTON_RC_BITRATE - -#elif CONFIG_KEYPAD == SANSA_E200_PAD -#define METRONOME_QUIT BUTTON_POWER -#define METRONOME_PLAYPAUSE BUTTON_UP -#define METRONOME_VOL_UP BUTTON_SCROLL_UP -#define METRONOME_VOL_DOWN BUTTON_SCROLL_DOWN -#define METRONOME_TAP BUTTON_SELECT -#define METRONOME_MSG_START "press play" -#define METRONOME_MSG_STOP "press pause" - -#elif CONFIG_KEYPAD == IRIVER_H10_PAD -#define METRONOME_QUIT BUTTON_POWER -#define METRONOME_PLAYPAUSE BUTTON_PLAY -#define METRONOME_VOL_UP BUTTON_SCROLL_UP -#define METRONOME_VOL_DOWN BUTTON_SCROLL_DOWN -#define METRONOME_TAP BUTTON_FF -#define METRONOME_MSG_START "press play" -#define METRONOME_MSG_STOP "press pause" - -#endif static struct plugin_api* rb; @@ -925,6 +869,21 @@ void tap(void) enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ int button; + const struct button_mapping *plugin_contexts[] + = {generic_directions, +#if CONFIG_KEYPAD == ONDIO_PAD + ondio_action, +#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) + iriver_syncaction, +#endif + generic_actions}; +#if (CONFIG_KEYPAD == ONDIO_PAD) \ + || (CONFIG_KEYPAD == IRIVER_H100_PAD) \ + || (CONFIG_KEYPAD == IRIVER_H300_PAD) +#define PLA_ARRAY_COUNT 3 +#else +#define PLA_ARRAY_COUNT 2 +#endif (void)parameter; rb = api; @@ -947,53 +906,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ while (true){ reset_tap = true; - button = rb->button_get(true); - -#if CONFIG_REMOTE_KEYPAD == H100_REMOTE - if(button && BUTTON_REMOTE) { - switch(button) { - case BUTTON_RC_STOP: - button = METRONOME_QUIT; - break; - case BUTTON_RC_ON: - button = METRONOME_PLAYPAUSE; - break; - case BUTTON_RC_VOL_UP: - button = METRONOME_VOL_UP; - break; - case BUTTON_RC_VOL_UP | BUTTON_REPEAT: - button = METRONOME_VOL_UP | BUTTON_REPEAT; - break; - case BUTTON_RC_VOL_DOWN: - button = METRONOME_VOL_DOWN; - break; - case BUTTON_RC_VOL_DOWN | BUTTON_REPEAT: - button = METRONOME_VOL_DOWN | BUTTON_REPEAT; - break; - case BUTTON_RC_FF: - button = BUTTON_RIGHT; - break; - case BUTTON_RC_FF | BUTTON_REPEAT: - button = BUTTON_RIGHT | BUTTON_REPEAT; - break; - case BUTTON_RC_REW: - button = BUTTON_LEFT; - break; - case BUTTON_RC_REW | BUTTON_REPEAT: - button = BUTTON_LEFT | BUTTON_REPEAT; - break; - case BUTTON_RC_MODE: - button = METRONOME_SYNC; - break; - case BUTTON_RC_REC: - case BUTTON_RC_SOURCE: - case BUTTON_RC_MENU: - case BUTTON_RC_BITRATE: - button = METRONOME_TAP; - break; - } - } -#endif + button = pluginlib_getaction(rb,TIMEOUT_BLOCK, + plugin_contexts,PLA_ARRAY_COUNT); switch (button) { @@ -1031,13 +945,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ #endif case METRONOME_VOL_UP: - case METRONOME_VOL_UP | BUTTON_REPEAT: + case METRONOME_VOL_UP_REP: change_volume(1); calc_period(); break; case METRONOME_VOL_DOWN: - case METRONOME_VOL_DOWN | BUTTON_REPEAT: + case METRONOME_VOL_DOWN_REP: change_volume(-1); calc_period(); break; @@ -1060,7 +974,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ break; #endif -#ifdef METRONOME_SYNC +#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) case METRONOME_SYNC: minitick = period; break; |