From 70240b430266b4ae2e99bf25f0ff5e7df039e623 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 10 Dec 2011 23:35:16 +0000 Subject: [PATCH] input: evdev: do centering adjustment git-svn-id: file:///home/notaz/opt/svn/PicoDrive@940 be3aeb3a-fb24-0410-a615-afba39da0efa --- platform/linux/in_evdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/platform/linux/in_evdev.c b/platform/linux/in_evdev.c index 7dd631e4..23d2e2a3 100644 --- a/platform/linux/in_evdev.c +++ b/platform/linux/in_evdev.c @@ -37,8 +37,8 @@ typedef struct { int kc_first; int kc_last; unsigned int abs_count; - /* 16.16 multiplier to IN_ABS_RANGE */ - unsigned int abs_mult[MAX_ABS_DEVS]; + int abs_mult[MAX_ABS_DEVS]; /* 16.16 multiplier to IN_ABS_RANGE */ + int abs_adj[MAX_ABS_DEVS]; /* adjust for centering */ unsigned int abs_to_digital:1; } in_evdev_t; @@ -246,6 +246,7 @@ static void in_evdev_probe(void) dist = ainfo.maximum - ainfo.minimum; if (dist != 0) dev->abs_mult[u] = IN_ABS_RANGE * 2 * 65536 / dist; + dev->abs_adj[u] = -(ainfo.maximum + ainfo.minimum + 1) / 2; have_abs = 1; } dev->abs_count = u; @@ -371,7 +372,8 @@ static int in_evdev_update_analog(void *drv_data, int axis_id, int *result) if (ret != 0) return ret; - *result = (int)(ainfo.value * dev->abs_mult[axis_id]) >> 16; + *result = (ainfo.value + dev->abs_adj[axis_id]) * dev->abs_mult[axis_id]; + *result >>= 16; return 0; } -- 2.39.5