blob: 73369a2ccc029c17fd773b36d02f8f259a6b537c [file] [log] [blame]
Dees_Troy51a0e822012-09-05 15:24:24 -04001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <fcntl.h>
20#include <dirent.h>
21#include <sys/poll.h>
22#include <limits.h>
23
24#include <linux/input.h>
25
26#include "../common.h"
27
28#include "minui.h"
29
30//#define _EVENT_LOGGING
31
Dees_Troy3f23d9e2013-05-03 21:04:05 +000032#define MAX_DEVICES 32
Dees_Troy51a0e822012-09-05 15:24:24 -040033
34#define VIBRATOR_TIMEOUT_FILE "/sys/class/timed_output/vibrator/enable"
35#define VIBRATOR_TIME_MS 50
36
Dees_Troyf7596752012-09-28 13:21:36 -040037#ifndef SYN_REPORT
Dees_Troy51a0e822012-09-05 15:24:24 -040038#define SYN_REPORT 0x00
Dees_Troyf7596752012-09-28 13:21:36 -040039#endif
40#ifndef SYN_CONFIG
Dees_Troy51a0e822012-09-05 15:24:24 -040041#define SYN_CONFIG 0x01
Dees_Troyf7596752012-09-28 13:21:36 -040042#endif
43#ifndef SYN_MT_REPORT
Dees_Troy51a0e822012-09-05 15:24:24 -040044#define SYN_MT_REPORT 0x02
Dees_Troyf7596752012-09-28 13:21:36 -040045#endif
Dees_Troy51a0e822012-09-05 15:24:24 -040046
47#define ABS_MT_POSITION 0x2a /* Group a set of X and Y */
48#define ABS_MT_AMPLITUDE 0x2b /* Group a set of Z and W */
49#define ABS_MT_SLOT 0x2f
50#define ABS_MT_TOUCH_MAJOR 0x30
51#define ABS_MT_TOUCH_MINOR 0x31
52#define ABS_MT_WIDTH_MAJOR 0x32
53#define ABS_MT_WIDTH_MINOR 0x33
54#define ABS_MT_ORIENTATION 0x34
55#define ABS_MT_POSITION_X 0x35
56#define ABS_MT_POSITION_Y 0x36
57#define ABS_MT_TOOL_TYPE 0x37
58#define ABS_MT_BLOB_ID 0x38
59#define ABS_MT_TRACKING_ID 0x39
60#define ABS_MT_PRESSURE 0x3a
61#define ABS_MT_DISTANCE 0x3b
62
63enum {
64 DOWN_NOT,
65 DOWN_SENT,
66 DOWN_RELEASED,
67};
68
69struct virtualkey {
70 int scancode;
71 int centerx, centery;
72 int width, height;
73};
74
75struct position {
76 int x, y;
77 int synced;
78 struct input_absinfo xi, yi;
79};
80
81struct ev {
82 struct pollfd *fd;
83
84 struct virtualkey *vks;
85 int vk_count;
86
87 char deviceName[64];
88
89 int ignored;
90
91 struct position p, mt_p;
92 int down;
93};
94
95static struct pollfd ev_fds[MAX_DEVICES];
96static struct ev evs[MAX_DEVICES];
97static unsigned ev_count = 0;
98
99static inline int ABS(int x) {
100 return x<0?-x:x;
101}
102
103int vibrate(int timeout_ms)
104{
105 char str[20];
106 int fd;
107 int ret;
108
109 fd = open(VIBRATOR_TIMEOUT_FILE, O_WRONLY);
110 if (fd < 0)
111 return -1;
112
113 ret = snprintf(str, sizeof(str), "%d", timeout_ms);
114 ret = write(fd, str, ret);
115 close(fd);
116
117 if (ret < 0)
118 return -1;
119
120 return 0;
121}
122
123/* Returns empty tokens */
124static char *vk_strtok_r(char *str, const char *delim, char **save_str)
125{
126 if(!str)
127 {
128 if(!*save_str)
129 return NULL;
130
131 str = (*save_str) + 1;
132 }
133 *save_str = strpbrk(str, delim);
134
135 if (*save_str)
136 **save_str = '\0';
137
138 return str;
139}
140
141static int vk_init(struct ev *e)
142{
143 char vk_path[PATH_MAX] = "/sys/board_properties/virtualkeys.";
144 char vks[2048], *ts = NULL;
145 ssize_t len;
146 int vk_fd;
147 int i;
148
149 e->vk_count = 0;
150
151 len = strlen(vk_path);
152 len = ioctl(e->fd->fd, EVIOCGNAME(sizeof(e->deviceName)), e->deviceName);
153 if (len <= 0)
154 {
Dees_Troy2673cec2013-04-02 20:22:16 +0000155 printf("Unable to query event object.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400156 return -1;
157 }
158#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000159 printf("Event object: %s\n", e->deviceName);
Dees_Troy51a0e822012-09-05 15:24:24 -0400160#endif
161
162 // Blacklist these "input" devices
Dees_Troy07a3a742012-12-11 15:13:21 +0000163 if (strcmp(e->deviceName, "bma250") == 0 || strcmp(e->deviceName, "bma150") == 0)
Dees_Troy51a0e822012-09-05 15:24:24 -0400164 {
165 e->ignored = 1;
166 }
167
168 strcat(vk_path, e->deviceName);
169
170 // Some devices split the keys from the touchscreen
171 e->vk_count = 0;
172 vk_fd = open(vk_path, O_RDONLY);
173 if (vk_fd >= 0)
174 {
175 len = read(vk_fd, vks, sizeof(vks)-1);
176 close(vk_fd);
177 if (len <= 0)
178 return -1;
179
180 vks[len] = '\0';
181
182 /* Parse a line like:
183 keytype:keycode:centerx:centery:width:height:keytype2:keycode2:centerx2:...
184 */
185 for (ts = vks, e->vk_count = 1; *ts; ++ts) {
186 if (*ts == ':')
187 ++e->vk_count;
188 }
189
190 if (e->vk_count % 6) {
Dees_Troy2673cec2013-04-02 20:22:16 +0000191 printf("minui: %s is %d %% 6\n", vk_path, e->vk_count % 6);
Dees_Troy51a0e822012-09-05 15:24:24 -0400192 }
193 e->vk_count /= 6;
194 if (e->vk_count <= 0)
195 return -1;
196
197 e->down = DOWN_NOT;
198 }
199
200 ioctl(e->fd->fd, EVIOCGABS(ABS_X), &e->p.xi);
201 ioctl(e->fd->fd, EVIOCGABS(ABS_Y), &e->p.yi);
202 e->p.synced = 0;
203#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000204 printf("EV: ST minX: %d maxX: %d minY: %d maxY: %d\n", e->p.xi.minimum, e->p.xi.maximum, e->p.yi.minimum, e->p.yi.maximum);
Dees_Troy51a0e822012-09-05 15:24:24 -0400205#endif
206
207 ioctl(e->fd->fd, EVIOCGABS(ABS_MT_POSITION_X), &e->mt_p.xi);
208 ioctl(e->fd->fd, EVIOCGABS(ABS_MT_POSITION_Y), &e->mt_p.yi);
209 e->mt_p.synced = 0;
210#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000211 printf("EV: MT minX: %d maxX: %d minY: %d maxY: %d\n", e->mt_p.xi.minimum, e->mt_p.xi.maximum, e->mt_p.yi.minimum, e->mt_p.yi.maximum);
Dees_Troy51a0e822012-09-05 15:24:24 -0400212#endif
213
214 e->vks = malloc(sizeof(*e->vks) * e->vk_count);
215
216 for (i = 0; i < e->vk_count; ++i) {
217 char *token[6];
218 int j;
219
220 for (j = 0; j < 6; ++j) {
221 token[j] = vk_strtok_r((i||j)?NULL:vks, ":", &ts);
222 }
223
224 if (strcmp(token[0], "0x01") != 0) {
225 /* Java does string compare, so we do too. */
Dees_Troy2673cec2013-04-02 20:22:16 +0000226 printf("minui: %s: ignoring unknown virtual key type %s\n", vk_path, token[0]);
Dees_Troy51a0e822012-09-05 15:24:24 -0400227 continue;
228 }
229
230 e->vks[i].scancode = strtol(token[1], NULL, 0);
231 e->vks[i].centerx = strtol(token[2], NULL, 0);
232 e->vks[i].centery = strtol(token[3], NULL, 0);
233 e->vks[i].width = strtol(token[4], NULL, 0);
234 e->vks[i].height = strtol(token[5], NULL, 0);
235 }
236
237 return 0;
238}
239
240int ev_init(void)
241{
242 DIR *dir;
243 struct dirent *de;
244 int fd;
245
246 dir = opendir("/dev/input");
247 if(dir != 0) {
248 while((de = readdir(dir))) {
249// fprintf(stderr,"/dev/input/%s\n", de->d_name);
250 if(strncmp(de->d_name,"event",5)) continue;
251 fd = openat(dirfd(dir), de->d_name, O_RDONLY);
252 if(fd < 0) continue;
253
254 ev_fds[ev_count].fd = fd;
255 ev_fds[ev_count].events = POLLIN;
256 evs[ev_count].fd = &ev_fds[ev_count];
257
258 /* Load virtualkeys if there are any */
259 vk_init(&evs[ev_count]);
260
261 ev_count++;
262 if(ev_count == MAX_DEVICES) break;
263 }
264 }
265
266 return 0;
267}
268
269void ev_exit(void)
270{
271 while (ev_count-- > 0) {
272 if (evs[ev_count].vk_count) {
273 free(evs[ev_count].vks);
274 evs[ev_count].vk_count = 0;
275 }
276 close(ev_fds[ev_count].fd);
277 }
278}
279
280static int vk_inside_display(__s32 value, struct input_absinfo *info, int screen_size)
281{
282 int screen_pos;
283
284 if (info->minimum == info->maximum)
285 return 0;
286
287 screen_pos = (value - info->minimum) * (screen_size - 1) / (info->maximum - info->minimum);
288 return (screen_pos >= 0 && screen_pos < screen_size);
289}
290
Dees_Troyb7ecc092013-08-24 12:15:41 +0000291static int vk_tp_to_screen(struct position *p, int *x, int *y)
Dees_Troy51a0e822012-09-05 15:24:24 -0400292{
293 if (p->xi.minimum == p->xi.maximum || p->yi.minimum == p->yi.maximum)
294 {
295 // In this case, we assume the screen dimensions are the same.
296 *x = p->x;
297 *y = p->y;
298 return 0;
299 }
300
Dees_Troyb7ecc092013-08-24 12:15:41 +0000301#ifdef _EVENT_LOGGING
302 printf("EV: p->x=%d x-range=%d,%d fb-width=%d\n", p->x, p->xi.minimum, p->xi.maximum, gr_fb_width());
303#endif
304
Dees_Troy51a0e822012-09-05 15:24:24 -0400305#ifndef RECOVERY_TOUCHSCREEN_SWAP_XY
Dees_Troyb7ecc092013-08-24 12:15:41 +0000306 int fb_width = gr_fb_width();
307 int fb_height = gr_fb_height();
Dees_Troy51a0e822012-09-05 15:24:24 -0400308#else
309 // We need to swap the scaling sizes, too
Dees_Troyb7ecc092013-08-24 12:15:41 +0000310 int fb_width = gr_fb_height();
311 int fb_height = gr_fb_width();
Dees_Troy51a0e822012-09-05 15:24:24 -0400312#endif
313
314 *x = (p->x - p->xi.minimum) * (fb_width - 1) / (p->xi.maximum - p->xi.minimum);
315 *y = (p->y - p->yi.minimum) * (fb_height - 1) / (p->yi.maximum - p->yi.minimum);
316
317 if (*x >= 0 && *x < fb_width &&
318 *y >= 0 && *y < fb_height)
319 {
320 return 0;
321 }
322
323 return 1;
324}
325
326/* Translate a virtual key in to a real key event, if needed */
327/* Returns non-zero when the event should be consumed */
Dees_Troyb7ecc092013-08-24 12:15:41 +0000328static int vk_modify(struct ev *e, struct input_event *ev)
Dees_Troy51a0e822012-09-05 15:24:24 -0400329{
330 static int downX = -1, downY = -1;
331 static int discard = 0;
332 static int lastWasSynReport = 0;
333 static int touchReleaseOnNextSynReport = 0;
Dees_Troyd86400b2013-05-13 19:04:35 +0000334 static int use_tracking_id_negative_as_touch_release = 0; // On some devices, type: 3 code: 39 value: -1, aka EV_ABS ABS_MT_TRACKING_ID -1 indicates a true touch release
Dees_Troy51a0e822012-09-05 15:24:24 -0400335 int i;
336 int x, y;
337
338 // This is used to ditch useless event handlers, like an accelerometer
339 if (e->ignored) return 1;
340
341 if (ev->type == EV_REL && ev->code == REL_Z)
342 {
343 // This appears to be an accelerometer or another strange input device. It's not the touchscreen.
344#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000345 printf("EV: Device disabled due to non-touchscreen messages.\n");
Dees_Troy51a0e822012-09-05 15:24:24 -0400346#endif
347 e->ignored = 1;
348 return 1;
349 }
350
351#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000352 printf("EV: %s => type: %x code: %x value: %d\n", e->deviceName, ev->type, ev->code, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400353#endif
354
355 // Handle keyboard events, value of 1 indicates key down, 0 indicates key up
356 if (ev->type == EV_KEY) {
357 return 0;
358 }
359
360 if (ev->type == EV_ABS) {
361 switch (ev->code) {
362
363 case ABS_X: //00
364 e->p.synced |= 0x01;
365 e->p.x = ev->value;
366#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000367 printf("EV: %s => EV_ABS ABS_X %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400368#endif
369 break;
370
371 case ABS_Y: //01
372 e->p.synced |= 0x02;
373 e->p.y = ev->value;
374#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000375 printf("EV: %s => EV_ABS ABS_Y %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400376#endif
377 break;
378
379 case ABS_MT_POSITION: //2a
380 e->mt_p.synced = 0x03;
381 if (ev->value == (1 << 31))
382 {
383 e->mt_p.x = 0;
384 e->mt_p.y = 0;
385 lastWasSynReport = 1;
386 }
387 else
388 {
389 lastWasSynReport = 0;
390 e->mt_p.x = (ev->value & 0x7FFF0000) >> 16;
391 e->mt_p.y = (ev->value & 0xFFFF);
392 }
393 break;
394
395 case ABS_MT_TOUCH_MAJOR: //30
396 if (ev->value == 0)
397 {
Ibrahim Awwal2e9cb012014-01-04 12:38:26 -0800398#ifndef TW_IGNORE_MAJOR_AXIS_0
Dees_Troy51a0e822012-09-05 15:24:24 -0400399 // We're in a touch release, although some devices will still send positions as well
400 e->mt_p.x = 0;
401 e->mt_p.y = 0;
402 touchReleaseOnNextSynReport = 1;
Ibrahim Awwal2e9cb012014-01-04 12:38:26 -0800403#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400404 }
405#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000406 printf("EV: %s => EV_ABS ABS_MT_TOUCH_MAJOR %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400407#endif
408 break;
409
410 case ABS_MT_PRESSURE: //3a
411 if (ev->value == 0)
412 {
413 // We're in a touch release, although some devices will still send positions as well
414 e->mt_p.x = 0;
415 e->mt_p.y = 0;
416 touchReleaseOnNextSynReport = 1;
417 }
418#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000419 printf("EV: %s => EV_ABS ABS_MT_PRESSURE %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400420#endif
421 break;
422
423 case ABS_MT_POSITION_X: //35
424 e->mt_p.synced |= 0x01;
425 e->mt_p.x = ev->value;
426#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000427 printf("EV: %s => EV_ABS ABS_MT_POSITION_X %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400428#endif
429 break;
430
431 case ABS_MT_POSITION_Y: //36
432 e->mt_p.synced |= 0x02;
433 e->mt_p.y = ev->value;
434#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000435 printf("EV: %s => EV_ABS ABS_MT_POSITION_Y %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400436#endif
437 break;
438
Dees_Troy51a0e822012-09-05 15:24:24 -0400439 case ABS_MT_TOUCH_MINOR: //31
Dees_Troyd86400b2013-05-13 19:04:35 +0000440#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000441 printf("EV: %s => EV_ABS ABS_MT_TOUCH_MINOR %d\n", e->deviceName, ev->value);
Dees_Troyd86400b2013-05-13 19:04:35 +0000442#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400443 break;
444
445 case ABS_MT_WIDTH_MAJOR: //32
Dees_Troyd86400b2013-05-13 19:04:35 +0000446#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000447 printf("EV: %s => EV_ABS ABS_MT_WIDTH_MAJOR %d\n", e->deviceName, ev->value);
Dees_Troyd86400b2013-05-13 19:04:35 +0000448#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400449 break;
450
451 case ABS_MT_WIDTH_MINOR: //33
Dees_Troyd86400b2013-05-13 19:04:35 +0000452#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000453 printf("EV: %s => EV_ABS ABS_MT_WIDTH_MINOR %d\n", e->deviceName, ev->value);
Dees_Troyd86400b2013-05-13 19:04:35 +0000454#endif
Dees_Troy51a0e822012-09-05 15:24:24 -0400455 break;
456
Dees_Troyd86400b2013-05-13 19:04:35 +0000457 case ABS_MT_TRACKING_ID: //39
458 if (ev->value < 0) {
459 e->mt_p.x = 0;
460 e->mt_p.y = 0;
461 touchReleaseOnNextSynReport = 2;
462 use_tracking_id_negative_as_touch_release = 1;
463#ifdef _EVENT_LOGGING
464 if (use_tracking_id_negative_as_touch_release)
465 printf("using ABS_MT_TRACKING_ID value -1 to indicate touch releases\n");
466#endif
467 }
468#ifdef _EVENT_LOGGING
469 printf("EV: %s => EV_ABS ABS_MT_TRACKING_ID %d\n", e->deviceName, ev->value);
470#endif
471 break;
472
473#ifdef _EVENT_LOGGING
474 // These are for touch logging purposes only
Dees_Troy51a0e822012-09-05 15:24:24 -0400475 case ABS_MT_ORIENTATION: //34
Dees_Troy2673cec2013-04-02 20:22:16 +0000476 printf("EV: %s => EV_ABS ABS_MT_ORIENTATION %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400477 return 1;
478 break;
479
480 case ABS_MT_TOOL_TYPE: //37
481 LOGI("EV: %s => EV_ABS ABS_MT_TOOL_TYPE %d\n", e->deviceName, ev->value);
482 return 1;
483 break;
484
485 case ABS_MT_BLOB_ID: //38
Dees_Troy2673cec2013-04-02 20:22:16 +0000486 printf("EV: %s => EV_ABS ABS_MT_BLOB_ID %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400487 return 1;
488 break;
489
Dees_Troy51a0e822012-09-05 15:24:24 -0400490 case ABS_MT_DISTANCE: //3b
Dees_Troy2673cec2013-04-02 20:22:16 +0000491 printf("EV: %s => EV_ABS ABS_MT_DISTANCE %d\n", e->deviceName, ev->value);
Dees_Troy51a0e822012-09-05 15:24:24 -0400492 return 1;
493 break;
494#endif
495
496 default:
497 // This is an unhandled message, just skip it
498 return 1;
499 }
500
501 if (ev->code != ABS_MT_POSITION)
502 {
503 lastWasSynReport = 0;
504 return 1;
505 }
506 }
507
508 // Check if we should ignore the message
509 if (ev->code != ABS_MT_POSITION && (ev->type != EV_SYN || (ev->code != SYN_REPORT && ev->code != SYN_MT_REPORT)))
510 {
511 lastWasSynReport = 0;
512 return 0;
513 }
514
515#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000516 if (ev->type == EV_SYN && ev->code == SYN_REPORT) printf("EV: %s => EV_SYN SYN_REPORT\n", e->deviceName);
517 if (ev->type == EV_SYN && ev->code == SYN_MT_REPORT) printf("EV: %s => EV_SYN SYN_MT_REPORT\n", e->deviceName);
Dees_Troy51a0e822012-09-05 15:24:24 -0400518#endif
519
520 // Discard the MT versions
521 if (ev->code == SYN_MT_REPORT) return 0;
522
Dees_Troyd86400b2013-05-13 19:04:35 +0000523 if (((lastWasSynReport == 1 || touchReleaseOnNextSynReport == 1) && !use_tracking_id_negative_as_touch_release) || (use_tracking_id_negative_as_touch_release && touchReleaseOnNextSynReport == 2))
Dees_Troy51a0e822012-09-05 15:24:24 -0400524 {
525 // Reset the value
526 touchReleaseOnNextSynReport = 0;
527
528 // We are a finger-up state
529 if (!discard)
530 {
531 // Report the key up
532 ev->type = EV_ABS;
533 ev->code = 0;
534 ev->value = (downX << 16) | downY;
535 }
536 downX = -1;
537 downY = -1;
538 if (discard)
539 {
540 discard = 0;
541 return 1;
542 }
543 return 0;
544 }
545 lastWasSynReport = 1;
546
547 // Retrieve where the x,y position is
548 if (e->p.synced & 0x03)
549 {
Dees_Troyb7ecc092013-08-24 12:15:41 +0000550 vk_tp_to_screen(&e->p, &x, &y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400551 }
552 else if (e->mt_p.synced & 0x03)
553 {
Dees_Troyb7ecc092013-08-24 12:15:41 +0000554 vk_tp_to_screen(&e->mt_p, &x, &y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400555 }
556 else
557 {
558 // We don't have useful information to convey
559 return 1;
560 }
561
562#ifdef RECOVERY_TOUCHSCREEN_SWAP_XY
563 x ^= y;
564 y ^= x;
565 x ^= y;
566#endif
567#ifdef RECOVERY_TOUCHSCREEN_FLIP_X
Dees_Troyb7ecc092013-08-24 12:15:41 +0000568 x = gr_fb_width() - x;
Dees_Troy51a0e822012-09-05 15:24:24 -0400569#endif
570#ifdef RECOVERY_TOUCHSCREEN_FLIP_Y
Dees_Troyb7ecc092013-08-24 12:15:41 +0000571 y = gr_fb_height() - y;
Dees_Troy51a0e822012-09-05 15:24:24 -0400572#endif
573
574#ifdef _EVENT_LOGGING
Dees_Troy2673cec2013-04-02 20:22:16 +0000575 printf("EV: x: %d y: %d\n", x, y);
Dees_Troy51a0e822012-09-05 15:24:24 -0400576#endif
577
578 // Clear the current sync states
579 e->p.synced = e->mt_p.synced = 0;
580
581 // If we have nothing useful to report, skip it
582 if (x == -1 || y == -1) return 1;
583
584 // On first touch, see if we're at a virtual key
585 if (downX == -1)
586 {
587 // Attempt mapping to virtual key
588 for (i = 0; i < e->vk_count; ++i)
589 {
590 int xd = ABS(e->vks[i].centerx - x);
591 int yd = ABS(e->vks[i].centery - y);
592
593 if (xd < e->vks[i].width/2 && yd < e->vks[i].height/2)
594 {
595 ev->type = EV_KEY;
596 ev->code = e->vks[i].scancode;
597 ev->value = 1;
598
599 vibrate(VIBRATOR_TIME_MS);
600
601 // Mark that all further movement until lift is discard,
602 // and make sure we don't come back into this area
603 discard = 1;
604 downX = 0;
605 return 0;
606 }
607 }
608 }
609
610 // If we were originally a button press, discard this event
611 if (discard)
612 {
613 return 1;
614 }
615
616 // Record where we started the touch for deciding if this is a key or a scroll
617 downX = x;
618 downY = y;
619
620 ev->type = EV_ABS;
621 ev->code = 1;
622 ev->value = (x << 16) | y;
623 return 0;
624}
625
Dees_Troyb7ecc092013-08-24 12:15:41 +0000626int ev_get(struct input_event *ev, unsigned dont_wait)
Dees_Troy51a0e822012-09-05 15:24:24 -0400627{
628 int r;
629 unsigned n;
630
631 do {
632 r = poll(ev_fds, ev_count, dont_wait ? 0 : -1);
633
634 if(r > 0) {
635 for(n = 0; n < ev_count; n++) {
636 if(ev_fds[n].revents & POLLIN) {
637 r = read(ev_fds[n].fd, ev, sizeof(*ev));
638 if(r == sizeof(*ev)) {
Dees_Troyb7ecc092013-08-24 12:15:41 +0000639 if (!vk_modify(&evs[n], ev))
Dees_Troy51a0e822012-09-05 15:24:24 -0400640 return 0;
641 }
642 }
643 }
644 }
645 } while(dont_wait == 0);
646
647 return -1;
648}
649
650int ev_wait(int timeout)
651{
652 return -1;
653}
654
655void ev_dispatch(void)
656{
657 return;
658}
659
660int ev_get_input(int fd, short revents, struct input_event *ev)
661{
662 return -1;
663}