blob: 3f1e582e3eccb7701f066bf4f6d90cbf83afd307 [file] [log] [blame]
Dennis Kempina9963ba2012-06-08 10:32:23 -07001/*
2 * Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
Dennis Kempin320aef12012-06-11 15:26:52 -07007#include <libevdev/libevdev_event.h>
Dennis Kempina9963ba2012-06-08 10:32:23 -07008
9#include <errno.h>
10#include <linux/input.h>
11#include <stdbool.h>
12#include <time.h>
13
Dennis Kempin320aef12012-06-11 15:26:52 -070014#include <libevdev/libevdev.h>
15#include <libevdev/libevdev_util.h>
Dennis Kempina9963ba2012-06-08 10:32:23 -070016
17#ifndef BTN_TOOL_QUINTTAP
18#define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */
19#endif
20
21/* Set clockid to be used for timestamps */
22#ifndef EVIOCSCLOCKID
23#define EVIOCSCLOCKID _IOW('E', 0xa0, int)
24#endif
25
26#ifndef EVIOCGMTSLOTS
27#define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len)
28#endif
29
30/* SYN_DROPPED added in kernel v2.6.38-rc4 */
31#ifndef SYN_DROPPED
32#define SYN_DROPPED 3
33#endif
34
Chung-yih Wang1359d8b2012-11-21 11:25:33 +080035/* make VCSID as version number */
36#ifndef VCSID
37#define VCSID "Unknown"
38#endif
Dennis Kempina9963ba2012-06-08 10:32:23 -070039
Che-Liang Chiouf616b122012-10-24 17:08:51 -070040static void Event_Clear_Ev_Rel_State(EvdevPtr);
Dennis Kempina9963ba2012-06-08 10:32:23 -070041
Che-Liang Chiouf616b122012-10-24 17:08:51 -070042static bool Event_Syn(EvdevPtr, struct input_event*);
Dennis Kempina9963ba2012-06-08 10:32:23 -070043static void Event_Syn_Report(EvdevPtr, struct input_event*);
44static void Event_Syn_MT_Report(EvdevPtr, struct input_event*);
45
46static void Event_Key(EvdevPtr, struct input_event*);
47
48static void Event_Abs(EvdevPtr, struct input_event*);
49static void Event_Abs_MT(EvdevPtr, struct input_event*);
Chung-yih Wang8b2fa0a2012-07-23 16:49:10 +080050static void Event_Abs_Update_Pressure(EvdevPtr, struct input_event*);
Dennis Kempina9963ba2012-06-08 10:32:23 -070051
Che-Liang Chiouf616b122012-10-24 17:08:51 -070052static void Event_Rel(EvdevPtr, struct input_event*);
53
Dennis Kempina9963ba2012-06-08 10:32:23 -070054static void Event_Get_Time(struct timeval*, bool);
55
Chung-yih Wang1359d8b2012-11-21 11:25:33 +080056const char*
57Evdev_Get_Version() {
58 return VCSID;
59}
60
Dennis Kempina9963ba2012-06-08 10:32:23 -070061/**
62 * Input Device Event Property accessors
63 */
64int
65Event_Get_Left(EvdevPtr device)
66{
Yufeng Shen86e52252012-07-05 11:44:36 -040067 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_POSITION_X];
Dennis Kempina9963ba2012-06-08 10:32:23 -070068 return absinfo->minimum;
69}
70
71int
72Event_Get_Right(EvdevPtr device)
73{
Yufeng Shen86e52252012-07-05 11:44:36 -040074 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_POSITION_X];
Dennis Kempina9963ba2012-06-08 10:32:23 -070075 return absinfo->maximum;
76}
77
78int
79Event_Get_Top(EvdevPtr device)
80{
Yufeng Shen86e52252012-07-05 11:44:36 -040081 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_POSITION_Y];
Dennis Kempina9963ba2012-06-08 10:32:23 -070082 return absinfo->minimum;
83}
84
85int
86Event_Get_Bottom(EvdevPtr device)
87{
Yufeng Shen86e52252012-07-05 11:44:36 -040088 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_POSITION_Y];
Dennis Kempina9963ba2012-06-08 10:32:23 -070089 return absinfo->maximum;
90}
91
92int
93Event_Get_Res_Y(EvdevPtr device)
94{
Yufeng Shen86e52252012-07-05 11:44:36 -040095 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_POSITION_Y];
Dennis Kempina9963ba2012-06-08 10:32:23 -070096 return absinfo->resolution;
97}
98
99int
100Event_Get_Res_X(EvdevPtr device)
101{
Yufeng Shen86e52252012-07-05 11:44:36 -0400102 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_POSITION_X];
Dennis Kempina9963ba2012-06-08 10:32:23 -0700103 return absinfo->resolution;
104}
105
106int
Che-Liang Chioua2563012012-10-11 11:41:06 -0700107Event_Get_Orientation_Minimum(EvdevPtr device)
108{
109 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_ORIENTATION];
110 return absinfo->minimum;
111}
112
113int
114Event_Get_Orientation_Maximum(EvdevPtr device)
115{
116 struct input_absinfo* absinfo = &device->info.absinfo[ABS_MT_ORIENTATION];
117 return absinfo->maximum;
118}
119
120int
Dennis Kempina9963ba2012-06-08 10:32:23 -0700121Event_Get_Button_Pad(EvdevPtr device)
122{
123 return TestBit(INPUT_PROP_BUTTONPAD, device->info.prop_bitmask);
124}
125
126int
127Event_Get_Semi_MT(EvdevPtr device)
128{
129 return TestBit(INPUT_PROP_SEMI_MT, device->info.prop_bitmask);
130}
131
132int
133Event_Get_T5R2(EvdevPtr device)
134{
135 EventStatePtr evstate = device->evstate;
136 if (Event_Get_Semi_MT(device))
137 return 0;
138 return (Event_Get_Touch_Count_Max(device) > evstate->slot_count);
139}
140
141int
142Event_Get_Touch_Count_Max(EvdevPtr device)
143{
144
145 if (TestBit(BTN_TOOL_QUINTTAP, device->info.key_bitmask))
146 return 5;
147 if (TestBit(BTN_TOOL_QUADTAP, device->info.key_bitmask))
148 return 4;
149 if (TestBit(BTN_TOOL_TRIPLETAP, device->info.key_bitmask))
150 return 3;
151 if (TestBit(BTN_TOOL_DOUBLETAP, device->info.key_bitmask))
152 return 2;
153 return 1;
154}
155
156int
157Event_Get_Touch_Count(EvdevPtr device)
158{
159
160 if (TestBit(BTN_TOOL_QUINTTAP, device->key_state_bitmask))
161 return 5;
162 if (TestBit(BTN_TOOL_QUADTAP, device->key_state_bitmask))
163 return 4;
164 if (TestBit(BTN_TOOL_TRIPLETAP, device->key_state_bitmask))
165 return 3;
166 if (TestBit(BTN_TOOL_DOUBLETAP, device->key_state_bitmask))
167 return 2;
168 if (TestBit(BTN_TOOL_FINGER, device->key_state_bitmask))
169 return 1;
170 return 0;
171}
172
173int
174Event_Get_Slot_Count(EvdevPtr device)
175{
176 EventStatePtr evstate = device->evstate;
177 return evstate->slot_count;
178}
179
180int
181Event_Get_Button_Left(EvdevPtr device)
182{
183 return TestBit(BTN_LEFT, device->key_state_bitmask);
184}
185
186int
187Event_Get_Button_Middle(EvdevPtr device)
188{
189 return TestBit(BTN_MIDDLE, device->key_state_bitmask);
190}
191
192int
193Event_Get_Button_Right(EvdevPtr device)
194{
195 return TestBit(BTN_RIGHT, device->key_state_bitmask);
196}
197
198#define CASE_RETURN(s) \
199 case (s):\
200 return #s
201
202
203const char *
204Event_To_String(int type, int code) {
205 switch (type) {
206 case EV_SYN:
207 switch (code) {
208 CASE_RETURN(SYN_REPORT);
209 CASE_RETURN(SYN_MT_REPORT);
210 default:
211 break;
212 }
213 break;
214 case EV_ABS:
215 switch (code) {
216 CASE_RETURN(ABS_X);
217 CASE_RETURN(ABS_Y);
218 CASE_RETURN(ABS_Z);
219 CASE_RETURN(ABS_PRESSURE);
220 CASE_RETURN(ABS_TOOL_WIDTH);
221 CASE_RETURN(ABS_MT_TOUCH_MAJOR);
222 CASE_RETURN(ABS_MT_TOUCH_MINOR);
223 CASE_RETURN(ABS_MT_WIDTH_MAJOR);
224 CASE_RETURN(ABS_MT_WIDTH_MINOR);
225 CASE_RETURN(ABS_MT_ORIENTATION);
226 CASE_RETURN(ABS_MT_POSITION_X);
227 CASE_RETURN(ABS_MT_POSITION_Y);
228 CASE_RETURN(ABS_MT_TOOL_TYPE);
229 CASE_RETURN(ABS_MT_BLOB_ID);
230 CASE_RETURN(ABS_MT_TRACKING_ID);
231 CASE_RETURN(ABS_MT_PRESSURE);
232 CASE_RETURN(ABS_MT_SLOT);
233 default:
234 break;
235 }
236 break;
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700237 case EV_REL:
238 switch (code) {
239 CASE_RETURN(REL_X);
240 CASE_RETURN(REL_Y);
241 CASE_RETURN(REL_WHEEL);
242 CASE_RETURN(REL_HWHEEL);
243 default:
244 break;
245 }
246 break;
Dennis Kempina9963ba2012-06-08 10:32:23 -0700247 case EV_KEY:
248 switch (code) {
249 CASE_RETURN(BTN_LEFT);
250 CASE_RETURN(BTN_RIGHT);
251 CASE_RETURN(BTN_MIDDLE);
252 CASE_RETURN(BTN_TOUCH);
253 CASE_RETURN(BTN_TOOL_FINGER);
254 CASE_RETURN(BTN_TOOL_DOUBLETAP);
255 CASE_RETURN(BTN_TOOL_TRIPLETAP);
256 CASE_RETURN(BTN_TOOL_QUADTAP);
257 CASE_RETURN(BTN_TOOL_QUINTTAP);
258 default:
259 break;
260 }
261 break;
262 default:
263 break;
264 }
265 return "?";
266}
267#undef CASE_RETURN
268
269const char *
270Event_Type_To_String(int type) {
271 switch (type) {
272 case EV_SYN: return "SYN";
273 case EV_KEY: return "KEY";
274 case EV_REL: return "REL";
275 case EV_ABS: return "ABS";
276 case EV_MSC: return "MSC";
277 case EV_SW: return "SW";
278 case EV_LED: return "LED";
279 case EV_SND: return "SND";
280 case EV_REP: return "REP";
281 case EV_FF: return "FF";
282 case EV_PWR: return "PWR";
283 default: return "?";
284 }
285}
286
287
288/**
289 * Probe Device Input Event Support
290 */
291int
292Event_Init(EvdevPtr device)
293{
294 int i;
295 EventStatePtr evstate;
296
297 evstate = device->evstate;
298 if (EvdevProbe(device) != Success) {
299 return !Success;
300 }
301
Dennis Kempina9963ba2012-06-08 10:32:23 -0700302 for (i = ABS_X; i <= ABS_MAX; i++) {
303 if (TestBit(i, device->info.abs_bitmask)) {
304 struct input_absinfo* absinfo = &device->info.absinfo[i];
305 if (i == ABS_MT_SLOT) {
306 int rc;
307 rc = MTB_Init(device, absinfo->minimum, absinfo->maximum,
308 absinfo->value);
309 if (rc != Success)
310 return rc;
311 } else if (IS_ABS_MT(i)) {
312 evstate->mt_axes[MT_CODE(i)] = absinfo;
313 }
314 }
315 }
Dennis Kempina9963ba2012-06-08 10:32:23 -0700316 return Success;
317}
318
319void
320Event_Free(EvdevPtr device)
321{
322 MT_Free(device);
323}
324
325void
326Event_Open(EvdevPtr device)
327{
328 /* Select monotonic input event timestamps, if supported by kernel */
329 device->info.is_monotonic = (EvdevEnableMonotonic(device) == Success);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700330 LOG_DEBUG(device, "Using %s input event time stamps\n",
331 device->info.is_monotonic ? "monotonic" : "realtime");
Daniel Kurtz000bdff2012-09-17 15:45:29 +0800332
333 /* Synchronize all MT slots with kernel evdev driver */
334 Event_Sync_State(device);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700335}
336
337static void
338Event_Get_Time(struct timeval *t, bool use_monotonic) {
339 struct timespec now;
340 clockid_t clockid = (use_monotonic) ? CLOCK_MONOTONIC : CLOCK_REALTIME;
341
342 clock_gettime(clockid, &now);
343 t->tv_sec = now.tv_sec;
344 t->tv_usec = now.tv_nsec / 1000;
345}
346
347/**
348 * Synchronize the current state with kernel evdev driver. For cmt, there are
349 * only four components required to be synced: current touch count, the MT
350 * slots information, current slot id and physical button states. However, as
351 * pressure readings are missing in ABS_MT_PRESSURE field of MT slots for
352 * semi_mt touchpad device (e.g. Cr48), we also need need to extract it with
353 * extra EVIOCGABS query.
354 */
355void
356Event_Sync_State(EvdevPtr device)
357{
358 int i;
359
360 Event_Get_Time(&device->before_sync_time, device->info.is_monotonic);
361
362 EvdevProbeKeyState(device);
363
Chung-yih Wang8b2fa0a2012-07-23 16:49:10 +0800364 /* Get current pressure information for single-pressure device */
365 if (EvdevIsSinglePressureDevice(device) == Success) {
366 struct input_event ev;
367 ev.code = ABS_PRESSURE;
368 ev.value = device->info.absinfo[ABS_PRESSURE].value;
369 Event_Abs_Update_Pressure(device, &ev);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700370 }
371
372 /* TODO(cywang): Sync all ABS_ states for completeness */
373
374 /* Get current MT information for each slot */
375 for (i = _ABS_MT_FIRST; i <= _ABS_MT_LAST; i++) {
376 MTSlotInfo req;
377
378 if (!TestBit(i, device->info.abs_bitmask))
379 continue;
380 /*
381 * TODO(cywang): Scale the size of slots in MTSlotInfo based on the
382 * evstate->slot_count.
383 */
384
385 req.code = i;
386 if (EvdevProbeMTSlot(device, &req) != Success) {
387 continue;
388 }
389 MT_Slot_Sync(device, &req);
390 }
391
392 /* Get current slot id */
393 if (EvdevProbeAbsinfo(device, ABS_MT_SLOT) == Success)
394 MT_Slot_Set(device, device->info.absinfo[ABS_MT_SLOT].value);
395
396 Event_Get_Time(&device->after_sync_time, device->info.is_monotonic);
397
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700398 /* Initialize EV_REL event state */
399 Event_Clear_Ev_Rel_State(device);
400
Chung-yih Wangb709c082012-07-20 16:26:15 +0800401 LOG_WARNING(device, "Event_Sync_State: before %ld.%ld after %ld.%ld\n",
402 device->before_sync_time.tv_sec,
403 device->before_sync_time.tv_usec,
404 device->after_sync_time.tv_sec,
405 device->after_sync_time.tv_usec);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700406}
407
408static void
409Event_Print(EvdevPtr device, struct input_event* ev)
410{
411 switch (ev->type) {
412 case EV_SYN:
413 switch (ev->code) {
414 case SYN_REPORT:
Dennis Kempinde0712f2012-06-11 15:13:50 -0700415 LOG_DEBUG(device, "@ %ld.%06ld ---------- SYN_REPORT -------\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700416 ev->time.tv_sec, ev->time.tv_usec);
417 return;
418 case SYN_MT_REPORT:
Dennis Kempinde0712f2012-06-11 15:13:50 -0700419 LOG_DEBUG(device, "@ %ld.%06ld ........ SYN_MT_REPORT ......\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700420 ev->time.tv_sec, ev->time.tv_usec);
421 return;
422 case SYN_DROPPED:
Dennis Kempin85a14442012-06-25 11:24:59 -0700423 LOG_WARNING(device, "@ %ld.%06ld ++++++++ SYN_DROPPED ++++++++\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700424 ev->time.tv_sec, ev->time.tv_usec);
425 return;
426 default:
Dennis Kempin85a14442012-06-25 11:24:59 -0700427 LOG_WARNING(device, "@ %ld.%06ld ?????? SYN_UNKNOWN (%d) ?????\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700428 ev->time.tv_sec, ev->time.tv_usec, ev->code);
429 return;
430 }
431 break;
432 case EV_ABS:
433 if (ev->code == ABS_MT_SLOT) {
Dennis Kempinde0712f2012-06-11 15:13:50 -0700434 LOG_DEBUG(device, "@ %ld.%06ld .......... MT SLOT %d ........\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700435 ev->time.tv_sec, ev->time.tv_usec, ev->value);
436 return;
437 }
438 break;
439 default:
440 break;
441 }
442
Dennis Kempinde0712f2012-06-11 15:13:50 -0700443 LOG_DEBUG(device, "@ %ld.%06ld %s[%d] (%s) = %d\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700444 ev->time.tv_sec, ev->time.tv_usec, Event_Type_To_String(ev->type),
445 ev->code, Event_To_String(ev->type, ev->code), ev->value);
446}
447
448/**
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700449 * Process Input Events. It returns TRUE if SYN_DROPPED detected.
Dennis Kempina9963ba2012-06-08 10:32:23 -0700450 */
451bool
452Event_Process(EvdevPtr device, struct input_event* ev)
453{
Dennis Kempina9963ba2012-06-08 10:32:23 -0700454 Event_Print(device, ev);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700455
456 switch (ev->type) {
457 case EV_SYN:
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700458 return Event_Syn(device, ev);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700459
460 case EV_KEY:
461 Event_Key(device, ev);
462 break;
463
464 case EV_ABS:
465 Event_Abs(device, ev);
466 break;
467
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700468 case EV_REL:
469 Event_Rel(device, ev);
470 break;
471
Dennis Kempina9963ba2012-06-08 10:32:23 -0700472 default:
473 break;
474 }
475 return false;
476}
477
478/**
479 * Dump the log of input events to disk
480 */
481void
482Event_Dump_Debug_Log(void* vinfo)
483{
484 EvdevPtr device = (EvdevPtr) vinfo;
485 size_t i;
486 EventStatePtr evstate = device->evstate;
487
488 FILE* fp = fopen("/var/log/cmt_input_events.dat", "wb");
489 if (!fp) {
490 LOG_ERROR(device, "fopen() failed for debug log");
491 return;
492 }
493 for (i = 0; i < DEBUG_BUF_SIZE; i++) {
494 size_t rc;
495 struct input_event *ev =
496 &evstate->debug_buf[(evstate->debug_buf_tail + i) % DEBUG_BUF_SIZE];
497 if (ev->time.tv_sec == 0 && ev->time.tv_usec == 0)
498 continue;
499 rc = fprintf(fp, "E: %ld.%06ld %04x %04x %d\n",
500 ev->time.tv_sec,
501 ev->time.tv_usec,
502 ev->type,
503 ev->code,
504 ev->value);
505 if (rc == 0) {
506 LOG_ERROR(device, "fprintf() failed for debug log. Log is short");
507 break;
508 }
509 }
510 fclose(fp);
511}
512
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700513/**
514 * Clear EV_REL event state. This function should be called after a EV_SYN
515 * event is processed because EV_REL event state is not accumulative.
516 */
Dennis Kempina9963ba2012-06-08 10:32:23 -0700517static void
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700518Event_Clear_Ev_Rel_State(EvdevPtr device)
519{
520 EventStatePtr evstate;
521
522 evstate = device->evstate;
523 evstate->rel_x = 0;
524 evstate->rel_y = 0;
525 evstate->rel_wheel = 0;
526 evstate->rel_hwheel = 0;
527}
528
529/**
530 * Process EV_SYN events. It returns TRUE if SYN_DROPPED detected.
531 */
532static bool
Dennis Kempina9963ba2012-06-08 10:32:23 -0700533Event_Syn(EvdevPtr device, struct input_event* ev)
534{
535 switch (ev->code) {
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700536 case SYN_DROPPED:
537 /*
538 * Technically we don't need to call Event_Clear_Ev_Rel_State() here
539 * because when SYN_DROPPED is detected, Event_Sync_State() will be
540 * called and Event_Sync_State() will call Event_Clear_Ev_Rel_State()
541 * to re-initialize EV_REL event state.
542 */
543 return true;
Dennis Kempina9963ba2012-06-08 10:32:23 -0700544 case SYN_REPORT:
545 Event_Syn_Report(device, ev);
546 break;
547 case SYN_MT_REPORT:
548 Event_Syn_MT_Report(device, ev);
549 break;
550 }
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700551 return false;
Dennis Kempina9963ba2012-06-08 10:32:23 -0700552}
553
554static void
555Event_Syn_Report(EvdevPtr device, struct input_event* ev)
556{
557 EventStatePtr evstate = device->evstate;
558 device->syn_report(device->syn_report_udata, evstate, &ev->time);
559
560 MT_Print_Slots(device);
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700561
562 Event_Clear_Ev_Rel_State(device);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700563}
564
565static void
566Event_Syn_MT_Report(EvdevPtr device, struct input_event* ev)
567{
568 /* TODO(djkurtz): Handle MT-A */
569}
570
571static void
572Event_Key(EvdevPtr device, struct input_event* ev)
573{
574 AssignBit(device->key_state_bitmask, ev->code, ev->value);
575}
576
577static void
Chung-yih Wang8b2fa0a2012-07-23 16:49:10 +0800578Event_Abs_Update_Pressure(EvdevPtr device, struct input_event* ev)
Dennis Kempina9963ba2012-06-08 10:32:23 -0700579{
580 /*
581 * Update all active slots with the same ABS_PRESSURE value if it is a
Chung-yih Wang8b2fa0a2012-07-23 16:49:10 +0800582 * single-pressure device.
Dennis Kempina9963ba2012-06-08 10:32:23 -0700583 */
584 EventStatePtr evstate = device->evstate;
585
586 for (int i = 0; i < evstate->slot_count; i++) {
587 MtSlotPtr slot = &evstate->slots[i];
588 slot->pressure = ev->value;
589 }
590}
591
592static void
593Event_Abs(EvdevPtr device, struct input_event* ev)
594{
595 if (ev->code == ABS_MT_SLOT)
596 MT_Slot_Set(device, ev->value);
597 else if (IS_ABS_MT(ev->code))
598 Event_Abs_MT(device, ev);
Chung-yih Wang8b2fa0a2012-07-23 16:49:10 +0800599 else if ((ev->code == ABS_PRESSURE) && EvdevIsSinglePressureDevice(device))
600 Event_Abs_Update_Pressure(device, ev);
Dennis Kempina9963ba2012-06-08 10:32:23 -0700601}
602
603static void
604Event_Abs_MT(EvdevPtr device, struct input_event* ev)
605{
606 EventStatePtr evstate = device->evstate;
607 struct input_absinfo* axis = evstate->mt_axes[MT_CODE(ev->code)];
608 MtSlotPtr slot = evstate->slot_current;
609
610 if (axis == NULL) {
Dennis Kempin85a14442012-06-25 11:24:59 -0700611 LOG_WARNING(device, "ABS_MT[%02x] was not reported by this device\n",
Dennis Kempina9963ba2012-06-08 10:32:23 -0700612 ev->code);
613 return;
614 }
615
616 /* Warn about out of range data, but don't ignore */
617 if ((ev->code != ABS_MT_TRACKING_ID)
618 && ((ev->value < axis->minimum)
619 || (ev->value > axis->maximum))) {
620 LOG_WARNING(device, "ABS_MT[%02x] = %d : value out of range [%d .. %d]\n",
621 ev->code, ev->value, axis->minimum, axis->maximum);
622 }
623
624 if (slot == NULL) {
Dennis Kempin85a14442012-06-25 11:24:59 -0700625 LOG_WARNING(device, "MT slot not set. Ignoring ABS_MT event\n");
Dennis Kempina9963ba2012-06-08 10:32:23 -0700626 return;
627 }
628
629 MT_Slot_Value_Set(slot, ev->code, ev->value);
630}
Che-Liang Chiouf616b122012-10-24 17:08:51 -0700631
632static void
633Event_Rel(EvdevPtr device, struct input_event* ev)
634{
635 EventStatePtr evstate = device->evstate;
636
637 switch (ev->code) {
638 case REL_X:
639 evstate->rel_x = ev->value;
640 break;
641 case REL_Y:
642 evstate->rel_y = ev->value;
643 break;
644 case REL_WHEEL:
645 evstate->rel_wheel = ev->value;
646 break;
647 case REL_HWHEEL:
648 evstate->rel_hwheel = ev->value;
649 break;
650 }
651}