summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rwxr-xr-xfirmware/drivers/touchscreen.c33
1 files 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);