summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@bitmath.org>2010-08-30 02:57:38 +0200
committerHenrik Rydberg <rydberg@bitmath.org>2010-08-30 02:57:38 +0200
commit84366d8e709861e497179ac8ae2126b25d37d5a4 (patch)
tree2ed9c0d54fa6d2a78ee434806914d178e0ac6f72 /src
parentf38cecf915dc5001f7f8a1bd6a3ae6914b973f94 (diff)
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 <rydberg@bitmath.org>
Diffstat (limited to 'src')
-rw-r--r--src/touch-caps.c9
1 files 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)
49 caps->min_y = 0; 49 caps->min_y = 0;
50 caps->max_y = 768; 50 caps->max_y = 768;
51 } 51 }
52 if (caps->min_orient == caps->max_orient) { 52 if (caps->min_orient == caps->max_orient)
53 caps->min_orient = 0;
54 caps->max_orient = 1; 53 caps->max_orient = 1;
55 } 54 if (caps->min_orient + caps->max_orient != 0)
55 caps->min_orient = -caps->max_orient;
56 if (caps->min_press == caps->max_press) { 56 if (caps->min_press == caps->max_press) {
57 caps->min_press = 0; 57 caps->min_press = 0;
58 caps->max_press = 256; 58 caps->max_press = 256;
@@ -62,8 +62,7 @@ void touch_caps_init(struct touch_dev *dev)
62float touch_angle(const struct touch_dev *dev, int orient) 62float touch_angle(const struct touch_dev *dev, int orient)
63{ 63{
64 const struct touch_caps *caps = &dev->caps; 64 const struct touch_caps *caps = &dev->caps;
65 double div = caps->max_orient - caps->min_orient; 65 return orient / caps->max_orient * M_PI_2;
66 return ((orient - caps->min_orient) / div - 0.5) * M_PI;
67} 66}
68 67
69float touch_pressure(const struct touch_dev *dev, int press) 68float touch_pressure(const struct touch_dev *dev, int press)