dev builds
themes manual
device status forums
mailing lists
IRC bugs
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 <>
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 )

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,


// 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] = {

static action_buttons [4] = { ... } ;

... 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])
        else if (button == action_buttons [ACTION_DOWN])
        else if (button == action_buttons [ACTION_FOO])
        else if (button == action_buttons [ACTION_BAR])

Received on Mon May 29 10:43:51 2006

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