diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-08-19 20:03:15 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-08-19 20:03:15 +0200 |
| commit | a704984e03d28b4be40e12c43be1b163bc9e09e2 (patch) | |
| tree | c4720a59aa77918ffef742d7ec7ef2a7e2eda16e /src/touch-caps.c | |
| parent | cb2cad3b8c506a08a6bdad548a10ff47f85ef38b (diff) | |
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 <rydberg@euromail.se>
Diffstat (limited to 'src/touch-caps.c')
| -rw-r--r-- | src/touch-caps.c | 73 |
1 files changed, 73 insertions, 0 deletions
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 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * grail - Gesture Recognition And Instantiation Library | ||
| 4 | * | ||
| 5 | * Copyright (C) 2010 Canonical Ltd. | ||
| 6 | * Copyright (C) 2010 Henrik Rydberg <rydberg@bitmath.org> | ||
| 7 | * | ||
| 8 | * This program is free software: you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License as published by the | ||
| 10 | * Free Software Foundation, either version 3 of the License, or (at your | ||
| 11 | * option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, but | ||
| 14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License along | ||
| 19 | * with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 20 | * | ||
| 21 | ****************************************************************************/ | ||
| 22 | |||
| 23 | #include <grail-touch.h> | ||
| 24 | #include <math.h> | ||
| 25 | |||
| 26 | /* see mtdev-mapping.h */ | ||
| 27 | #define MTDEV_POSITION_X 5 | ||
| 28 | #define MTDEV_POSITION_Y 6 | ||
| 29 | #define MTDEV_ORIENTATION 4 | ||
| 30 | #define MTDEV_PRESSURE 10 | ||
| 31 | |||
| 32 | void touch_caps_init(struct touch_dev *dev) | ||
| 33 | { | ||
| 34 | const struct mtdev_caps *mt = &dev->mtdev.caps; | ||
| 35 | struct touch_caps *caps = &dev->caps; | ||
| 36 | caps->min_x = mt->abs[MTDEV_POSITION_X].minimum; | ||
| 37 | caps->max_x = mt->abs[MTDEV_POSITION_X].maximum; | ||
| 38 | caps->min_y = mt->abs[MTDEV_POSITION_Y].minimum; | ||
| 39 | caps->max_y = mt->abs[MTDEV_POSITION_Y].maximum; | ||
| 40 | caps->min_orient = mt->abs[MTDEV_ORIENTATION].minimum; | ||
| 41 | caps->max_orient = mt->abs[MTDEV_ORIENTATION].maximum; | ||
| 42 | caps->min_press = mt->abs[MTDEV_PRESSURE].minimum; | ||
| 43 | caps->max_press = mt->abs[MTDEV_PRESSURE].maximum; | ||
| 44 | if (caps->min_x == caps->max_x) { | ||
| 45 | caps->min_x = 0; | ||
| 46 | caps->max_x = 1024; | ||
| 47 | } | ||
| 48 | if (caps->min_y == caps->max_y) { | ||
| 49 | caps->min_y = 0; | ||
| 50 | caps->max_y = 768; | ||
| 51 | } | ||
| 52 | if (caps->min_orient == caps->max_orient) { | ||
| 53 | caps->min_orient = 0; | ||
| 54 | caps->max_orient = 1; | ||
| 55 | } | ||
| 56 | if (caps->min_press == caps->max_press) { | ||
| 57 | caps->min_press = 0; | ||
| 58 | caps->max_press = 256; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | float touch_angle(const struct touch_dev *dev, int orient) | ||
| 63 | { | ||
| 64 | const struct touch_caps *caps = &dev->caps; | ||
| 65 | double div = caps->max_orient - caps->min_orient; | ||
| 66 | return ((orient - caps->min_orient) / div - 0.5) * M_PI; | ||
| 67 | } | ||
| 68 | |||
| 69 | float touch_pressure(const struct touch_dev *dev, int press) | ||
| 70 | { | ||
| 71 | const struct touch_caps *caps = &dev->caps; | ||
| 72 | return (press - caps->min_press) / (caps->max_press - caps->min_press); | ||
| 73 | } | ||
