evdev: fix device_transform_ functions
authorBenjamin Tissoires <benjamin.tissoires@gmail.com>
Mon, 17 Feb 2014 18:42:52 +0000 (13:42 -0500)
committerPeter Hutterer <peter.hutterer@who-t.net>
Thu, 20 Feb 2014 01:30:08 +0000 (11:30 +1000)
X and Y are li_fixed_t, which is 24.8 fixed point real number.
li_fixed_t max is thus ~8388607.

On a touchscreen with a range of 32767 values (like a 3M sensor), and
mapped on monitor with a resolution of 1920x1080, we currently have:
(x - li_fixed_from_int(device->abs.min_x)) * width == 62912640

which is 7 times bigger than li_fixed_t max.

Force a cast to uint64_t to keep the precision of the sensor.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
src/evdev.c

index 3fe28e4..beec75e 100644 (file)
@@ -91,7 +91,7 @@ evdev_device_transform_x(struct evdev_device *device,
                         li_fixed_t x,
                         uint32_t width)
 {
-       return (x - li_fixed_from_int(device->abs.min_x)) * width /
+       return ((uint64_t)x - li_fixed_from_int(device->abs.min_x)) * width /
                (device->abs.max_x - device->abs.min_x + 1);
 }
 
@@ -100,7 +100,7 @@ evdev_device_transform_y(struct evdev_device *device,
                         li_fixed_t y,
                         uint32_t height)
 {
-       return (y - li_fixed_from_int(device->abs.min_y)) * height /
+       return ((uint64_t)y - li_fixed_from_int(device->abs.min_y)) * height /
                (device->abs.max_y - device->abs.min_y + 1);
 }