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 )
On 24/03/06, Jonathan Gordon <[EMAIL PROTECTED]> wrote:
On 24/03/06, Brandon Low <[EMAIL PROTECTED]> wrote: > Yer a smart one. :) > > I hoep you keep noodling on this while we're all busy doing 3.0 :) ye, thats why im playing with it.. figured i may aswell do something while everyone else is getting ready for 3.0 > > On Fri, 03/24/06 at 12:08:47 +1100, Jonathan Gordon wrote: > > maybe we do a simple last button cache thing? > > i.e if button == last_button then start the loop at the last i.. > > of, even just cache the last return_code and return that imediatly.. i > > think that would work? > > > > On 24/03/06, Brandon Low <[EMAIL PROTECTED]> wrote: > > > Scroll events happen frequently enough to be worth concern, as do > > > button_repeat events... > > > > > > Darn those remote controls. > > > > > > Brandon > > > > > > On Thu, 03/23/06 at 14:45:07 +0100, Bj?rn Stenberg wrote: > > > > Brandon Low wrote: > > > > > I think that button processing can't be going through lists like that, > > > > > too slow. > > > > > > > > I'm not so sure. Buttons are pressed rather rarely (from a system/cpu point of view) and the lag cause by looping through a few dozen entries will probably not be measurable, let alone noticeable. > > > > > > > > The case for using variable button mapping is mainly driven by the fact that irivers can have several different remote controls, and change between then in runtime. Handling that requires more flexibility than #defines can provide. > > > > > > > > -- > > > > Bj?rn > > > >
#include "plugin.h" PLUGIN_HEADER static struct plugin_api* rb; struct ButtonItem { int button_code; int ret_code; int pre_button_relative_index; } ; enum { ACTION_UNUSED = -1, ACTION_NONE = 0, ACTION_UP, ACTION_DOWN, ACTION_LEFT, ACTION_RIGHT, ACTION_SELECT, ACTION_MENU, }; static struct ButtonItem standard_buttons #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ (CONFIG_KEYPAD == IRIVER_H300_PAD) [6/* button count*/] = { {BUTTON_UP,ACTION_UP,0}, {BUTTON_DOWN,ACTION_DOWN,0}, {BUTTON_LEFT,ACTION_LEFT,0}, {BUTTON_RIGHT,ACTION_RIGHT,0}, {BUTTON_SELECT,ACTION_SELECT,0}, {BUTTON_MODE,ACTION_MENU,0}, #endif }; /* static struct ButtonItem standard_buttons */ int read_button(struct ButtonItem *items, int button_count, int timeout) { static int last_button = BUTTON_NONE; static struct ButtonItem *last_button_list = NULL; static int last_i = 0; int button; int i=0; int ret; if (timeout) button = rb->button_get_w_tmo(timeout); else button = rb->button_get(1); if (button == BUTTON_NONE || button == SYS_USB_CONNECTED) { last_button = button; last_i=0; last_button_list = NULL; return button; } if ((last_button == button) && (items == last_button_list)) i = last_i; ret = BUTTON_NONE; /* in case the button is not in the list */ while (i<button_count) { if (items[i].button_code == button) { if (items[i].pre_button_relative_index) { if ((items[i-items[i].pre_button_relative_index].button_code == last_button) || (items[i-items[i].pre_button_relative_index].button_code == BUTTON_NONE) || (items[i].button_code == last_button)) { ret = items[i].ret_code; break; } } else { ret = items[i].ret_code; break; } } i++; } last_i = i; last_button = button; last_button_list = items; return ret; } /* this is the plugin entry point */ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) { static struct ButtonItem buttons[5] = {{ BUTTON_SELECT, -1, 0 }, // _pre { BUTTON_SELECT|BUTTON_REL, 1, 1 }, // short press { BUTTON_SELECT|BUTTON_REPEAT, 2, 2 }, // long press { BUTTON_SELECT|BUTTON_LEFT, 3, 0 }, // combo short press { BUTTON_SELECT|BUTTON_LEFT|BUTTON_REPEAT, 4, 1 }, // combo long press }; rb = api; while (1) { switch (read_button(buttons,5,0)) { case 1: DEBUGF("SHORT PRESS\n"); break; case 2: DEBUGF("LONG PRESS\n"); break; case 3: DEBUGF("COMBO SHORT PRESS\n"); break; case 4: DEBUGF("COMBO LONG PRESS\n"); break; default: break; } } return PLUGIN_OK; }