From 5f8ffa02a6941fb2f866fb54ba59b317871f1631 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 23 Sep 2004 12:08:48 +0000 Subject: [PATCH] An attempt to filter the button reading git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5109 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/button.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 1fb1905862..c0f5edb8c6 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -35,25 +35,26 @@ struct event_queue button_queue; -static int lastbtn; +static int lastbtn; /* Last valid button status */ +static int last_read; /* Last button status, for debouncing/filtering */ #if defined(HAVE_RECORDER_KEYPAD) || defined(HAVE_ONDIO_KEYPAD) static bool flipped; /* bottons can be flipped to match the LCD flip */ #endif /* how often we check to see if a button is pressed */ -#define POLL_FREQUENCY HZ/20 +#define POLL_FREQUENCY HZ/100 /* how long until repeat kicks in */ -#define REPEAT_START 6 +#define REPEAT_START 30 /* the speed repeat starts at */ -#define REPEAT_INTERVAL_START 4 +#define REPEAT_INTERVAL_START 16 /* speed repeat finishes at */ -#define REPEAT_INTERVAL_FINISH 2 +#define REPEAT_INTERVAL_FINISH 5 /* Number of repeated keys before shutting off */ -#define POWEROFF_COUNT 8 +#define POWEROFF_COUNT 40 static int button_read(void); @@ -275,6 +276,7 @@ void button_set_flip(bool flip) static int button_read(void) { int btn = BUTTON_NONE; + int retval; /* Check port B pins for ON and OFF */ int data; @@ -333,9 +335,17 @@ static int button_read(void) } if (btn && flipped) - return button_flip(btn); /* swap upside down */ - - return btn; + btn = button_flip(btn); /* swap upside down */ + + /* Filter the button status. It is only accepted if we get the same + status twice in a row. */ + if(btn != last_read) + retval = lastbtn; + else + retval = btn; + last_read = btn; + + return retval; } #elif defined(HAVE_PLAYER_KEYPAD)