| 1 | /* |
|---|
| 2 | sample by Eric Weiss eric@eric-weiss.de |
|---|
| 3 | */ |
|---|
| 4 | #include <stdio.h> |
|---|
| 5 | #include <sys/time.h> |
|---|
| 6 | #include <sys/types.h> |
|---|
| 7 | #include <unistd.h> |
|---|
| 8 | #include <sys/stat.h> |
|---|
| 9 | #include <fcntl.h> |
|---|
| 10 | #include <linux/input.h> |
|---|
| 11 | int |
|---|
| 12 | main(void) { |
|---|
| 13 | fd_set rfds; |
|---|
| 14 | struct timeval tv; |
|---|
| 15 | int retval; |
|---|
| 16 | struct input_event evt; |
|---|
| 17 | struct input_event evt1; |
|---|
| 18 | int file,file1; |
|---|
| 19 | int a; |
|---|
| 20 | int rep[2]; /* Repeat rate array (milliseconds) */ |
|---|
| 21 | rep[0] = 1000; /* Delay before first repeat */ |
|---|
| 22 | rep[1] = 250; /* Repeating delay */ |
|---|
| 23 | int x,y; |
|---|
| 24 | |
|---|
| 25 | /* Watch stdin (fd 0) to see when it has input. */ |
|---|
| 26 | file=open("/dev/input/event0",O_NONBLOCK +O_ASYNC+O_RDONLY); |
|---|
| 27 | file1=open("/dev/input/touchscreen0",O_NONBLOCK +O_ASYNC+O_RDONLY); |
|---|
| 28 | printf( "fds %i , %i \n",file,file1); |
|---|
| 29 | |
|---|
| 30 | /* Wait up to five seconds. */ |
|---|
| 31 | while(1) |
|---|
| 32 | { |
|---|
| 33 | tv.tv_sec = 1; |
|---|
| 34 | tv.tv_usec = 0; |
|---|
| 35 | FD_ZERO(&rfds); |
|---|
| 36 | FD_SET(file, &rfds); |
|---|
| 37 | FD_SET(file1, &rfds); |
|---|
| 38 | // if(ioctl(file1, EVIOCSREP, rep)) |
|---|
| 39 | //{ |
|---|
| 40 | //perror("evdev ioctl"); |
|---|
| 41 | //} |
|---|
| 42 | retval = select(5, &rfds, NULL, NULL, &tv); |
|---|
| 43 | // printf("retval %i\n",retval); |
|---|
| 44 | if( FD_ISSET(file, &rfds)) |
|---|
| 45 | { |
|---|
| 46 | read(file,&evt, sizeof(struct input_event)); |
|---|
| 47 | printf("event: code %i val %i type %i ret %i\n",evt.code,evt.value,evt.type,retval); |
|---|
| 48 | } |
|---|
| 49 | if( FD_ISSET(file1, &rfds)) |
|---|
| 50 | { |
|---|
| 51 | read(file1,&evt1, sizeof(struct input_event)); |
|---|
| 52 | if (( evt1.code==0 ) & (evt1.type==3 )) |
|---|
| 53 | { |
|---|
| 54 | x=(evt1.value-200)/300; |
|---|
| 55 | } |
|---|
| 56 | if (( evt1.code==1 ) & (evt1.type==3 )) |
|---|
| 57 | { |
|---|
| 58 | y=(evt1.value-200)/300; |
|---|
| 59 | } |
|---|
| 60 | // printf("event1: code %i value %i val %i ret%i\n", evt1.code,evt1.value,evt1.type,retval); |
|---|
| 61 | printf ("X %i Y %i \n",x,y); |
|---|
| 62 | } |
|---|
| 63 | if ( evt.type == EV_KEY) |
|---|
| 64 | { |
|---|
| 65 | // printf ("%i %i %i\n",evt.type,evt.value,evt.code); |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | /* Don't rely on the value of tv now! */ |
|---|
| 70 | |
|---|
| 71 | if (retval == -1) |
|---|
| 72 | perror("select()"); |
|---|
| 73 | else if (retval) |
|---|
| 74 | printf("Data is available now.\n"); |
|---|
| 75 | /* FD_ISSET(0, &rfds) will be true. */ |
|---|
| 76 | else |
|---|
| 77 | printf("No data within five seconds.\n"); |
|---|
| 78 | return 0; |
|---|
| 79 | } |
|---|