2 * MicroTouch touch panel driver for MicroTouch capacitive and resistive
3 * controllers at RS232 port.
5 * We expect the Microtouch Controller configured to 9600 Baud, 8 data bits,
6 * 1 stop bit, no parity
8 * Written by Holger Waechtler <hwaechtler@users.sourceforge.net>
18 static int MT_Open(MOUSEDEVICE *pmd);
19 static void MT_Close(void);
20 static int MT_GetButtonInfo(void);
21 static void MT_GetDefaultAccel(int *pscale,int *pthresh);
22 static int MT_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp);
24 MOUSEDEVICE mousedev = {
38 write (fd, "\001" x "\r", strlen(x) + 2); \
45 * Open up the mouse device.
48 MT_Open(MOUSEDEVICE *pmd)
50 char *devname = "/dev/ttyS0";
51 struct termios termios;
53 if ((mt_fd = open (devname, O_RDWR | O_NONBLOCK)) < 0) {
54 fprintf (stderr, "error opening '%s'\n", devname);
58 tcgetattr (mt_fd, &termios);
60 cfsetispeed (&termios, B9600);
61 cfsetospeed (&termios, B9600);
64 termios.c_cflag &= ~CBAUD;
65 termios.c_cflag = B9600;
66 termios.c_cflag |= CS8 | CREAD;
68 termios.c_oflag &= ~(OCRNL | ONLRET);
70 tcsetattr (mt_fd, TCSAFLUSH, &termios);
80 * This is a sort of hack, but our embedded PPC was to slow to read all
81 * responses from the Microtouch controller. To get out of this we simply
85 tcflush (mt_fd, TCIOFLUSH);
91 * Close the mouse device.
103 * Get mouse buttons supported
106 MT_GetButtonInfo(void)
113 * doesn't makes sense for a touch panel ...
116 MT_GetDefaultAccel(int *pscale,int *pthresh)
125 int bytes_in_buf = 0;
129 * Attempt to read bytes from the mouse and interpret them.
130 * Returns -1 on error, 0 if either no bytes were read or not enough
131 * was read for a complete state, or 1 if the new state was read.
132 * When a new state is read, the current buttons and x and y deltas
133 * are returned. This routine does not block.
136 MT_Read(MWCOORD *dx, MWCOORD *dy, MWCOORD *dz, int *bp)
138 if (bytes_in_buf == 5) {
141 *dx = ((buf[1] & 0x7f) | ((buf[2] & 0x7f) << 7));
142 *dy = ((buf[3] & 0x7f) | ((buf[4] & 0x7f) << 7));
143 *dx = (*dx * scrdev.xvirtres) >> 14;
144 *dy = scrdev.yvirtres - ((*dy * scrdev.yvirtres) >> 14);
147 if (!(buf[0] & (1 << 6)))
155 if (read (mt_fd, buf + bytes_in_buf, 1) == 1)
158 if ((buf[bytes_in_buf-1] & 0x80) != 0) {
159 buf [0] = buf [bytes_in_buf-1];