From a704984e03d28b4be40e12c43be1b163bc9e09e2 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Thu, 19 Aug 2010 20:03:15 +0200 Subject: Simplify touch machinery To be able to model touch information uniformly across all supported devices, the semantics of the touch attributes has to be treated explicitly. Drop the generic touch property array and replace it by an actual structure. In addition, the touch-engine abstraction turned out to not be needed, so drop it as well. Signed-off-by: Henrik Rydberg --- src/touch-caps.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/touch-caps.c (limited to 'src/touch-caps.c') diff --git a/src/touch-caps.c b/src/touch-caps.c new file mode 100644 index 0000000..50306e0 --- /dev/null +++ b/src/touch-caps.c @@ -0,0 +1,73 @@ +/***************************************************************************** + * + * grail - Gesture Recognition And Instantiation Library + * + * Copyright (C) 2010 Canonical Ltd. + * Copyright (C) 2010 Henrik Rydberg + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + * + ****************************************************************************/ + +#include +#include + +/* see mtdev-mapping.h */ +#define MTDEV_POSITION_X 5 +#define MTDEV_POSITION_Y 6 +#define MTDEV_ORIENTATION 4 +#define MTDEV_PRESSURE 10 + +void touch_caps_init(struct touch_dev *dev) +{ + const struct mtdev_caps *mt = &dev->mtdev.caps; + struct touch_caps *caps = &dev->caps; + caps->min_x = mt->abs[MTDEV_POSITION_X].minimum; + caps->max_x = mt->abs[MTDEV_POSITION_X].maximum; + caps->min_y = mt->abs[MTDEV_POSITION_Y].minimum; + caps->max_y = mt->abs[MTDEV_POSITION_Y].maximum; + caps->min_orient = mt->abs[MTDEV_ORIENTATION].minimum; + caps->max_orient = mt->abs[MTDEV_ORIENTATION].maximum; + caps->min_press = mt->abs[MTDEV_PRESSURE].minimum; + caps->max_press = mt->abs[MTDEV_PRESSURE].maximum; + if (caps->min_x == caps->max_x) { + caps->min_x = 0; + caps->max_x = 1024; + } + if (caps->min_y == caps->max_y) { + caps->min_y = 0; + caps->max_y = 768; + } + if (caps->min_orient == caps->max_orient) { + caps->min_orient = 0; + caps->max_orient = 1; + } + if (caps->min_press == caps->max_press) { + caps->min_press = 0; + caps->max_press = 256; + } +} + +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; +} + +float touch_pressure(const struct touch_dev *dev, int press) +{ + const struct touch_caps *caps = &dev->caps; + return (press - caps->min_press) / (caps->max_press - caps->min_press); +} -- cgit v1.2.3