summaryrefslogtreecommitdiff
path: root/mtdev/hwdata.c
diff options
context:
space:
mode:
Diffstat (limited to 'mtdev/hwdata.c')
-rw-r--r--mtdev/hwdata.c133
1 files changed, 133 insertions, 0 deletions
diff --git a/mtdev/hwdata.c b/mtdev/hwdata.c
new file mode 100644
index 0000000..689418e
--- /dev/null
+++ b/mtdev/hwdata.c
@@ -0,0 +1,133 @@
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 "hwdata.h"
23
24void init_hwdata(struct HWData *hw)
25{
26 memset(hw, 0, sizeof(struct HWData));
27}
28
29static void set_value(struct HWData *hw, int code, int value)
30{
31 if (hw->nread < DIM_FINGER) {
32 (&hw->finger[hw->nread].touch_major)[code] = value;
33 SETBIT(hw->mread[hw->nread], code);
34 }
35 hw->mtread++;
36}
37
38static void accept_finger(struct HWData *hw)
39{
40 if (hw->nread < DIM_FINGER &&
41 GETBIT(hw->mread[hw->nread], BIT_MT_POSITION_X) &&
42 GETBIT(hw->mread[hw->nread], BIT_MT_POSITION_Y)) {
43 hw->mask[hw->nread] = hw->mread[hw->nread];
44 hw->nread++;
45 }
46 if (hw->nread < DIM_FINGER)
47 hw->mread[hw->nread] = 0;
48}
49
50static void accept_packet(struct HWData *hw, const struct timeval* tv)
51{
52 static const mstime_t ms = 1000;
53 if (hw->mtread)
54 hw->nfinger = hw->nread;
55 hw->mtread = 0;
56 hw->nread = 0;
57 hw->mread[hw->nread] = 0;
58 hw->evtime = tv->tv_usec / ms + tv->tv_sec * ms;
59}
60
61int read_hwdata(struct HWData *hw, const struct input_event* ev)
62{
63 switch (ev->type) {
64 case EV_SYN:
65 switch (ev->code) {
66 case SYN_REPORT:
67 accept_packet(hw, &ev->time);
68 return 1;
69 case SYN_MT_REPORT:
70 accept_finger(hw);
71 break;
72 }
73 break;
74 case EV_KEY:
75 switch (ev->code) {
76 case BTN_TOUCH:
77 hw->mtread++;
78 break;
79 case BTN_LEFT:
80 if (ev->value)
81 SETBIT(hw->button, MT_BUTTON_LEFT);
82 else
83 CLEARBIT(hw->button, MT_BUTTON_LEFT);
84 break;
85 case BTN_MIDDLE:
86 if (ev->value)
87 SETBIT(hw->button, MT_BUTTON_MIDDLE);
88 else
89 CLEARBIT(hw->button, MT_BUTTON_MIDDLE);
90 break;
91 case BTN_RIGHT:
92 if (ev->value)
93 SETBIT(hw->button, MT_BUTTON_RIGHT);
94 else
95 CLEARBIT(hw->button, MT_BUTTON_RIGHT);
96 break;
97 }
98 break;
99 case EV_ABS:
100 switch (ev->code) {
101 case ABS_MT_TOUCH_MAJOR:
102 set_value(hw, BIT_MT_TOUCH_MAJOR, ev->value);
103 break;
104 case ABS_MT_TOUCH_MINOR:
105 set_value(hw, BIT_MT_TOUCH_MINOR, ev->value);
106 break;
107 case ABS_MT_WIDTH_MAJOR:
108 set_value(hw, BIT_MT_WIDTH_MAJOR, ev->value);
109 break;
110 case ABS_MT_WIDTH_MINOR:
111 set_value(hw, BIT_MT_WIDTH_MINOR, ev->value);
112 break;
113 case ABS_MT_ORIENTATION:
114 set_value(hw, BIT_MT_ORIENTATION, ev->value);
115 break;
116 case ABS_MT_PRESSURE:
117 set_value(hw, BIT_MT_PRESSURE, ev->value);
118 break;
119 case ABS_MT_POSITION_X:
120 set_value(hw, BIT_MT_POSITION_X, ev->value);
121 break;
122 case ABS_MT_POSITION_Y:
123 set_value(hw, BIT_MT_POSITION_Y, ev->value);
124 break;
125 }
126 break;
127 }
128 return 0;
129}
130
131void output_hwdata(const struct HWData *hw)
132{
133}