Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: Re: half-idea for #ifdef and key deifnition hell...

Re: half-idea for #ifdef and key deifnition hell...

From: Fredrik Íhrn <ohrn_at_chl.chalmers.se>
Date: 2006-05-29

Jonathan Gordon wrote:
> hey all,
> well iv had another play with this and i tinhk it actually works :O
> attached is a demo plugin that just tests the loop.. hopefully its all
> simple enough to understand without thinking too much..
> the idea of line 12-35 is that there would be a standard list of
> buttons that would be global so the button list would really only ever
> really need to be coded again is if some wierd combo u want isnt in
> the main list..
> as u can see. the code easily handles short/long presses of both
> individual buttons and combo's. fancy stuff like quick double press
> and short then long press would need to be done after the call.. but
> that doesnt happen very often so thats no big deal..
> also, ive only tested this in the sim so i dont know how responsive it
> feels on the actual player.. (if the attachment doesnt work iv put it
> at http://members.optusnet.com.au/jdgordy/button_test.c )
>

Having both a for-loop and a switch case to read a button seems a bit over
kill to me.

Why not turn it into a if/else if/... chain instead? That loosens the
contraints of the current switch case style without incurring to much overhead.

Also checking for key up/down, long-press, double clicks etc, should be
handled by the button driver in firmware/drivers/button.c and set as flags.

Here's a quick sample of how I'm envisioning it:

enum {
    ACTION_UP = 0,
    ACTION_DOWN,
    ACTION_FOO,
    ACTION_BAR
};

#if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)

// Maps the actions above to button defines for a specific target.
// This array could be changed at runtime to allow a user to remap buttons or
// handle stuff like the 3 different remotes that an iRiver may have.

static action_buttons [4] = {
        BUTTON_UP,
        BUTTON_DOWN | BUTTON_DBLCLICK,
        BUTTON_MODE,
        BUTTON_SELECT | BUTTON_REL
};
#endif

#if CONFIG_KEYPAD == RECORDER_PAD
static action_buttons [4] = { ... } ;
#endif

... etc ...

enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{
        int button;
        rb = api;

        button = rb->button_status ();

        if (button == action_buttons [ACTION_UP])
                DEBUGF("Up!\n");
        else if (button == action_buttons [ACTION_DOWN])
                DEBUGF("Down!\n");
        else if (button == action_buttons [ACTION_FOO])
                DEBUGF("Foo!\n");
        else if (button == action_buttons [ACTION_BAR])
                DEBUGF("Bar!\n");

}
Received on Mon May 29 10:43:51 2006


Page was last modified "Jan 10 2012" The Rockbox Crew
aaa