diff options
Diffstat (limited to 'firmware/drivers')
-rw-r--r-- | firmware/drivers/touchscreen.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/firmware/drivers/touchscreen.c b/firmware/drivers/touchscreen.c index 9660e0cb9d..823c2e7a92 100644 --- a/firmware/drivers/touchscreen.c +++ b/firmware/drivers/touchscreen.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "touchscreen.h" | 25 | #include "touchscreen.h" |
26 | #include "string.h" | 26 | #include "string.h" |
27 | #include "logf.h" | 27 | #include "logf.h" |
28 | #include "lcd.h" | ||
28 | 29 | ||
29 | /* Size of the 'dead zone' around each 3x3 button */ | 30 | /* Size of the 'dead zone' around each 3x3 button */ |
30 | #define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03) | 31 | #define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03) |
@@ -167,3 +168,33 @@ enum touchscreen_mode touchscreen_get_mode(void) | |||
167 | { | 168 | { |
168 | return current_mode; | 169 | return current_mode; |
169 | } | 170 | } |
171 | |||
172 | |||
173 | #if ((CONFIG_PLATFORM & PLATFORM_ANDROID) == 0) | ||
174 | /* android has an API for this */ | ||
175 | |||
176 | #define TOUCH_SLOP 16u | ||
177 | #define REFERENCE_DPI 160 | ||
178 | |||
179 | int touchscreen_get_scroll_threshold(void) | ||
180 | { | ||
181 | #ifdef LCD_DPI | ||
182 | const int dpi = LCD_DPI; | ||
183 | #else | ||
184 | const int dpi = lcd_get_dpi(); | ||
185 | #endif | ||
186 | |||
187 | /* Inspired by Android calculation | ||
188 | * | ||
189 | * float density = real dpi / reference dpi (=160) | ||
190 | * int threshold = (int) (density * TOUCH_SLOP + 0.5f);(original calculation) | ||
191 | * | ||
192 | * + 0.5f is for rounding, we use fixed point math to achieve that | ||
193 | */ | ||
194 | |||
195 | int result = dpi * (TOUCH_SLOP<<1) / REFERENCE_DPI; | ||
196 | result += result & 1; /* round up if needed */ | ||
197 | return result>>1; | ||
198 | } | ||
199 | |||
200 | #endif | ||