2 * Microwindows touch screen driver for Psion 5
10 #include <sys/ioctl.h>
11 #define _LINUX_TYPES_H
13 #include </linux/include/asm-arm/arch/touch_psion.h>
17 /* file descriptor for touch panel */
20 /* Hack extern to used when hiding the mouse cursor
21 * There needs to be a better way to do this
23 extern SCREENDEVICE scrdev;
25 static int PD_Open(MOUSEDEVICE *pmd)
28 * open up the touch-panel device.
29 * Return the fd if successful, or negative if unsuccessful.
32 pd_fd = open("/dev/touch_psion", O_NONBLOCK);
34 fprintf(stderr, "Error %d opening touch panel\n", errno);
38 GdHideCursor(&scrdev);
42 static void PD_Close(void)
44 /* Close the touch panel device. */
45 fprintf(stderr,"PD_Close called\n");
51 static int PD_GetButtonInfo(void)
53 /* get "mouse" buttons supported */
57 static void PD_GetDefaultAccel(int *pscale,int *pthresh)
60 * Get default mouse acceleration settings
61 * This doesn't make sense for a touch panel.
62 * Just return something inconspicuous for now.
68 static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
70 /* read a data point */
71 struct touch_psion_event data;
74 bytes_read = read(pd_fd, &data, sizeof(data));
76 if (bytes_read != sizeof(data)) {
77 if (errno == EINTR || errno == EAGAIN)
82 *px = (MWCOORD)data.x_c;
83 *py = (MWCOORD)data.y_c;
85 *pb = (data.down>0?MWBUTTON_L:0);
88 if((*px == -1 || *py == -1) && *pb >= 0)
89 return 3; /* only have button data */
90 if((*px == -1 || *py == -1) && *pb < 0)
91 return 0; /* don't have any data */
92 return 2; /* have full set of data */
95 MOUSEDEVICE mousedev = {
105 int main(int argc, char ** v)
111 printf("Opening touch panel...\n");
113 if((result=PD_Open(0)) < 0)
114 printf("Error %d, result %d opening touch-panel\n", errno, result);
116 /* This stuff below can be used to set some of the parameters of the
117 * driver from the command line before going in to the test loop.
118 * Could this have been done better? Yup.
122 ioctl(result,1,atoi(v[1]));
123 fprintf(stderr,"Setting pressure to %d\n",atoi(v[1]));
126 ioctl(result,2,atoi(v[2]));
127 fprintf(stderr,"Setting updelay to %d\n",atoi(v[2]));
130 ioctl(result,3,atoi(v[3]));
131 fprintf(stderr,"Setting raw x to %d\n",atoi(v[3]));
134 ioctl(result,4,atoi(v[4]));
135 fprintf(stderr,"Setting raw y to %d\n",atoi(v[4]));
138 ioctl(result,5,atoi(v[5]));
139 fprintf(stderr,"Setting res x to %d\n",atoi(v[5]));
142 ioctl(result,6,atoi(v[6]));
143 fprintf(stderr,"Setting res y to %d\n",atoi(v[6]));
146 ioctl(result,7,atoi(v[7]));
147 fprintf(stderr,"Setting fudge x to %d\n",atoi(v[7]));
150 ioctl(result,8,atoi(v[8]));
151 fprintf(stderr,"Setting fudge y to %d\n",atoi(v[8]));
154 ioctl(result,9,atoi(v[9]));
155 fprintf(stderr,"Setting average sample to %d\n",atoi(v[9]));
158 ioctl(result,10,atoi(v[10]));
159 fprintf(stderr,"Setting raw min x to %d\n",atoi(v[10]));
162 ioctl(result,11,atoi(v[11]));
163 fprintf(stderr,"Setting raw min y to %d\n",atoi(v[11]));
166 printf("Reading touch panel...\n");
169 result = PD_Read(&x, &y, &z, &b);
174 printf("Pen Down\n");
179 printf("%d,%d,%d,%d,%d\n", result, x, y, z, b);