comparison touchTest/testIn.c~ @ 4639:f5cd4b6231ba

Added Test Directory. Touch input works in touchSimp for wacom bamboo fun on Ubuntu linux. Not yet integrated into library. Should support other touch devices and other linux distros, but not tested on anything else.
author Jim Grandpre <jim.tla@gmail.com>
date Mon, 24 May 2010 23:44:24 -0400
parents
children
comparison
equal deleted inserted replaced
4464:fa77a6429698 4639:f5cd4b6231ba
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <unistd.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <dirent.h>
8 #include <linux/input.h>
9 #include <sys/types.h>
10 #include <sys/stat.h>
11 #include <sys/select.h>
12 #include <sys/time.h>
13 #include <termios.h>
14 #include <signal.h>
15
16 void handler (int sig)
17 {
18 printf ("\nexiting...(%d)\n", sig);
19 exit (0);
20 }
21
22 void perror_exit (char *error)
23 {
24 perror (error);
25 handler (9);
26 }
27
28 int main (int argc, char *argv[])
29 {
30 struct input_event ev[64];
31 int fd, rd, value, size = sizeof (struct input_event);
32 char name[256] = "Unknown";
33 char *device = NULL;
34
35 //Setup check
36 if (argv[1] == NULL){
37 printf("Please specify (on the command line) the path to the dev event interface device\n");
38 exit (0);
39 }
40
41 if ((getuid ()) != 0)
42 printf ("You are not root! This may not work...\n");
43
44 if (argc > 1)
45 device = argv[1];
46
47 //Open Device
48 if ((fd = open (device, O_RDONLY)) == -1)
49 printf ("%s is not a vaild device.\n", device);
50
51 //Print Device Name
52 ioctl (fd, EVIOCGNAME (sizeof (name)), name);
53 printf ("Reading From : %s (%s)\n", device, name);
54
55 while (1){
56
57 if ((rd = read (fd, ev, size * 64)) < size)
58 perror_exit ("read()");
59 printf("time: %i\n type: %X\n code: %X\n value: %i\n ",ev[0].time,ev[0].type,ev[0].value,ev[0].value);
60
61 value = ev[0].value;
62
63 if (value != ' ' && ev[1].value == 1 && ev[1].type == 1){ // Only read the key press event
64 printf ("Code[%d]\n", (ev[1].code));
65 }
66 }
67
68 return 0;
69 }