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.tar.gz rockbox-7a112a720407fcfe60db2c6116c8fbc16c4da121.zip |
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 5532ad4432..ffbb67c463 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -28,19 +28,51 @@ | |||
28 | 28 | ||
29 | static struct event_queue button_queue; | 29 | static struct event_queue button_queue; |
30 | 30 | ||
31 | #define POLL_FREQUENCY HZ/10 | 31 | #define POLL_FREQUENCY HZ/10 |
32 | #define REPEAT_START 3 | ||
33 | #define REPEAT_INTERVAL 3 | ||
32 | 34 | ||
33 | static int button_read(void); | 35 | static int button_read(void); |
34 | 36 | ||
35 | static void button_tick(void) | 37 | static void button_tick(void) |
36 | { | 38 | { |
37 | static int counter=0; | 39 | static int tick=0; |
40 | static int count=0; | ||
41 | static int lastbtn=0; | ||
42 | static bool repeat=false; | ||
38 | 43 | ||
39 | /* only poll every X ticks */ | 44 | /* only poll every X ticks */ |
40 | if ( counter++ > POLL_FREQUENCY ) { | 45 | if ( tick++ > POLL_FREQUENCY ) { |
46 | bool post = false; | ||
41 | int btn = button_read(); | 47 | int btn = button_read(); |
42 | queue_post(&button_queue, btn, NULL); | 48 | |
43 | counter=0; | 49 | if ( btn ) { |
50 | /* normal keypress */ | ||
51 | if ( btn != lastbtn ) { | ||
52 | post = true; | ||
53 | } | ||
54 | /* repeat? */ | ||
55 | else { | ||
56 | if ( repeat ) { | ||
57 | if ( ! --count ) { | ||
58 | post = true; | ||
59 | count = REPEAT_INTERVAL; | ||
60 | } | ||
61 | } | ||
62 | else if (count++ > REPEAT_START) { | ||
63 | post = true; | ||
64 | repeat = true; | ||
65 | count = REPEAT_INTERVAL; | ||
66 | } | ||
67 | } | ||
68 | if ( post ) | ||
69 | queue_post(&button_queue, btn, NULL); | ||
70 | } | ||
71 | else | ||
72 | repeat = false; | ||
73 | |||
74 | lastbtn = btn; | ||
75 | tick = 0; | ||
44 | } | 76 | } |
45 | } | 77 | } |
46 | 78 | ||
@@ -48,9 +80,11 @@ int button_get(void) | |||
48 | { | 80 | { |
49 | struct event ev; | 81 | struct event ev; |
50 | 82 | ||
51 | if ( !queue_empty(&button_queue) ) | 83 | if ( !queue_empty(&button_queue) ) { |
52 | queue_wait(&button_queue, &ev); | 84 | queue_wait(&button_queue, &ev); |
53 | return ev.id; | 85 | return ev.id; |
86 | } | ||
87 | return BUTTON_NONE; | ||
54 | } | 88 | } |
55 | 89 | ||
56 | #ifdef HAVE_RECORDER_KEYPAD | 90 | #ifdef HAVE_RECORDER_KEYPAD |