Skip to content

Commit

Permalink
ts_uinput: input device check
Browse files Browse the repository at this point in the history
  • Loading branch information
merge committed Jan 17, 2017
1 parent 71f1511 commit c5f26c0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tools/ts_uinput.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
#define UI_GET_SYSNAME(len) _IOC(_IOC_READ, UINPUT_IOCTL_BASE, 44, len)
#endif

#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
#define BITS_PER_BYTE 8
#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
#ifndef ABS_CNT
# define ABS_CNT (ABS_MAX+1)
#endif

/* TODO user-option: read non-MT events off fd_input and send them in a seperate sync-frame */

struct data_t {
Expand Down Expand Up @@ -447,6 +456,7 @@ static void cleanup(struct data_t *data)

int main(int argc, char **argv)
{
long absbit[BITS_TO_LONGS(ABS_CNT)];
struct data_t data = {
.fd_uinput = 0,
.fd_input = 0,
Expand Down Expand Up @@ -573,6 +583,17 @@ int main(int argc, char **argv)
perror("open");
goto out;
}

if ((ioctl(data.fd_input, EVIOCGBIT(EV_ABS, sizeof(absbit)), absbit)) < 0 ||
!(absbit[BIT_WORD(ABS_X)] & BIT_MASK(ABS_X)) ||
!(absbit[BIT_WORD(ABS_Y)] & BIT_MASK(ABS_Y))) {
if (!(absbit[BIT_WORD(ABS_MT_POSITION_X)] & BIT_MASK(ABS_MT_POSITION_X)) ||
!(absbit[BIT_WORD(ABS_MT_POSITION_Y)] & BIT_MASK(ABS_MT_POSITION_Y))) {
fprintf(stderr, "ts_uinput: device is not a touchscreen (must support ABS_X/Y or ABS_MT_POSITION_X/Y events)\n");
goto out;
}
}

data.ts = ts_open(data.input_name, 0 /* blocking */);
if (!data.ts) {
perror("ts_open");
Expand Down

0 comments on commit c5f26c0

Please sign in to comment.