From 84366d8e709861e497179ac8ae2126b25d37d5a4 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 30 Aug 2010 02:57:38 +0200 Subject: Make orientation computation more robust The MT protocol defines the angle to be between -Pi/2 and Pi/2, and expects the defined range to be symmetric around zero. Make the angle computation more robust against varying definitions in the kernel drivers. Signed-off-by: Henrik Rydberg --- src/touch-caps.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/touch-caps.c b/src/touch-caps.c index 50306e0..7f243c5 100644 --- a/src/touch-caps.c +++ b/src/touch-caps.c @@ -49,10 +49,10 @@ void touch_caps_init(struct touch_dev *dev) caps->min_y = 0; caps->max_y = 768; } - if (caps->min_orient == caps->max_orient) { - caps->min_orient = 0; + if (caps->min_orient == caps->max_orient) caps->max_orient = 1; - } + if (caps->min_orient + caps->max_orient != 0) + caps->min_orient = -caps->max_orient; if (caps->min_press == caps->max_press) { caps->min_press = 0; caps->max_press = 256; @@ -62,8 +62,7 @@ void touch_caps_init(struct touch_dev *dev) float touch_angle(const struct touch_dev *dev, int orient) { const struct touch_caps *caps = &dev->caps; - double div = caps->max_orient - caps->min_orient; - return ((orient - caps->min_orient) / div - 0.5) * M_PI; + return orient / caps->max_orient * M_PI_2; } float touch_pressure(const struct touch_dev *dev, int press) -- cgit v1.2.3