diff options
Diffstat (limited to 'firmware/drivers/touchscreen.c')
-rwxr-xr-x | firmware/drivers/touchscreen.c | 33 |
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 @@ | |||
26 | #include "string.h" | 26 | #include "string.h" |
27 | #include "logf.h" | 27 | #include "logf.h" |
28 | 28 | ||
29 | /* Size of the 'dead zone' around each 3x3 button */ | ||
30 | #define BUTTON_MARGIN_X LCD_WIDTH * 0.03 | ||
31 | #define BUTTON_MARGIN_Y LCD_HEIGHT * 0.03 | ||
32 | |||
29 | static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT; | 33 | static enum touchscreen_mode current_mode = TOUCHSCREEN_POINT; |
30 | static const int touchscreen_buttons[3][3] = | 34 | static const int touchscreen_buttons[3][3] = |
31 | { | 35 | { |
@@ -121,9 +125,32 @@ int touchscreen_to_pixels(int x, int y, int *data) | |||
121 | 125 | ||
122 | map_pixels(&x, &y); | 126 | map_pixels(&x, &y); |
123 | 127 | ||
124 | if(current_mode == TOUCHSCREEN_BUTTON) | 128 | if (current_mode == TOUCHSCREEN_BUTTON) |
125 | return touchscreen_buttons[y / (LCD_HEIGHT/3)] | 129 | { |
126 | [x / (LCD_WIDTH/3) ]; | 130 | int column = 0, row = 0; |
131 | |||
132 | if (x < LCD_WIDTH/3 - BUTTON_MARGIN_X) | ||
133 | column = 0; | ||
134 | else if (x > LCD_WIDTH/3 + BUTTON_MARGIN_X && | ||
135 | x < 2*LCD_WIDTH/3 - BUTTON_MARGIN_X) | ||
136 | column = 1; | ||
137 | else if (x > 2*LCD_WIDTH/3 + BUTTON_MARGIN_X) | ||
138 | column = 2; | ||
139 | else | ||
140 | return BUTTON_NONE; | ||
141 | |||
142 | if (y < LCD_HEIGHT/3 - BUTTON_MARGIN_Y) | ||
143 | row = 0; | ||
144 | else if (y > LCD_HEIGHT/3 + BUTTON_MARGIN_Y && | ||
145 | y < 2*LCD_HEIGHT/3 - BUTTON_MARGIN_Y) | ||
146 | row = 1; | ||
147 | else if (y > 2*LCD_HEIGHT/3 + BUTTON_MARGIN_Y) | ||
148 | row = 2; | ||
149 | else | ||
150 | return BUTTON_NONE; | ||
151 | |||
152 | return touchscreen_buttons[row][column]; | ||
153 | } | ||
127 | else | 154 | else |
128 | { | 155 | { |
129 | *data = (x << 16 | y); | 156 | *data = (x << 16 | y); |