diff options
author | Jens Arnold <amiconn@rockbox.org> | 2006-04-16 22:28:24 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2006-04-16 22:28:24 +0000 |
commit | 5380376dbc50d9a660d1a4be6d8f813f7f1b2d58 (patch) | |
tree | 57f86dfe460f6b238729d5614abcc281d23ee1ba /firmware | |
parent | f7872ac61b60468510bf2cbd63f82c1a4ad14a94 (diff) | |
download | rockbox-5380376dbc50d9a660d1a4be6d8f813f7f1b2d58.tar.gz rockbox-5380376dbc50d9a660d1a4be6d8f813f7f1b2d58.zip |
H300 (and H1x0): Improved button debouncing. Solves the possible 'fake doubleclick' effect by not pretending no button is pressed if the reading is unstable. Now it uses the latest stable reading instead.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9691 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/button.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index e3998ae8a5..0c2e1e51f5 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -824,7 +824,8 @@ static int button_read(void) #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) static bool hold_button = false; static bool remote_hold_button = false; - static int last_button_val= 0xff; + static int prev_data = 0xff; + static int last_valid = 0xff; /* light handling */ if (hold_button && !button_hold()) @@ -843,8 +844,16 @@ static int button_read(void) if (!hold_button) { data = adc_scan(ADC_BUTTONS); + + /* ADC debouncing: Only accept new reading if it's + * stable (+/-1). Use latest stable value otherwise. */ + if ((unsigned)(data - prev_data + 1) <= 2) + last_valid = data; + prev_data = data; + data = last_valid; + #if CONFIG_KEYPAD == IRIVER_H100_PAD - if ((data < 0xf0) && ((unsigned)(data - last_button_val + 1) <= 2)) + if (data < 0xf0) { if (data < 0x80) if (data < 0x30) @@ -870,7 +879,7 @@ static int button_read(void) btn = BUTTON_REC; } #else /* H300 */ - if ((data < 0xba) && ((unsigned)(data - last_button_val + 1) <= 2)) + if (data < 0xba) { if (data < 0x54) if (data < 0x30) @@ -890,7 +899,6 @@ static int button_read(void) btn = BUTTON_OFF; } #endif - last_button_val = data; } /* remote buttons */ |