implement actions in the plugins, bubbles and metronome converted.

(hopefully buttons are correct, let me know in
http://forums.rockbox.org/index.php?topic=5829.0 if there is a major
stuff up)


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11535 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2006-11-16 02:53:44 +00:00
parent 4072848184
commit 7b8b0ff491
7 changed files with 306 additions and 252 deletions

View file

@ -161,7 +161,8 @@ int get_action_worker(int context, int timeout,
ret = do_button_check(items,button,last_button,&i); ret = do_button_check(items,button,last_button,&i);
if (context ==(int)CONTEXT_STOPSEARCHING) if ((context ==(int)CONTEXT_STOPSEARCHING) ||
items == NULL )
break; break;
if (ret == ACTION_UNKNOWN ) if (ret == ACTION_UNKNOWN )

View file

@ -210,6 +210,8 @@ enum {
ACTION_KBD_MORSE_INPUT, ACTION_KBD_MORSE_INPUT,
ACTION_KBD_MORSE_SELECT, ACTION_KBD_MORSE_SELECT,
LAST_ACTION_PLACEHOLDER, /* custom actions should be this + something */
}; };
struct button_mapping { struct button_mapping {

View file

@ -21,6 +21,7 @@
#include "plugin.h" #include "plugin.h"
#include "xlcd.h" #include "xlcd.h"
#include "pluginlib_actions.h"
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
@ -53,93 +54,6 @@ PLUGIN_HEADER
#define NUM_COMPRESS 9 #define NUM_COMPRESS 9
#define MAX_SHOTTIME 1000 #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 */ /* bubbles will consume height of 10*ROW_HEIGHT+2*(BUBBLE_HEIGHT-1)+BUBBLE_HEIGHT/2 */
/* 24x24 bubbles (iPod Video) */ /* 24x24 bubbles (iPod Video) */
#if (LCD_HEIGHT == 240) && (LCD_WIDTH == 320) #if (LCD_HEIGHT == 240) && (LCD_WIDTH == 320)
@ -2395,31 +2309,29 @@ static int bubbles_handlebuttons(struct game_context* bb, bool animblock,
int button; int button;
int buttonres; int buttonres;
long start; long start;
const struct button_mapping *plugin_contexts[]
button = rb->button_get_w_tmo(timeout); = {generic_directions,generic_actions};
button = pluginlib_getaction(rb,timeout,plugin_contexts,2);
#ifdef HAS_BUTTON_HOLD #ifdef HAS_BUTTON_HOLD
if (rb->button_hold()) if (rb->button_hold())
button = BUBBLES_START; button = PLA_START;
#endif #endif
switch(button){ switch(button){
case (BUBBLES_LEFT|BUTTON_REPEAT): case PLA_LEFT_REPEAT:
if(bb->angle > MIN_ANGLE) bb->angle -= 4; 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; if(bb->angle > MIN_ANGLE) bb->angle -= 2;
break; break;
case (BUBBLES_RIGHT|BUTTON_REPEAT): case PLA_RIGHT_REPEAT:
if(bb->angle < MAX_ANGLE) bb->angle += 4; 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; if(bb->angle < MAX_ANGLE) bb->angle += 2;
break; break;
case BUBBLES_SELECT: /* fire the shot */ case PLA_FIRE: /* fire the shot */
#if CONFIG_KEYPAD == IRIVER_H10_PAD
case BUBBLES_UP: /* easier to press on H10 */
#endif
if(!animblock) { if(!animblock) {
bb->elapsedlvl += bb->elapsedshot; bb->elapsedlvl += bb->elapsedshot;
bb->elapsedshot = 0; bb->elapsedshot = 0;
@ -2431,29 +2343,27 @@ static int bubbles_handlebuttons(struct game_context* bb, bool animblock,
} }
break; break;
case BUBBLES_START: /* pause the game */ case PLA_START: /* pause the game */
start = *rb->current_tick; start = *rb->current_tick;
rb->splash(1, true, "Paused"); 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; bb->startedshot += *rb->current_tick-start;
bubbles_drawboard(bb); bubbles_drawboard(bb);
rb->lcd_update(); rb->lcd_update();
break; break;
case BUBBLES_RESUME: /* save and end the game */ case PLA_MENU: /* save and end the game */
if(!animblock) { if(!animblock) {
rb->splash(HZ/2, true, "Saving game..."); rb->splash(HZ/2, true, "Saving game...");
bubbles_savegame(bb); bubbles_savegame(bb);
return BB_END; return BB_END;
} }
break; break;
#ifdef BUBBLES_RC_QUIT case PLA_QUIT: /* end the game */
case BUBBLES_RC_QUIT:
#endif
case BUBBLES_QUIT: /* end the game */
return BB_END; return BB_END;
case BUTTON_NONE: /* no button pressed */ case ACTION_UNKNOWN: /* no button pressed */
break; break;
default: default:
@ -2479,6 +2389,8 @@ static int bubbles(struct game_context* bb) {
bool startgame = false; bool startgame = false;
bool showscores = false; bool showscores = false;
long timeout; long timeout;
const struct button_mapping *plugin_contexts[]
= {generic_directions,generic_actions};
bubbles_setcolors(); bubbles_setcolors();
@ -2578,23 +2490,20 @@ static int bubbles(struct game_context* bb) {
rb->lcd_update(); rb->lcd_update();
/* handle menu button presses */ /* handle menu button presses */
button = rb->button_get(true); button = pluginlib_getaction(rb,timeout,plugin_contexts,2);
switch(button){ switch(button){
case BUBBLES_START: /* start playing */ case PLA_START: /* start playing */
bb->level = startlevel; bb->level = startlevel;
startgame = true; startgame = true;
break; break;
#ifdef BUBBLES_RC_QUIT case PLA_QUIT: /* quit program */
case BUBBLES_RC_QUIT:
#endif
case BUBBLES_QUIT: /* quit program */
if(showscores) { if(showscores) {
showscores = false; showscores = false;
break; break;
} }
return BB_QUIT; return BB_QUIT;
case BUBBLES_RESUME: /* resume game */ case PLA_MENU: /* resume game */
if(!bubbles_loadgame(bb)) { if(!bubbles_loadgame(bb)) {
rb->splash(HZ*2, true, "Nothing to resume"); rb->splash(HZ*2, true, "Nothing to resume");
} else { } else {
@ -2602,12 +2511,12 @@ static int bubbles(struct game_context* bb) {
} }
break; break;
case BUBBLES_SELECT: /* toggle high scores */ case PLA_FIRE: /* toggle high scores */
showscores = !showscores; showscores = !showscores;
break; break;
case (BUBBLES_UP|BUTTON_REPEAT): case PLA_UP: /* increase starting level */
case BUBBLES_UP: /* increase starting level */ case PLA_UP_REPEAT:
if(startlevel >= bb->highlevel) { if(startlevel >= bb->highlevel) {
startlevel = 0; startlevel = 0;
} else { } else {
@ -2615,8 +2524,8 @@ static int bubbles(struct game_context* bb) {
} }
break; break;
case (BUBBLES_DOWN|BUTTON_REPEAT): case PLA_DOWN: /* decrease starting level */
case BUBBLES_DOWN: /* decrease starting level */ case PLA_DOWN_REPEAT:
if(startlevel <= 0) { if(startlevel <= 0) {
startlevel = bb->highlevel; startlevel = bb->highlevel;
} else { } else {

View file

@ -25,3 +25,4 @@ xlcd_scroll.c
bmp.c bmp.c
#endif #endif
#endif #endif
pluginlib_actions.c

View file

@ -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);
}

View file

@ -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__ */

View file

@ -17,100 +17,44 @@
* *
****************************************************************************/ ****************************************************************************/
#include "plugin.h" #include "plugin.h"
#include "pluginlib_actions.h"
PLUGIN_HEADER PLUGIN_HEADER
/* variable button definitions */ #define METRONOME_QUIT PLA_QUIT
#if CONFIG_KEYPAD == RECORDER_PAD #define METRONOME_VOL_UP PLA_UP
#define METRONOME_QUIT BUTTON_OFF #define METRONOME_VOL_DOWN PLA_DOWN
#define METRONOME_PLAYPAUSE BUTTON_PLAY #define METRONOME_VOL_UP_REP PLA_UP_REPEAT
#define METRONOME_VOL_UP BUTTON_UP #define METRONOME_VOL_DOWN_REP PLA_DOWN_REPEAT
#define METRONOME_VOL_DOWN BUTTON_DOWN #define METRONOME_TAP PLA_START
#define METRONOME_TAP BUTTON_ON enum {
#define METRONOME_MSG_START "press play" METRONOME_PLAY_TAP = LAST_PLUGINLIB_ACTION+1,
#define METRONOME_MSG_STOP "press pause" METRONOME_PAUSE,
METRONOME_SYNC
};
#elif CONFIG_KEYPAD == ONDIO_PAD
#define METRONOME_QUIT BUTTON_OFF #if CONFIG_KEYPAD == ONDIO_PAD
#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
#define METRONOME_MSG_START "start: mode" #define METRONOME_MSG_START "start: mode"
#define METRONOME_MSG_STOP "pause: hold mode" #define METRONOME_MSG_STOP "pause: hold mode"
static const struct button_mapping ondio_action[] =
#elif CONFIG_KEYPAD == PLAYER_PAD {
#define METRONOME_QUIT BUTTON_STOP {METRONOME_PLAY_TAP, BUTTON_MENU|BUTTON_REL, BUTTON_NONE },
#define METRONOME_PLAYPAUSE BUTTON_PLAY {METRONOME_PAUSE, BUTTON_MENU|BUTTON_REPEAT, BUTTON_NONE }
#define METRONOME_VOL_UP (BUTTON_ON | BUTTON_RIGHT) };
#define METRONOME_VOL_DOWN (BUTTON_ON | BUTTON_LEFT) #else
#define METRONOME_TAP BUTTON_ON #define METRONOME_PLAYPAUSE PLA_FIRE
#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_START "press play"
#define METRONOME_MSG_STOP "press pause" #define METRONOME_MSG_STOP "press pause"
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
(CONFIG_KEYPAD == IPOD_3G_PAD) static const struct button_mapping iriver_syncaction[] =
#define METRONOME_QUIT BUTTON_MENU {
#define METRONOME_PLAYPAUSE BUTTON_PLAY {METRONOME_SYNC, BUTTON_REC, BUTTON_NONE },
#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
#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"
#endif #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; static struct plugin_api* rb;
@ -925,6 +869,21 @@ void tap(void)
enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
int button; 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; (void)parameter;
rb = api; rb = api;
@ -947,53 +906,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
while (true){ while (true){
reset_tap = true; reset_tap = true;
button = rb->button_get(true); button = pluginlib_getaction(rb,TIMEOUT_BLOCK,
plugin_contexts,PLA_ARRAY_COUNT);
#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
switch (button) { switch (button) {
@ -1031,13 +945,13 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
#endif #endif
case METRONOME_VOL_UP: case METRONOME_VOL_UP:
case METRONOME_VOL_UP | BUTTON_REPEAT: case METRONOME_VOL_UP_REP:
change_volume(1); change_volume(1);
calc_period(); calc_period();
break; break;
case METRONOME_VOL_DOWN: case METRONOME_VOL_DOWN:
case METRONOME_VOL_DOWN | BUTTON_REPEAT: case METRONOME_VOL_DOWN_REP:
change_volume(-1); change_volume(-1);
calc_period(); calc_period();
break; break;
@ -1060,7 +974,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter){
break; break;
#endif #endif
#ifdef METRONOME_SYNC #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
case METRONOME_SYNC: case METRONOME_SYNC:
minitick = period; minitick = period;
break; break;