From 2f3e0fbcd05c13cf9faffa92773e7e4390ba0ab7 Mon Sep 17 00:00:00 2001 From: Rob Purchase Date: Sat, 26 Sep 2009 17:33:36 +0000 Subject: Add a few pixels "dead zone" between the touchscreen grid "buttons", to avoid jitter. Flyspray: FS#10615 Author: Carsten Schreiter git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22843 a1c6a512-1295-4272-9138-f99709370657 --- firmware/drivers/touchscreen.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c index 002acf1236..bf63e488ec 100755 --- a/firmware/drivers/touchscreen.c +++ b/firmware/drivers/touchscreen.c @@ -26,6 +26,10 @@ #include "string.h" #include "logf.h" +/* Size of the 'dead zone' around each 3x3 button */ +#define BUTTON_MARGIN_X LCD_WIDTH * 0.03 +#define BUTTON_MARGIN_Y LCD_HEIGHT * 0.03 + static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT; static const int touchscreen_buttons[3][3] = { @@ -121,9 +125,32 @@ int touchscreen_to_pixels(int x, int y, int *data) map_pixels(&x, &y); - if(current_mode == TOUCHSCREEN_BUTTON) - return touchscreen_buttons[y / (LCD_HEIGHT/3)] - [x / (LCD_WIDTH/3) ]; + if (current_mode == TOUCHSCREEN_BUTTON) + { + int column = 0, row = 0; + + if (x < LCD_WIDTH/3 - BUTTON_MARGIN_X) + column = 0; + else if (x > LCD_WIDTH/3 + BUTTON_MARGIN_X && + x < 2*LCD_WIDTH/3 - BUTTON_MARGIN_X) + column = 1; + else if (x > 2*LCD_WIDTH/3 + BUTTON_MARGIN_X) + column = 2; + else + return BUTTON_NONE; + + if (y < LCD_HEIGHT/3 - BUTTON_MARGIN_Y) + row = 0; + else if (y > LCD_HEIGHT/3 + BUTTON_MARGIN_Y && + y < 2*LCD_HEIGHT/3 - BUTTON_MARGIN_Y) + row = 1; + else if (y > 2*LCD_HEIGHT/3 + BUTTON_MARGIN_Y) + row = 2; + else + return BUTTON_NONE; + + return touchscreen_buttons[row][column]; + } else { *data = (x << 16 | y); -- cgit v1.2.3