diff options
| author | Björn Stenberg <bjorn@haxx.se> | 2002-05-23 11:59:30 +0000 |
|---|---|---|
| committer | Björn Stenberg <bjorn@haxx.se> | 2002-05-23 11:59:30 +0000 |
| commit | 7a112a720407fcfe60db2c6116c8fbc16c4da121 (patch) | |
| tree | 0aa8c83dfbbf6a7d7d1c2a01e495d6c1fcc6390b /firmware | |
| parent | 4118d8c0318e69b366d424545cbad6529bfc5e53 (diff) | |
| download | rockbox-7a112a720407fcfe60db2c6116c8fbc16c4da121.zip rockbox-7a112a720407fcfe60db2c6116c8fbc16c4da121.tar.gz rockbox-7a112a720407fcfe60db2c6116c8fbc16c4da121.tar.bz2 rockbox-7a112a720407fcfe60db2c6116c8fbc16c4da121.tar.xz | |
Added repeat handling. Removed CRLF newlines.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@664 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
| -rw-r--r-- | firmware/drivers/button.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 5532ad4..ffbb67c 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -28,19 +28,51 @@ static struct event_queue button_queue; -#define POLL_FREQUENCY HZ/10 +#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(); - queue_post(&button_queue, btn, NULL); - counter=0; + + 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); + } + 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 ev.id; + } + return BUTTON_NONE; } #ifdef HAVE_RECORDER_KEYPAD |