|
Rockbox mail archiveSubject: Re: unique function for each buttonRe: unique function for each button
From: <tp_at_diffenbach.org>
Date: Fri, 31 Jan 2003 10:21:08 -0800 (PST) Er. Slimmer. But not much slower. typedef int ( *rockbox_function )( int, void* ) ; #define BUTTON_COUNT 10 ; #define STATE_COUNT 10 ; static rockbox_function known_rockbox_function[] = { &f_1, &f_2, ... } ; // 4 bytes per func. static unsigned char extra_level_of_indirection[ STATE_COUNT ][ BUTTON_COUNT ] = { 1, 1, 2, 0, ...} ; // 100 bytes total // at global scope rockbox_function current_state_buttons[ BUTTON_COUNT ] ; void enter_state( int state ) { for( int i = 0 ; i < BUTTON_COUNT ; ++i ) { current_state_buttons[ i ] = known_rockbox_function[ extra_level_of_indirection[ state ][ i ] ] ; } } ... //button code int pressed( int button ) { int extra_data_int = get_extra_data_int() ; // whatever void* extra_data_ptr = get_extra_data_ptr() ; return ( *( current_state_buttons[ button ] )( extra_data_int, extra_data_ptr ) ; } Quoting tp_at_diffenbach.org: > > Of course the Rockbox can be in different states, so you'd need to set > the mapping per state. The recorder has 10 buttons so, > > typedef int ( *rockbox_function )( int, void* ) ; > > #define BUTTON_COUNT 10 ; > #define STATE_COUNT 10 ; > > static rockbox_function[ STATE_COUNT ][ BUTTON_COUNT ] = { > { &default_button_1, def_button_2, ... } } ; > > > Now this is sizeof( func_ptr ) * STATE_COUNT * BUTTON_COUNT = 400 bytes, > so we might want to investigate ways to slim it down. > > Of course, it also requites writing wrappers for all major functions to > conform to the rockbox_function signature, or nasty casting. > > > Quoting Gary Richardi <gary_pr_at_yahoo.com>: > > > Making all button functions configurable by the user is a GREAT > idea! > > > > --- tp_at_diffenbach.org wrote: > > > > > > My two cents: what this (any?) button does should be customizable > by > > > the user. > > > > > > > > > ===== > > --- Gary --- > > 4 Way Street (West) - CSN&Y Tribute band ---> http://4waystreet.net > > My original music ---> http://www.mp3.com/gpr > > > > __________________________________________________ > > Do you Yahoo!? > > Yahoo! Mail Plus - Powerful. Affordable. Sign up now. > > http://mailplus.yahoo.com > > > > Received on 2003-01-31 Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy |