1
0
Fork 0
forked from len0rd/rockbox

Reworked the button code

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1462 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-07-27 19:38:20 +00:00
parent 42df584960
commit e1a97288fc
2 changed files with 69 additions and 53 deletions

View file

@ -37,7 +37,6 @@ struct event_queue button_queue;
static int repeat_mask = DEFAULT_REPEAT_MASK; static int repeat_mask = DEFAULT_REPEAT_MASK;
static int release_mask = DEFAULT_RELEASE_MASK; static int release_mask = DEFAULT_RELEASE_MASK;
static int locked_mask = DEFAULT_LOCKED_MASK;
static int button_read(void); static int button_read(void);
@ -50,12 +49,11 @@ static void button_tick(void)
int diff; int diff;
/* only poll every X ticks */ /* only poll every X ticks */
if ( ++tick >= POLL_FREQUENCY ) { if ( ++tick >= POLL_FREQUENCY )
{
bool post = false; bool post = false;
int btn = button_read(); int btn = button_read();
if ( btn )
{
/* Find out if a key has been released */ /* Find out if a key has been released */
diff = btn ^ lastbtn; diff = btn ^ lastbtn;
if((btn & diff) == 0) if((btn & diff) == 0)
@ -64,19 +62,34 @@ static void button_tick(void)
queue_post(&button_queue, BUTTON_REL | diff, NULL); queue_post(&button_queue, BUTTON_REL | diff, NULL);
} }
if ( btn )
{
/* normal keypress */ /* normal keypress */
if ( btn != lastbtn ) { if ( btn != lastbtn )
{
post = true; post = true;
repeat = false;
} }
/* repeat? */ else /* repeat? */
else { {
if ( repeat ) { if ( repeat )
{
if ( ! --count ) { if ( ! --count ) {
post = true; post = true;
count = REPEAT_INTERVAL; count = REPEAT_INTERVAL;
} }
} }
else if (count++ > REPEAT_START) { else
{
if(btn & repeat_mask ||
#ifdef HAVE_RECORDER_KEYPAD
btn == BUTTON_OFF)
#else
btn == BUTTON_STOP)
#endif
{
if (count++ > REPEAT_START)
{
/* Only repeat if a repeatable key is pressed */ /* Only repeat if a repeatable key is pressed */
if(btn & repeat_mask) if(btn & repeat_mask)
{ {
@ -84,10 +97,11 @@ static void button_tick(void)
repeat = true; repeat = true;
count = REPEAT_INTERVAL; count = REPEAT_INTERVAL;
} }
/* If the OFF button is pressed long enough, and we are /* If the OFF button is pressed long enough,
still alive, then the unit must be connected to a and we are still alive, then the unit must be
charger. Therefore we will reboot and let the original connected to a charger. Therefore we will
firmware handle the charging. */ reboot and let the original firmware handle
the charging. */
#ifdef HAVE_RECORDER_KEYPAD #ifdef HAVE_RECORDER_KEYPAD
if(btn == BUTTON_OFF) if(btn == BUTTON_OFF)
#elif HAVE_PLAYER_KEYPAD #elif HAVE_PLAYER_KEYPAD
@ -96,24 +110,28 @@ static void button_tick(void)
system_reboot(); system_reboot();
} }
} }
else
{
count = 0;
}
}
}
if ( post ) if ( post )
{ {
if(repeat)
queue_post(&button_queue, BUTTON_REPEAT | btn, NULL);
else
queue_post(&button_queue, btn, NULL); queue_post(&button_queue, btn, NULL);
backlight_on(); backlight_on();
} }
} }
else { else
{
repeat = false; repeat = false;
count = 0; count = 0;
/* Report that the key has been released */
if(lastbtn != btn)
{
if(lastbtn & release_mask)
queue_post(&button_queue, BUTTON_REL | lastbtn, NULL);
}
} }
lastbtn = btn; lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT);
tick = 0; tick = 0;
} }
@ -145,13 +163,6 @@ int button_set_release(int newmask)
return oldmask; return oldmask;
} }
int button_set_locked(int newmask)
{
int oldmask = locked_mask;
locked_mask = newmask;
return oldmask;
}
#ifdef HAVE_RECORDER_KEYPAD #ifdef HAVE_RECORDER_KEYPAD
/* AJBR buttons are connected to the CPU as follows: /* AJBR buttons are connected to the CPU as follows:

View file

@ -28,7 +28,6 @@ void button_init (void);
int button_get (bool block); int button_get (bool block);
int button_set_repeat(int newmask); int button_set_repeat(int newmask);
int button_set_release(int newmask); int button_set_release(int newmask);
int button_set_locked(int newmask);
/* Shared button codes */ /* Shared button codes */
#define BUTTON_NONE 0x0000 #define BUTTON_NONE 0x0000
@ -39,7 +38,7 @@ int button_set_locked(int newmask);
#define BUTTON_RIGHT 0x0080 #define BUTTON_RIGHT 0x0080
/* Button modifiers */ /* Button modifiers */
#define BUTTON_HELD 0x4000 #define BUTTON_REPEAT 0x4000
#define BUTTON_REL 0x8000 #define BUTTON_REL 0x8000
/* Special message */ /* Special message */
@ -57,6 +56,10 @@ int button_set_locked(int newmask);
#define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT | \ #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT | \
BUTTON_UP | BUTTON_DOWN) BUTTON_UP | BUTTON_DOWN)
#define ALL_BUTTONS (BUTTON_ON | BUTTON_UP | BUTTON_DOWN | BUTTON_LEFT | \
BUTTON_RIGHT | BUTTON_OFF | BUTTON_PLAY | BUTTON_F1 | \
BUTTON_F2 | BUTTON_F3)
#elif HAVE_PLAYER_KEYPAD #elif HAVE_PLAYER_KEYPAD
/* Jukebox 6000 and Studio specific button codes */ /* Jukebox 6000 and Studio specific button codes */
@ -66,9 +69,11 @@ int button_set_locked(int newmask);
#define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT) #define DEFAULT_REPEAT_MASK (BUTTON_LEFT | BUTTON_RIGHT)
#define ALL_BUTTONS (BUTTON_ON | BUTTON_UP | BUTTON_DOWN | BUTTON_LEFT | \
BUTTON_RIGHT | BUTTON_OFF | BUTTON_MENU)
#endif /* HAVE_PLAYER_KEYPAD */ #endif /* HAVE_PLAYER_KEYPAD */
#define DEFAULT_RELEASE_MASK 0 #define DEFAULT_RELEASE_MASK 0
#define DEFAULT_LOCKED_MASK 0
#endif #endif