Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 7 | #include "libevdev_event.h" |
| 8 | |
| 9 | #include <errno.h> |
| 10 | #include <linux/input.h> |
| 11 | #include <stdbool.h> |
| 12 | #include <time.h> |
| 13 | |
| 14 | #include "libevdev.h" |
| 15 | #include "libevdev_util.h" |
| 16 | |
| 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 | |
| 35 | |
| 36 | |
| 37 | static void Event_Syn(EvdevPtr, struct input_event*); |
| 38 | static void Event_Syn_Report(EvdevPtr, struct input_event*); |
| 39 | static void Event_Syn_MT_Report(EvdevPtr, struct input_event*); |
| 40 | |
| 41 | static void Event_Key(EvdevPtr, struct input_event*); |
| 42 | |
| 43 | static void Event_Abs(EvdevPtr, struct input_event*); |
| 44 | static void Event_Abs_MT(EvdevPtr, struct input_event*); |
| 45 | static void SemiMtSetAbsPressure(EvdevPtr, struct input_event*); |
| 46 | |
| 47 | static void Event_Get_Time(struct timeval*, bool); |
| 48 | |
| 49 | /** |
| 50 | * Input Device Event Property accessors |
| 51 | */ |
| 52 | int |
| 53 | Event_Get_Left(EvdevPtr device) |
| 54 | { |
| 55 | struct input_absinfo* absinfo = &device->info.absinfo[ABS_X]; |
| 56 | return absinfo->minimum; |
| 57 | } |
| 58 | |
| 59 | int |
| 60 | Event_Get_Right(EvdevPtr device) |
| 61 | { |
| 62 | struct input_absinfo* absinfo = &device->info.absinfo[ABS_X]; |
| 63 | return absinfo->maximum; |
| 64 | } |
| 65 | |
| 66 | int |
| 67 | Event_Get_Top(EvdevPtr device) |
| 68 | { |
| 69 | struct input_absinfo* absinfo = &device->info.absinfo[ABS_Y]; |
| 70 | return absinfo->minimum; |
| 71 | } |
| 72 | |
| 73 | int |
| 74 | Event_Get_Bottom(EvdevPtr device) |
| 75 | { |
| 76 | struct input_absinfo* absinfo = &device->info.absinfo[ABS_Y]; |
| 77 | return absinfo->maximum; |
| 78 | } |
| 79 | |
| 80 | int |
| 81 | Event_Get_Res_Y(EvdevPtr device) |
| 82 | { |
| 83 | struct input_absinfo* absinfo = &device->info.absinfo[ABS_Y]; |
| 84 | return absinfo->resolution; |
| 85 | } |
| 86 | |
| 87 | int |
| 88 | Event_Get_Res_X(EvdevPtr device) |
| 89 | { |
| 90 | struct input_absinfo* absinfo = &device->info.absinfo[ABS_X]; |
| 91 | return absinfo->resolution; |
| 92 | } |
| 93 | |
| 94 | int |
| 95 | Event_Get_Button_Pad(EvdevPtr device) |
| 96 | { |
| 97 | return TestBit(INPUT_PROP_BUTTONPAD, device->info.prop_bitmask); |
| 98 | } |
| 99 | |
| 100 | int |
| 101 | Event_Get_Semi_MT(EvdevPtr device) |
| 102 | { |
| 103 | return TestBit(INPUT_PROP_SEMI_MT, device->info.prop_bitmask); |
| 104 | } |
| 105 | |
| 106 | int |
| 107 | Event_Get_T5R2(EvdevPtr device) |
| 108 | { |
| 109 | EventStatePtr evstate = device->evstate; |
| 110 | if (Event_Get_Semi_MT(device)) |
| 111 | return 0; |
| 112 | return (Event_Get_Touch_Count_Max(device) > evstate->slot_count); |
| 113 | } |
| 114 | |
| 115 | int |
| 116 | Event_Get_Touch_Count_Max(EvdevPtr device) |
| 117 | { |
| 118 | |
| 119 | if (TestBit(BTN_TOOL_QUINTTAP, device->info.key_bitmask)) |
| 120 | return 5; |
| 121 | if (TestBit(BTN_TOOL_QUADTAP, device->info.key_bitmask)) |
| 122 | return 4; |
| 123 | if (TestBit(BTN_TOOL_TRIPLETAP, device->info.key_bitmask)) |
| 124 | return 3; |
| 125 | if (TestBit(BTN_TOOL_DOUBLETAP, device->info.key_bitmask)) |
| 126 | return 2; |
| 127 | return 1; |
| 128 | } |
| 129 | |
| 130 | int |
| 131 | Event_Get_Touch_Count(EvdevPtr device) |
| 132 | { |
| 133 | |
| 134 | if (TestBit(BTN_TOOL_QUINTTAP, device->key_state_bitmask)) |
| 135 | return 5; |
| 136 | if (TestBit(BTN_TOOL_QUADTAP, device->key_state_bitmask)) |
| 137 | return 4; |
| 138 | if (TestBit(BTN_TOOL_TRIPLETAP, device->key_state_bitmask)) |
| 139 | return 3; |
| 140 | if (TestBit(BTN_TOOL_DOUBLETAP, device->key_state_bitmask)) |
| 141 | return 2; |
| 142 | if (TestBit(BTN_TOOL_FINGER, device->key_state_bitmask)) |
| 143 | return 1; |
| 144 | return 0; |
| 145 | } |
| 146 | |
| 147 | int |
| 148 | Event_Get_Slot_Count(EvdevPtr device) |
| 149 | { |
| 150 | EventStatePtr evstate = device->evstate; |
| 151 | return evstate->slot_count; |
| 152 | } |
| 153 | |
| 154 | int |
| 155 | Event_Get_Button_Left(EvdevPtr device) |
| 156 | { |
| 157 | return TestBit(BTN_LEFT, device->key_state_bitmask); |
| 158 | } |
| 159 | |
| 160 | int |
| 161 | Event_Get_Button_Middle(EvdevPtr device) |
| 162 | { |
| 163 | return TestBit(BTN_MIDDLE, device->key_state_bitmask); |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | Event_Get_Button_Right(EvdevPtr device) |
| 168 | { |
| 169 | return TestBit(BTN_RIGHT, device->key_state_bitmask); |
| 170 | } |
| 171 | |
| 172 | #define CASE_RETURN(s) \ |
| 173 | case (s):\ |
| 174 | return #s |
| 175 | |
| 176 | |
| 177 | const char * |
| 178 | Event_To_String(int type, int code) { |
| 179 | switch (type) { |
| 180 | case EV_SYN: |
| 181 | switch (code) { |
| 182 | CASE_RETURN(SYN_REPORT); |
| 183 | CASE_RETURN(SYN_MT_REPORT); |
| 184 | default: |
| 185 | break; |
| 186 | } |
| 187 | break; |
| 188 | case EV_ABS: |
| 189 | switch (code) { |
| 190 | CASE_RETURN(ABS_X); |
| 191 | CASE_RETURN(ABS_Y); |
| 192 | CASE_RETURN(ABS_Z); |
| 193 | CASE_RETURN(ABS_PRESSURE); |
| 194 | CASE_RETURN(ABS_TOOL_WIDTH); |
| 195 | CASE_RETURN(ABS_MT_TOUCH_MAJOR); |
| 196 | CASE_RETURN(ABS_MT_TOUCH_MINOR); |
| 197 | CASE_RETURN(ABS_MT_WIDTH_MAJOR); |
| 198 | CASE_RETURN(ABS_MT_WIDTH_MINOR); |
| 199 | CASE_RETURN(ABS_MT_ORIENTATION); |
| 200 | CASE_RETURN(ABS_MT_POSITION_X); |
| 201 | CASE_RETURN(ABS_MT_POSITION_Y); |
| 202 | CASE_RETURN(ABS_MT_TOOL_TYPE); |
| 203 | CASE_RETURN(ABS_MT_BLOB_ID); |
| 204 | CASE_RETURN(ABS_MT_TRACKING_ID); |
| 205 | CASE_RETURN(ABS_MT_PRESSURE); |
| 206 | CASE_RETURN(ABS_MT_SLOT); |
| 207 | default: |
| 208 | break; |
| 209 | } |
| 210 | break; |
| 211 | case EV_KEY: |
| 212 | switch (code) { |
| 213 | CASE_RETURN(BTN_LEFT); |
| 214 | CASE_RETURN(BTN_RIGHT); |
| 215 | CASE_RETURN(BTN_MIDDLE); |
| 216 | CASE_RETURN(BTN_TOUCH); |
| 217 | CASE_RETURN(BTN_TOOL_FINGER); |
| 218 | CASE_RETURN(BTN_TOOL_DOUBLETAP); |
| 219 | CASE_RETURN(BTN_TOOL_TRIPLETAP); |
| 220 | CASE_RETURN(BTN_TOOL_QUADTAP); |
| 221 | CASE_RETURN(BTN_TOOL_QUINTTAP); |
| 222 | default: |
| 223 | break; |
| 224 | } |
| 225 | break; |
| 226 | default: |
| 227 | break; |
| 228 | } |
| 229 | return "?"; |
| 230 | } |
| 231 | #undef CASE_RETURN |
| 232 | |
| 233 | const char * |
| 234 | Event_Type_To_String(int type) { |
| 235 | switch (type) { |
| 236 | case EV_SYN: return "SYN"; |
| 237 | case EV_KEY: return "KEY"; |
| 238 | case EV_REL: return "REL"; |
| 239 | case EV_ABS: return "ABS"; |
| 240 | case EV_MSC: return "MSC"; |
| 241 | case EV_SW: return "SW"; |
| 242 | case EV_LED: return "LED"; |
| 243 | case EV_SND: return "SND"; |
| 244 | case EV_REP: return "REP"; |
| 245 | case EV_FF: return "FF"; |
| 246 | case EV_PWR: return "PWR"; |
| 247 | default: return "?"; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | |
| 252 | /** |
| 253 | * Probe Device Input Event Support |
| 254 | */ |
| 255 | int |
| 256 | Event_Init(EvdevPtr device) |
| 257 | { |
| 258 | int i; |
| 259 | EventStatePtr evstate; |
| 260 | |
| 261 | evstate = device->evstate; |
| 262 | if (EvdevProbe(device) != Success) { |
| 263 | return !Success; |
| 264 | } |
| 265 | |
| 266 | /* |
| 267 | * TODO(djkurtz): Solve the race condition between MT slot initialization |
| 268 | * from absinfo, and incoming/lost input events. |
| 269 | * Specifically, if kernel driver sends MT_SLOT event between absinfo |
| 270 | * probe and when we start listening for input events. |
| 271 | */ |
| 272 | |
| 273 | for (i = ABS_X; i <= ABS_MAX; i++) { |
| 274 | if (TestBit(i, device->info.abs_bitmask)) { |
| 275 | struct input_absinfo* absinfo = &device->info.absinfo[i]; |
| 276 | if (i == ABS_MT_SLOT) { |
| 277 | int rc; |
| 278 | rc = MTB_Init(device, absinfo->minimum, absinfo->maximum, |
| 279 | absinfo->value); |
| 280 | if (rc != Success) |
| 281 | return rc; |
| 282 | } else if (IS_ABS_MT(i)) { |
| 283 | evstate->mt_axes[MT_CODE(i)] = absinfo; |
| 284 | } |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /* Synchronize all MT slots with kernel evdev driver */ |
| 289 | Event_Sync_State(device); |
| 290 | return Success; |
| 291 | } |
| 292 | |
| 293 | void |
| 294 | Event_Free(EvdevPtr device) |
| 295 | { |
| 296 | MT_Free(device); |
| 297 | } |
| 298 | |
| 299 | void |
| 300 | Event_Open(EvdevPtr device) |
| 301 | { |
| 302 | /* Select monotonic input event timestamps, if supported by kernel */ |
| 303 | device->info.is_monotonic = (EvdevEnableMonotonic(device) == Success); |
| 304 | /* Reset the sync time variables */ |
| 305 | Event_Get_Time(&device->before_sync_time, device->info.is_monotonic); |
| 306 | Event_Get_Time(&device->after_sync_time, device->info.is_monotonic); |
| 307 | LOG_DEBUG(device, "Using %s input event time stamps\n", |
| 308 | device->info.is_monotonic ? "monotonic" : "realtime"); |
| 309 | } |
| 310 | |
| 311 | static void |
| 312 | Event_Get_Time(struct timeval *t, bool use_monotonic) { |
| 313 | struct timespec now; |
| 314 | clockid_t clockid = (use_monotonic) ? CLOCK_MONOTONIC : CLOCK_REALTIME; |
| 315 | |
| 316 | clock_gettime(clockid, &now); |
| 317 | t->tv_sec = now.tv_sec; |
| 318 | t->tv_usec = now.tv_nsec / 1000; |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Synchronize the current state with kernel evdev driver. For cmt, there are |
| 323 | * only four components required to be synced: current touch count, the MT |
| 324 | * slots information, current slot id and physical button states. However, as |
| 325 | * pressure readings are missing in ABS_MT_PRESSURE field of MT slots for |
| 326 | * semi_mt touchpad device (e.g. Cr48), we also need need to extract it with |
| 327 | * extra EVIOCGABS query. |
| 328 | */ |
| 329 | void |
| 330 | Event_Sync_State(EvdevPtr device) |
| 331 | { |
| 332 | int i; |
| 333 | |
| 334 | Event_Get_Time(&device->before_sync_time, device->info.is_monotonic); |
| 335 | |
| 336 | EvdevProbeKeyState(device); |
| 337 | |
| 338 | /* Get current pressure information for semi_mt device */ |
| 339 | if (Event_Get_Semi_MT(device)) { |
| 340 | if (EvdevProbeAbsinfo(device, ABS_PRESSURE) == Success) { |
| 341 | struct input_event ev; |
| 342 | ev.code = ABS_PRESSURE; |
| 343 | ev.value = device->info.absinfo[ABS_PRESSURE].value; |
| 344 | SemiMtSetAbsPressure(device, &ev); |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /* TODO(cywang): Sync all ABS_ states for completeness */ |
| 349 | |
| 350 | /* Get current MT information for each slot */ |
| 351 | for (i = _ABS_MT_FIRST; i <= _ABS_MT_LAST; i++) { |
| 352 | MTSlotInfo req; |
| 353 | |
| 354 | if (!TestBit(i, device->info.abs_bitmask)) |
| 355 | continue; |
| 356 | /* |
| 357 | * TODO(cywang): Scale the size of slots in MTSlotInfo based on the |
| 358 | * evstate->slot_count. |
| 359 | */ |
| 360 | |
| 361 | req.code = i; |
| 362 | if (EvdevProbeMTSlot(device, &req) != Success) { |
| 363 | continue; |
| 364 | } |
| 365 | MT_Slot_Sync(device, &req); |
| 366 | } |
| 367 | |
| 368 | /* Get current slot id */ |
| 369 | if (EvdevProbeAbsinfo(device, ABS_MT_SLOT) == Success) |
| 370 | MT_Slot_Set(device, device->info.absinfo[ABS_MT_SLOT].value); |
| 371 | |
| 372 | Event_Get_Time(&device->after_sync_time, device->info.is_monotonic); |
| 373 | |
| 374 | LOG_DEBUG(device, "Event_Sync_State: before %ld.%ld after %ld.%ld\n", |
| 375 | device->before_sync_time.tv_sec, device->before_sync_time.tv_usec, |
| 376 | device->after_sync_time.tv_sec, device->after_sync_time.tv_usec); |
| 377 | } |
| 378 | |
| 379 | static void |
| 380 | Event_Print(EvdevPtr device, struct input_event* ev) |
| 381 | { |
| 382 | switch (ev->type) { |
| 383 | case EV_SYN: |
| 384 | switch (ev->code) { |
| 385 | case SYN_REPORT: |
Dennis Kempin | de0712f | 2012-06-11 15:13:50 -0700 | [diff] [blame^] | 386 | LOG_DEBUG(device, "@ %ld.%06ld ---------- SYN_REPORT -------\n", |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 387 | ev->time.tv_sec, ev->time.tv_usec); |
| 388 | return; |
| 389 | case SYN_MT_REPORT: |
Dennis Kempin | de0712f | 2012-06-11 15:13:50 -0700 | [diff] [blame^] | 390 | LOG_DEBUG(device, "@ %ld.%06ld ........ SYN_MT_REPORT ......\n", |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 391 | ev->time.tv_sec, ev->time.tv_usec); |
| 392 | return; |
| 393 | case SYN_DROPPED: |
Dennis Kempin | de0712f | 2012-06-11 15:13:50 -0700 | [diff] [blame^] | 394 | LOG_DEBUG(device, "@ %ld.%06ld ++++++++ SYN_DROPPED ++++++++\n", |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 395 | ev->time.tv_sec, ev->time.tv_usec); |
| 396 | return; |
| 397 | default: |
Dennis Kempin | de0712f | 2012-06-11 15:13:50 -0700 | [diff] [blame^] | 398 | LOG_DEBUG(device, "@ %ld.%06ld ?????? SYN_UNKNOWN (%d) ?????\n", |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 399 | ev->time.tv_sec, ev->time.tv_usec, ev->code); |
| 400 | return; |
| 401 | } |
| 402 | break; |
| 403 | case EV_ABS: |
| 404 | if (ev->code == ABS_MT_SLOT) { |
Dennis Kempin | de0712f | 2012-06-11 15:13:50 -0700 | [diff] [blame^] | 405 | LOG_DEBUG(device, "@ %ld.%06ld .......... MT SLOT %d ........\n", |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 406 | ev->time.tv_sec, ev->time.tv_usec, ev->value); |
| 407 | return; |
| 408 | } |
| 409 | break; |
| 410 | default: |
| 411 | break; |
| 412 | } |
| 413 | |
Dennis Kempin | de0712f | 2012-06-11 15:13:50 -0700 | [diff] [blame^] | 414 | LOG_DEBUG(device, "@ %ld.%06ld %s[%d] (%s) = %d\n", |
Dennis Kempin | a9963ba | 2012-06-08 10:32:23 -0700 | [diff] [blame] | 415 | ev->time.tv_sec, ev->time.tv_usec, Event_Type_To_String(ev->type), |
| 416 | ev->code, Event_To_String(ev->type, ev->code), ev->value); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Process Input Events |
| 421 | */ |
| 422 | bool |
| 423 | Event_Process(EvdevPtr device, struct input_event* ev) |
| 424 | { |
| 425 | EventStatePtr evstate = device->evstate; |
| 426 | |
| 427 | Event_Print(device, ev); |
| 428 | if (evstate->debug_buf) { |
| 429 | evstate->debug_buf[evstate->debug_buf_tail] = *ev; |
| 430 | evstate->debug_buf_tail = |
| 431 | (evstate->debug_buf_tail + 1) % DEBUG_BUF_SIZE; |
| 432 | } |
| 433 | |
| 434 | switch (ev->type) { |
| 435 | case EV_SYN: |
| 436 | if (ev->code == SYN_DROPPED) |
| 437 | return true; |
| 438 | Event_Syn(device, ev); |
| 439 | break; |
| 440 | |
| 441 | case EV_KEY: |
| 442 | Event_Key(device, ev); |
| 443 | break; |
| 444 | |
| 445 | case EV_ABS: |
| 446 | Event_Abs(device, ev); |
| 447 | break; |
| 448 | |
| 449 | default: |
| 450 | break; |
| 451 | } |
| 452 | return false; |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Dump the log of input events to disk |
| 457 | */ |
| 458 | void |
| 459 | Event_Dump_Debug_Log(void* vinfo) |
| 460 | { |
| 461 | EvdevPtr device = (EvdevPtr) vinfo; |
| 462 | size_t i; |
| 463 | EventStatePtr evstate = device->evstate; |
| 464 | |
| 465 | FILE* fp = fopen("/var/log/cmt_input_events.dat", "wb"); |
| 466 | if (!fp) { |
| 467 | LOG_ERROR(device, "fopen() failed for debug log"); |
| 468 | return; |
| 469 | } |
| 470 | for (i = 0; i < DEBUG_BUF_SIZE; i++) { |
| 471 | size_t rc; |
| 472 | struct input_event *ev = |
| 473 | &evstate->debug_buf[(evstate->debug_buf_tail + i) % DEBUG_BUF_SIZE]; |
| 474 | if (ev->time.tv_sec == 0 && ev->time.tv_usec == 0) |
| 475 | continue; |
| 476 | rc = fprintf(fp, "E: %ld.%06ld %04x %04x %d\n", |
| 477 | ev->time.tv_sec, |
| 478 | ev->time.tv_usec, |
| 479 | ev->type, |
| 480 | ev->code, |
| 481 | ev->value); |
| 482 | if (rc == 0) { |
| 483 | LOG_ERROR(device, "fprintf() failed for debug log. Log is short"); |
| 484 | break; |
| 485 | } |
| 486 | } |
| 487 | fclose(fp); |
| 488 | } |
| 489 | |
| 490 | static void |
| 491 | Event_Syn(EvdevPtr device, struct input_event* ev) |
| 492 | { |
| 493 | switch (ev->code) { |
| 494 | case SYN_REPORT: |
| 495 | Event_Syn_Report(device, ev); |
| 496 | break; |
| 497 | case SYN_MT_REPORT: |
| 498 | Event_Syn_MT_Report(device, ev); |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | |
| 503 | static void |
| 504 | Event_Syn_Report(EvdevPtr device, struct input_event* ev) |
| 505 | { |
| 506 | EventStatePtr evstate = device->evstate; |
| 507 | device->syn_report(device->syn_report_udata, evstate, &ev->time); |
| 508 | |
| 509 | MT_Print_Slots(device); |
| 510 | } |
| 511 | |
| 512 | static void |
| 513 | Event_Syn_MT_Report(EvdevPtr device, struct input_event* ev) |
| 514 | { |
| 515 | /* TODO(djkurtz): Handle MT-A */ |
| 516 | } |
| 517 | |
| 518 | static void |
| 519 | Event_Key(EvdevPtr device, struct input_event* ev) |
| 520 | { |
| 521 | AssignBit(device->key_state_bitmask, ev->code, ev->value); |
| 522 | } |
| 523 | |
| 524 | static void |
| 525 | SemiMtSetAbsPressure(EvdevPtr device, struct input_event* ev) |
| 526 | { |
| 527 | /* |
| 528 | * Update all active slots with the same ABS_PRESSURE value if it is a |
| 529 | * semi-mt device. |
| 530 | */ |
| 531 | EventStatePtr evstate = device->evstate; |
| 532 | |
| 533 | for (int i = 0; i < evstate->slot_count; i++) { |
| 534 | MtSlotPtr slot = &evstate->slots[i]; |
| 535 | slot->pressure = ev->value; |
| 536 | } |
| 537 | } |
| 538 | |
| 539 | static void |
| 540 | Event_Abs(EvdevPtr device, struct input_event* ev) |
| 541 | { |
| 542 | if (ev->code == ABS_MT_SLOT) |
| 543 | MT_Slot_Set(device, ev->value); |
| 544 | else if (IS_ABS_MT(ev->code)) |
| 545 | Event_Abs_MT(device, ev); |
| 546 | else if ((ev->code == ABS_PRESSURE) && Event_Get_Semi_MT(device)) |
| 547 | SemiMtSetAbsPressure(device, ev); |
| 548 | } |
| 549 | |
| 550 | static void |
| 551 | Event_Abs_MT(EvdevPtr device, struct input_event* ev) |
| 552 | { |
| 553 | EventStatePtr evstate = device->evstate; |
| 554 | struct input_absinfo* axis = evstate->mt_axes[MT_CODE(ev->code)]; |
| 555 | MtSlotPtr slot = evstate->slot_current; |
| 556 | |
| 557 | if (axis == NULL) { |
| 558 | LOG_ERROR(device, "ABS_MT[%02x] was not reported by this device\n", |
| 559 | ev->code); |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | /* Warn about out of range data, but don't ignore */ |
| 564 | if ((ev->code != ABS_MT_TRACKING_ID) |
| 565 | && ((ev->value < axis->minimum) |
| 566 | || (ev->value > axis->maximum))) { |
| 567 | LOG_WARNING(device, "ABS_MT[%02x] = %d : value out of range [%d .. %d]\n", |
| 568 | ev->code, ev->value, axis->minimum, axis->maximum); |
| 569 | } |
| 570 | |
| 571 | if (slot == NULL) { |
| 572 | LOG_ERROR(device, "MT slot not set. Ignoring ABS_MT event\n"); |
| 573 | return; |
| 574 | } |
| 575 | |
| 576 | MT_Slot_Value_Set(slot, ev->code, ev->value); |
| 577 | } |