This repository has been archived by the owner on Jun 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
touch.c
58 lines (50 loc) · 1.15 KB
/
touch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define _GNU_SOURCE 1
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#include <fcntl.h>
#include <linux/input.h>
#include "misc.h" // for our version of pthread_setname()
#define TOUCH "/dev/input/event1"
void touchitem(void *arg,int x,int y,int ev);
void *touch(void *arg){
if(arg == NULL)
return NULL;
pthread_setname("touch");
int touch_fd = -1;
int pos_x=0,pos_y=0,pos_id=0;
while(1){
if(touch_fd == -1
&& (touch_fd = open(TOUCH,O_RDONLY)) == -1){
usleep(1000000); // Don't spin tight
continue;
}
struct input_event event;
int len;
if((len = read(touch_fd,&event,sizeof(event))) == -1){
touch_fd = -1; // Close and retry
continue;
}
// Got something from the touchscreen
if(event.type == EV_SYN){
touchitem(arg,pos_x,pos_y,pos_id);
continue;
}
if(event.type == EV_ABS){
switch(event.code){
case ABS_MT_TRACKING_ID:
pos_id = event.value;
break;
case ABS_MT_POSITION_X:
pos_x = event.value;
break;
case ABS_MT_POSITION_Y:
pos_y = event.value;
default:
break;
}
}
}
}