Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scale input received from evdev, if touchscreen resolution does not match display resolution #35

Closed
mheranco opened this issue Nov 8, 2018 · 1 comment

Comments

@mheranco
Copy link
Contributor

mheranco commented Nov 8, 2018

Hi,

the resolution of my touch input reveived from evdev does not match the resolution of my display.
With the following patch it would be possible to define a custom input resolution. Every position read from evdev would be scaled to the display resolution.

index 94027d8..e7346f7 100644
--- a/b/indev/evdev.c
+++ b/a/indev/evdev.c
@@ -90,21 +90,25 @@ bool evdev_read(lv_indev_data_t * data)
         }
     }

-
-    if(evdev_root_x < 0)
-        evdev_root_x = 0;
-    if(evdev_root_y < 0)
-        evdev_root_y = 0;
-    if(evdev_root_x >= LV_HOR_RES)
-        evdev_root_x = LV_HOR_RES - 1;
-    if(evdev_root_y >= LV_VER_RES)
-        evdev_root_y = LV_VER_RES - 1;
-
     /*Store the collected data*/
+#if SCALE_EVDEV
+    data->point.x = (evdev_root_x * LV_HOR_RES) / SCALE_EVDEV_HOR_RES;
+    data->point.y = (evdev_root_y * LV_VER_RES) / SCALE_EVDEV_VER_RES;
+#else
     data->point.x = evdev_root_x;
     data->point.y = evdev_root_y;
+#endif
     data->state = evdev_button;

+    if(data->point.x < 0)
+      data->point.x = 0;
+    if(data->point.y < 0)
+      data->point.y = 0;
+    if(data->point.x >= LV_HOR_RES)
+      data->point.x = LV_HOR_RES - 1;
+    if(data->point.y >= LV_VER_RES)
+      data->point.y = LV_VER_RES - 1;
+
     return false;
 }
index 449796c..2090830 100644
--- a/b/lv_drv_conf_templ.h
+++ b/a/lv_drv_conf_templ.h
@@ -207,6 +207,11 @@
 #define USE_EVDEV    0
 #if USE_EVDEV
 #define EVDEV_NAME   "/dev/input/event0"        /*You can use the "evtest" Linux tool to get the list of devices and test them*/
+#define SCALE_EVDEV  0                          /* Scale input, e.g. if touchscreen resolution does not match display resolution */
+#if SCALE_EVDEV
+#define SCALE_EVDEV_HOR_RES     (4096)          /* Horizontal resolution of touchscreen */
+#define SCALE_EVDEV_VER_RES     (4096)          /* Vertical resolution of touchscreen */
+#endif
 #endif
@kisvegabor
Copy link
Member

I've just merged your PR.
Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants