summaryrefslogtreecommitdiffstats
path: root/firmware/drivers/touchscreen.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-11-10 15:25:15 +0000
committerThomas Martitz <kugel@rockbox.org>2010-11-10 15:25:15 +0000
commit33af0dec28cf31be0ce7195b90546861efcce76f (patch)
treef106c9118c9191bff00e1468c98540787081c0e8 /firmware/drivers/touchscreen.c
parente134021e1b05f797cffd28c6b4ee72a963ff3812 (diff)
downloadrockbox-33af0dec28cf31be0ce7195b90546861efcce76f.tar.gz
rockbox-33af0dec28cf31be0ce7195b90546861efcce76f.tar.bz2
rockbox-33af0dec28cf31be0ce7195b90546861efcce76f.zip
Touchscreen: Improved scroll threshold
Remove the hardcoded (and way too small) scroll threshold (the distance moved in pixels before we think the users wants to scroll) and replace it with something based on the actual DPI of the screen. On Android we call the API for that, on other touchscreens we reimplemented Android's formula (as of 2.2) and calculate it. Flyspray: 11727 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28548 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/touchscreen.c')
-rw-r--r--firmware/drivers/touchscreen.c31
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 @@
#include "touchscreen.h"
#include "string.h"
#include "logf.h"
+#include "lcd.h"
/* Size of the 'dead zone' around each 3x3 button */
#define BUTTON_MARGIN_X (int)(LCD_WIDTH * 0.03)
@@ -167,3 +168,33 @@ enum touchscreen_mode touchscreen_get_mode(void)
{
return current_mode;
}
+
+
+#if ((CONFIG_PLATFORM & PLATFORM_ANDROID) == 0)
+/* android has an API for this */
+
+#define TOUCH_SLOP 16u
+#define REFERENCE_DPI 160
+
+int touchscreen_get_scroll_threshold(void)
+{
+#ifdef LCD_DPI
+ const int dpi = LCD_DPI;
+#else
+ const int dpi = lcd_get_dpi();
+#endif
+
+ /* Inspired by Android calculation
+ *
+ * float density = real dpi / reference dpi (=160)
+ * int threshold = (int) (density * TOUCH_SLOP + 0.5f);(original calculation)
+ *
+ * + 0.5f is for rounding, we use fixed point math to achieve that
+ */
+
+ int result = dpi * (TOUCH_SLOP<<1) / REFERENCE_DPI;
+ result += result & 1; /* round up if needed */
+ return result>>1;
+}
+
+#endif