diff options
Diffstat (limited to 'src/touch-caps.c')
| -rw-r--r-- | src/touch-caps.c | 117 |
1 files changed, 0 insertions, 117 deletions
diff --git a/src/touch-caps.c b/src/touch-caps.c deleted file mode 100644 index f99b0d7..0000000 --- a/src/touch-caps.c +++ /dev/null | |||
| @@ -1,117 +0,0 @@ | |||
| 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 <errno.h> | ||
| 25 | #include <math.h> | ||
| 26 | |||
| 27 | /* see mtdev-mapping.h */ | ||
| 28 | #define MTDEV_POSITION_X 5 | ||
| 29 | #define MTDEV_POSITION_Y 6 | ||
| 30 | #define MTDEV_ORIENTATION 4 | ||
| 31 | #define MTDEV_PRESSURE 10 | ||
| 32 | |||
| 33 | #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) | ||
| 34 | |||
| 35 | static const int bits_per_long = 8 * sizeof(long); | ||
| 36 | |||
| 37 | static inline int nlongs(int nbit) | ||
| 38 | { | ||
| 39 | return (nbit + bits_per_long - 1) / bits_per_long; | ||
| 40 | } | ||
| 41 | |||
| 42 | static inline int getbit(const unsigned long *map, int key) | ||
| 43 | { | ||
| 44 | return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; | ||
| 45 | } | ||
| 46 | |||
| 47 | int touch_caps_is_supported(struct touch_dev *dev, int fd) | ||
| 48 | { | ||
| 49 | unsigned long keybits[nlongs(KEY_MAX)]; | ||
| 50 | unsigned long absbits[nlongs(ABS_MAX)]; | ||
| 51 | unsigned long relbits[nlongs(REL_CNT)]; | ||
| 52 | int rc; | ||
| 53 | |||
| 54 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits)); | ||
| 55 | if (rc < 0) | ||
| 56 | return 0; | ||
| 57 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); | ||
| 58 | if (rc < 0) | ||
| 59 | return 0; | ||
| 60 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits)); | ||
| 61 | if (rc < 0) | ||
| 62 | return 0; | ||
| 63 | |||
| 64 | /* only support pure absolute devices at this time */ | ||
| 65 | if (getbit(relbits, REL_X) || getbit(relbits, REL_Y)) | ||
| 66 | return 0; | ||
| 67 | |||
| 68 | if (dev->mtdev.caps.has_mtdata) | ||
| 69 | return 1; | ||
| 70 | |||
| 71 | return getbit(absbits, ABS_X) && | ||
| 72 | getbit(absbits, ABS_Y) && | ||
| 73 | getbit(keybits, BTN_TOUCH) && | ||
| 74 | getbit(keybits, BTN_TOOL_DOUBLETAP); | ||
| 75 | } | ||
| 76 | |||
| 77 | void touch_caps_init(struct touch_dev *dev) | ||
| 78 | { | ||
| 79 | const struct mtdev_caps *mt = &dev->mtdev.caps; | ||
| 80 | struct touch_caps *caps = &dev->caps; | ||
| 81 | caps->min_x = mt->abs[MTDEV_POSITION_X].minimum; | ||
| 82 | caps->max_x = mt->abs[MTDEV_POSITION_X].maximum; | ||
| 83 | caps->min_y = mt->abs[MTDEV_POSITION_Y].minimum; | ||
| 84 | caps->max_y = mt->abs[MTDEV_POSITION_Y].maximum; | ||
| 85 | caps->min_orient = mt->abs[MTDEV_ORIENTATION].minimum; | ||
| 86 | caps->max_orient = mt->abs[MTDEV_ORIENTATION].maximum; | ||
| 87 | caps->min_press = mt->abs[MTDEV_PRESSURE].minimum; | ||
| 88 | caps->max_press = mt->abs[MTDEV_PRESSURE].maximum; | ||
| 89 | if (caps->min_x == caps->max_x) { | ||
| 90 | caps->min_x = 0; | ||
| 91 | caps->max_x = 1024; | ||
| 92 | } | ||
| 93 | if (caps->min_y == caps->max_y) { | ||
| 94 | caps->min_y = 0; | ||
| 95 | caps->max_y = 768; | ||
| 96 | } | ||
| 97 | if (caps->min_orient == caps->max_orient) | ||
| 98 | caps->max_orient = 1; | ||
| 99 | if (caps->min_orient + caps->max_orient != 0) | ||
| 100 | caps->min_orient = -caps->max_orient; | ||
| 101 | if (caps->min_press == caps->max_press) { | ||
| 102 | caps->min_press = 0; | ||
| 103 | caps->max_press = 256; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 107 | float touch_angle(const struct touch_dev *dev, int orient) | ||
| 108 | { | ||
| 109 | const struct touch_caps *caps = &dev->caps; | ||
| 110 | return orient / caps->max_orient * M_PI_2; | ||
| 111 | } | ||
| 112 | |||
| 113 | float touch_pressure(const struct touch_dev *dev, int press) | ||
| 114 | { | ||
| 115 | const struct touch_caps *caps = &dev->caps; | ||
| 116 | return (press - caps->min_press) / (caps->max_press - caps->min_press); | ||
| 117 | } | ||
