diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2010-10-12 15:38:43 +0200 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2010-10-12 15:38:43 +0200 |
| commit | acea9df3381825a634c000a574f58b4ca5293ee8 (patch) | |
| tree | 3698bd55f137bc377f1b840e4fb5bf9e446e7250 /src/capabilities.c | |
| parent | 7380af2c93dc83f4f09e293717d46eadf7799e89 (diff) | |
Same version, but using the mtdev library.
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/capabilities.c')
| -rw-r--r-- | src/capabilities.c | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/src/capabilities.c b/src/capabilities.c new file mode 100644 index 0000000..0d11669 --- /dev/null +++ b/src/capabilities.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * Multitouch X driver | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | * | ||
| 20 | **************************************************************************/ | ||
| 21 | |||
| 22 | #include "capabilities.h" | ||
| 23 | |||
| 24 | #define SETABS(c, x, map, key, fd) \ | ||
| 25 | (c->has_##x = getbit(map, key) && getabs(&c->x, key, fd)) | ||
| 26 | |||
| 27 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") | ||
| 28 | |||
| 29 | static const int SN_COORD = 250; /* coordinate signal-to-noise ratio */ | ||
| 30 | static const int SN_WIDTH = 100; /* width signal-to-noise ratio */ | ||
| 31 | static const int SN_ORIENT = 10; /* orientation signal-to-noise ratio */ | ||
| 32 | |||
| 33 | static const int bits_per_long = 8 * sizeof(long); | ||
| 34 | |||
| 35 | static inline int nlongs(int nbit) | ||
| 36 | { | ||
| 37 | return (nbit + bits_per_long - 1) / bits_per_long; | ||
| 38 | } | ||
| 39 | |||
| 40 | static inline int getbit(const unsigned long *map, int key) | ||
| 41 | { | ||
| 42 | return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; | ||
| 43 | } | ||
| 44 | |||
| 45 | static int getabs(struct input_absinfo *abs, int key, int fd) | ||
| 46 | { | ||
| 47 | int rc; | ||
| 48 | SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs)); | ||
| 49 | return rc >= 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | static int has_mt_data(const struct Capabilities *cap) | ||
| 53 | { | ||
| 54 | return cap->has_abs[MTDEV_POSITION_X] && cap->has_abs[MTDEV_POSITION_Y]; | ||
| 55 | } | ||
| 56 | |||
| 57 | static int has_integrated_button(const struct Capabilities *cap) | ||
| 58 | { | ||
| 59 | static const int bcm5974_vmask_ibt = 1; | ||
| 60 | if (strcmp(cap->devname, "bcm5974")) | ||
| 61 | return 0; | ||
| 62 | return cap->devid.version & bcm5974_vmask_ibt; | ||
| 63 | } | ||
| 64 | |||
| 65 | static void default_fuzz(struct Capabilities *cap, unsigned int code, int sn) | ||
| 66 | { | ||
| 67 | int bit = mtdev_abs2mt(code); | ||
| 68 | if (cap->has_abs[bit] && cap->abs[bit].fuzz == 0) | ||
| 69 | cap->abs[bit].fuzz = | ||
| 70 | (cap->abs[bit].maximum - cap->abs[bit].minimum) / sn; | ||
| 71 | } | ||
| 72 | |||
| 73 | int read_capabilities(struct Capabilities *cap, int fd) | ||
| 74 | { | ||
| 75 | unsigned long evbits[nlongs(EV_MAX)]; | ||
| 76 | unsigned long absbits[nlongs(ABS_MAX)]; | ||
| 77 | unsigned long keybits[nlongs(KEY_MAX)]; | ||
| 78 | int rc, i; | ||
| 79 | |||
| 80 | memset(cap, 0, sizeof(struct Capabilities)); | ||
| 81 | |||
| 82 | SYSCALL(rc = ioctl(fd, EVIOCGID, &cap->devid)); | ||
| 83 | if (rc < 0) | ||
| 84 | return rc; | ||
| 85 | SYSCALL(rc = ioctl(fd, EVIOCGNAME(sizeof(cap->devname)), cap->devname)); | ||
| 86 | if (rc < 0) | ||
| 87 | return rc; | ||
| 88 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits)); | ||
| 89 | if (rc < 0) | ||
| 90 | return rc; | ||
| 91 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits)); | ||
| 92 | if (rc < 0) | ||
| 93 | return rc; | ||
| 94 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); | ||
| 95 | if (rc < 0) | ||
| 96 | return rc; | ||
| 97 | |||
| 98 | cap->has_left = getbit(keybits, BTN_LEFT); | ||
| 99 | cap->has_middle = getbit(keybits, BTN_MIDDLE); | ||
| 100 | cap->has_right = getbit(keybits, BTN_RIGHT); | ||
| 101 | |||
| 102 | SETABS(cap, slot, absbits, ABS_MT_SLOT, fd); | ||
| 103 | for (i = 0; i < MT_ABS_SIZE; i++) | ||
| 104 | SETABS(cap, abs[i], absbits, mtdev_mt2abs(i), fd); | ||
| 105 | |||
| 106 | cap->has_mtdata = has_mt_data(cap); | ||
| 107 | cap->has_ibt = has_integrated_button(cap); | ||
| 108 | |||
| 109 | default_fuzz(cap, ABS_MT_POSITION_X, SN_COORD); | ||
| 110 | default_fuzz(cap, ABS_MT_POSITION_Y, SN_COORD); | ||
| 111 | default_fuzz(cap, ABS_MT_TOUCH_MAJOR, SN_WIDTH); | ||
| 112 | default_fuzz(cap, ABS_MT_TOUCH_MINOR, SN_WIDTH); | ||
| 113 | default_fuzz(cap, ABS_MT_WIDTH_MAJOR, SN_WIDTH); | ||
| 114 | default_fuzz(cap, ABS_MT_WIDTH_MINOR, SN_WIDTH); | ||
| 115 | default_fuzz(cap, ABS_MT_ORIENTATION, SN_ORIENT); | ||
| 116 | |||
| 117 | return 0; | ||
| 118 | } | ||
| 119 | |||
| 120 | int get_cap_xsize(const struct Capabilities *cap) | ||
| 121 | { | ||
| 122 | const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X]; | ||
| 123 | return x->maximum - x->minimum; | ||
| 124 | } | ||
| 125 | |||
| 126 | int get_cap_ysize(const struct Capabilities *cap) | ||
| 127 | { | ||
| 128 | const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y]; | ||
| 129 | return y->maximum - y->minimum; | ||
| 130 | } | ||
| 131 | |||
| 132 | int get_cap_wsize(const struct Capabilities *cap) | ||
| 133 | { | ||
| 134 | const struct input_absinfo *w = &cap->abs[MTDEV_TOUCH_MAJOR]; | ||
| 135 | return w->maximum - w->minimum; | ||
| 136 | } | ||
| 137 | |||
| 138 | int get_cap_xmid(const struct Capabilities *cap) | ||
| 139 | { | ||
| 140 | const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X]; | ||
| 141 | return (x->maximum + x->minimum) >> 1; | ||
| 142 | } | ||
| 143 | |||
| 144 | int get_cap_ymid(const struct Capabilities *cap) | ||
| 145 | { | ||
| 146 | const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y]; | ||
| 147 | return (y->maximum + y->minimum) >> 1; | ||
| 148 | } | ||
| 149 | |||
| 150 | void output_capabilities(const struct Capabilities *cap) | ||
| 151 | { | ||
| 152 | char line[1024]; | ||
| 153 | int i; | ||
| 154 | memset(line, 0, sizeof(line)); | ||
| 155 | ADDCAP(line, cap, left); | ||
| 156 | ADDCAP(line, cap, middle); | ||
| 157 | ADDCAP(line, cap, right); | ||
| 158 | ADDCAP(line, cap, mtdata); | ||
| 159 | ADDCAP(line, cap, ibt); | ||
| 160 | xf86Msg(X_INFO, "multitouch: devname: %s\n", cap->devname); | ||
| 161 | xf86Msg(X_INFO, "multitouch: devid: %x %x %x\n", | ||
| 162 | cap->devid.vendor, cap->devid.product, cap->devid.version); | ||
| 163 | xf86Msg(X_INFO, "multitouch: caps:%s\n", line); | ||
| 164 | for (i = 0; i < MT_ABS_SIZE; i++) { | ||
| 165 | if (cap->has_abs[i]) | ||
| 166 | xf86Msg(X_INFO, "multitouch: %d: min: %d max: %d\n", | ||
| 167 | i, | ||
| 168 | cap->abs[i].minimum, | ||
| 169 | cap->abs[i].maximum); | ||
| 170 | } | ||
| 171 | } | ||
