forked from len0rd/rockbox
Added repeat handling. Removed CRLF newlines.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@664 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4118d8c031
commit
7a112a7204
1 changed files with 41 additions and 7 deletions
|
|
@ -29,18 +29,50 @@
|
|||
static struct event_queue button_queue;
|
||||
|
||||
#define POLL_FREQUENCY HZ/10
|
||||
#define REPEAT_START 3
|
||||
#define REPEAT_INTERVAL 3
|
||||
|
||||
static int button_read(void);
|
||||
|
||||
static void button_tick(void)
|
||||
{
|
||||
static int counter=0;
|
||||
static int tick=0;
|
||||
static int count=0;
|
||||
static int lastbtn=0;
|
||||
static bool repeat=false;
|
||||
|
||||
/* only poll every X ticks */
|
||||
if ( counter++ > POLL_FREQUENCY ) {
|
||||
if ( tick++ > POLL_FREQUENCY ) {
|
||||
bool post = false;
|
||||
int btn = button_read();
|
||||
|
||||
if ( btn ) {
|
||||
/* normal keypress */
|
||||
if ( btn != lastbtn ) {
|
||||
post = true;
|
||||
}
|
||||
/* repeat? */
|
||||
else {
|
||||
if ( repeat ) {
|
||||
if ( ! --count ) {
|
||||
post = true;
|
||||
count = REPEAT_INTERVAL;
|
||||
}
|
||||
}
|
||||
else if (count++ > REPEAT_START) {
|
||||
post = true;
|
||||
repeat = true;
|
||||
count = REPEAT_INTERVAL;
|
||||
}
|
||||
}
|
||||
if ( post )
|
||||
queue_post(&button_queue, btn, NULL);
|
||||
counter=0;
|
||||
}
|
||||
else
|
||||
repeat = false;
|
||||
|
||||
lastbtn = btn;
|
||||
tick = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -48,9 +80,11 @@ int button_get(void)
|
|||
{
|
||||
struct event ev;
|
||||
|
||||
if ( !queue_empty(&button_queue) )
|
||||
if ( !queue_empty(&button_queue) ) {
|
||||
queue_wait(&button_queue, &ev);
|
||||
return ev.id;
|
||||
}
|
||||
return BUTTON_NONE;
|
||||
}
|
||||
|
||||
#ifdef HAVE_RECORDER_KEYPAD
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue