Clean up spec file for packaging.
[profile/ivi/xorg-drv-mtev.git] / src / hw.c
1 /***************************************************************************
2  *
3  * Multitouch protocol X driver
4  * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
5  * Copyright (C) 2009,2010 Nokia Corporation
6  *
7  * Adaptation to libmtdev and Linux multi-touch-protocol B (slotted)
8  * Copyright (C) 2010 Intel Corporation
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23  *
24  **************************************************************************/
25
26 #include <string.h>
27 #include <linux/input.h>
28 #include <xf86.h>
29 #include <mtdev.h>
30
31 #include "hw.h"
32
33 void hw_init(struct mtev_hw_state *hw)
34 {
35         int i;
36         memset(hw, 0, sizeof(struct mtev_hw_state));
37         for (i = 0; i < HW_MAX_SLOTS; i++)
38             hw->slot[i].tracking_id = INVALID_TRACKING_ID;
39 }
40
41 bool hw_read(struct mtev_hw_state *hw, const struct input_event* ev)
42 {
43         // xf86Msg(X_INFO, "event: %d %d %d\n", ev->type, ev->code, ev->value);
44
45         switch (ev->type) {
46         case EV_SYN:
47                 switch (ev->code) {
48                 case SYN_REPORT:
49                         return 1;
50
51                 case SYN_MT_REPORT:
52                         xf86Msg(X_ERROR, "libmtdev sent SYN_MT_REPORT");
53                         break;
54                 }
55                 break;
56
57         case EV_ABS:
58                 if (ev->code == ABS_MT_SLOT) {
59                         if (ev->value >= HW_MAX_SLOTS) {
60                                 xf86Msg(X_ERROR, "Slot usage (%d) exceeds limit of %d", ev->value, HW_MAX_SLOTS);
61                                 hw->current_slot = INVALID_SLOT;
62                         } else
63                                 hw->current_slot = ev->value;
64                         break;
65                 }
66
67                 if (hw->current_slot == INVALID_SLOT)
68                         break;
69
70                 switch (ev->code) {
71                 case ABS_MT_POSITION_X:
72                         hw->slot[hw->current_slot].position_x = ev->value;
73                         break;
74                 case ABS_MT_POSITION_Y:
75                         hw->slot[hw->current_slot].position_y = ev->value;
76                         break;
77                 case ABS_MT_TOUCH_MAJOR:
78                         hw->slot[hw->current_slot].touch_major = ev->value;
79                         break;
80                 case ABS_MT_TOUCH_MINOR:
81                         hw->slot[hw->current_slot].touch_minor = ev->value;
82                         break;
83                 case ABS_MT_WIDTH_MAJOR:
84                         hw->slot[hw->current_slot].width_major = ev->value;
85                         break;
86                 case ABS_MT_WIDTH_MINOR:
87                         hw->slot[hw->current_slot].width_minor = ev->value;
88                         break;
89                 case ABS_MT_ORIENTATION:
90                         hw->slot[hw->current_slot].orientation = ev->value;
91                         break;
92                 case ABS_MT_PRESSURE:
93                         hw->slot[hw->current_slot].pressure = ev->value;
94                         break;
95                 case ABS_MT_TRACKING_ID:
96                         if (ev->value == -1) /* Slot contact has been released */
97                                 hw->slot[hw->current_slot].tracking_id = INVALID_TRACKING_ID;
98                         else
99                                 hw->slot[hw->current_slot].tracking_id = hw->current_slot;//ev->value;
100                         break;
101                 }
102         }
103
104         return 0;
105 }