2 * Microwindows touch screen driver for G.Mate YOPY
4 * Copyright (c) 2000 Century Software Embedded Technologies
6 * Requires /dev/yopy-ts kernel mouse driver.
14 #include <sys/ioctl.h>
17 /* file descriptor for touch panel */
18 static int pd_fd = -1;
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;
31 #define TRANSFORMATION_UNITS_PER_PIXEL 4
32 static int GetPointerCalibrationData(void)
35 * Read the calibration data from the calibration file.
36 * Calibration file format is seven coefficients separated by spaces.
39 /* Get pointer calibration data from this file */
40 const char cal_filename[] = "/etc/ts.conf";
44 FILE* f = fopen(cal_filename, "r");
47 EPRINTF("Error %d opening pointer calibration file %s.\n",
52 items = fscanf(f, "%d %d %d %d %d %d %d",
53 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5], &cal[6]);
56 EPRINTF("Improperly formatted pointer calibration file %s.\n",
62 EPRINTF("a=%d b=%d c=%d d=%d e=%d f=%d s=%d\n",
63 cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], cal[6]);
69 static XYPOINT DeviceToScreen(XYPOINT p)
72 * Transform device coordinates to screen coordinates.
73 * Take a point p in device coordinates and return the corresponding
74 * point in screen coodinates.
75 * This can scale, translate, rotate and/or skew, based on the coefficients
76 * calculated above based on the list of screen vs. device coordinates.
80 /* set slop at 3/4 pixel */
81 const short slop = TRANSFORMATION_UNITS_PER_PIXEL * 3 / 4;
85 new.x = (cal[0] * p.x + cal[1] * p.y + cal[2]) / cal[6];
86 new.y = (cal[3] * p.x + cal[4] * p.y + cal[5]) / cal[6];
88 /* hysteresis (thanks to John Siau) */
89 if ( abs(new.x - prev.x) >= slop )
90 out.x = (new.x | 0x3) ^ 0x3;
94 if ( abs(new.y - prev.y) >= slop )
95 out.y = (new.y | 0x3) ^ 0x3;
104 static int PD_Open(MOUSEDEVICE *pmd)
107 * open up the touch-panel device.
108 * Return the fd if successful, or negative if unsuccessful.
111 pd_fd = open("/dev/yopy-ts", O_NONBLOCK);
113 EPRINTF("Error %d opening touch panel\n", errno);
117 GetPointerCalibrationData();
118 GdHideCursor(&scrdev);
123 static void PD_Close(void)
125 /* Close the touch panel device. */
131 static int PD_GetButtonInfo(void)
133 /* get "mouse" buttons supported */
137 static void PD_GetDefaultAccel(int *pscale,int *pthresh)
140 * Get default mouse acceleration settings
141 * This doesn't make sense for a touch panel.
142 * Just return something inconspicuous for now.
149 static int PD_Read(MWCOORD *px, MWCOORD *py, MWCOORD *pz, int *pb)
151 /* read a data point */
158 bytes_read = read(pd_fd, &data, sizeof(data));
160 if (bytes_read != sizeof(data)) {
161 if (errno == EINTR || errno == EAGAIN) {
167 transformed.x = (data & 0x3ff);
168 transformed.y = (data >> 10) & 0x3ff;
170 transformed = DeviceToScreen(transformed);
178 *pb = (((data >> 31) & 0x1) ? MWBUTTON_L : 0);
183 return 3; /* only have button data */
185 return 2; /* have full set of data */
188 MOUSEDEVICE mousedev = {
198 int main(int argc, char ** v)
204 DPRINTF("Opening touch panel...\n");
206 if((result=PD_Open(0)) < 0)
207 DPRINTF("Error %d, result %d opening touch-panel\n", errno, result);
210 result = PD_Read(&x, &y, &z, &b);
215 DPRINTF("Pen Down\n");
219 DPRINTF("%d,%d,%d,%d,%d\n", result, x, y, z, b);