-
Notifications
You must be signed in to change notification settings - Fork 5
/
Touch.h
73 lines (61 loc) · 1.58 KB
/
Touch.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/select.h>
#include <signal.h>
#include <linux/input.h>
int tfd;
int touchX=0;
int touchY=0;
int touchAvailable();
int getTouch();
int initTouch(char * tpath);
int initTouch(char * tpath)
{
if ((tfd = open(tpath, O_RDONLY)) < 0) {
return 1;
}
}
//Returns 0 if no touch available. 1 if Touch start. 2 if touch end. 3 if touch move
int getTouch()
{
int i;
size_t rb;
struct input_event ev[64];
int retval;
retval=0;
if(touchAvailable())
{
rb=read(tfd,ev,sizeof(struct input_event)*64);
for (i = 0; i < (rb / sizeof(struct input_event)); i++)
{
if (ev[i].type == EV_SYN)
{
if(retval==0) retval=3;
break; //action
}
else if (ev[i].type == EV_KEY && ev[i].code == 330 && ev[i].value == 1) retval=1; //touch start
else if (ev[i].type == EV_KEY && ev[i].code == 330 && ev[i].value == 0) retval=2; //touch finish
else if (ev[i].type == EV_ABS && ev[i].code == 0 && ev[i].value > 0)
{
touchX = ev[i].value;
}
else if (ev[i].type == EV_ABS && ev[i].code == 1 && ev[i].value > 0)
{
touchY = ev[i].value;
}
}
}
return retval;
}
int touchAvailable()
{
struct timeval tv;
fd_set fds;
tv.tv_sec = 0;
tv.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(tfd, &fds);
select(tfd+1, &fds, NULL, NULL, &tv);
return (FD_ISSET(tfd, &fds));
}