/* * wacom - * This is a temporary WACOM tablet driver process, it sould * be run in the background after system startup by adding it to * /etc/inittab. This driver is made to work with a 9x6 Wacom * SD-510C while using the pressure sensitive pen. Feel free to * modify and distribute this source as you like. * * Paul Haeberli - 1990 * * 1. Your cable should look like this: * * WACOM IRIS * ----------------------------------------- * TX Pin 2 RX Pin 3 * RX Pin 3 TX Pin 2 * RTS Pin 4 CTS Pin 5 * CTS Pin 5 RTS Pin 4 * DSR Pin 6 DTR Pin 9 * GND Pin 7 GND Pin 7 * * * 2. Plug the tablet into /dev/tty1. * 3. make sure there isn't a getty running on /dev/ttyd1. * 4. vi /etc/inittab, and make sure any lines with "ttyd1" * in them have "off" in them as well. * 5. su and chmod +wr /dev/ttyd1 * 6. compile the driver with a command like: * cc -I/usr/include/ wacom.c -o wacom -lgl_s * 7. run the driver in the background ./wacom & to try it out. * * 8. This driver is set up to generate mouse position events * and to make the left mouse button appear to go down when * the pressure sensitive pen in pressed. The actual pressure * value is available by reading the valuator "DIAL0". * * 9. when things are working well, copy wacom /etc/gl and add * a line to /etc/inittab like the line for "tabletd". * */ #include "stdio.h" #include "sys/types.h" #include "sys/stat.h" #include "fcntl.h" #include "termio.h" #include "gl.h" #include "device.h" #include "dials.h" /* #ifdef DEBUG */ #define PENBUTTON LEFTMOUSE #define PENX MOUSEX #define PENY MOUSEY #define PENPRESSURE DIAL0 #define MINPRESS (5) #define PSCALE (0.40) #define TTYDEV "/dev/ttyd1" struct termio term, sterm; int f, n; int os1, os2, os3, os4; int s1, s2, s3, s4; int oxpos, oypos, opval; int xpos, ypos, pval; main() { f = open(TTYDEV,O_RDWR); if(f < 0) { fprintf(stderr,"penmouse: error opening %s\n",TTYDEV); exit(1); } serialinit(); os1 = -1; os2 = -1; os3 = -1; os4 = -1; oxpos = -1; oypos = -1; wacominit(); readbinary(); } wacominit() { int n; /* n = write(f,"DE1\r",4); /* relative mode */ /* n = write(f,"IT50\r",5); /* transmit rate 4 per sec */ /* n = write(f,"SU03\r",5); /* suppressed mode DON'T WORK RIGHT */ /* n = write(f,"IT02\r",5); /* transmit rate 100 per sec */ /* n = write(f,"IT99\r",5); /* transmit rate 5 per sec */ n = write(f,"DE0\r",4); /* absolute mode */ n = write(f,"PH1\r",4); /* pressure mode */ n = write(f,"IT02\r",5); /* transmit rate 100 per sec */ n = write(f,"SR\r",3); /* continous stream mode */ n = write(f,"IN003\r",6); /* increment mode */ n = write(f,"AS1\r",4); /* binary mode */ } readbinary() { int c, phase; int xsign, ysign, psign, inside; while(1) { c = getwchar(); if(c&0x80) break; } phase = 1; while(1) { switch(phase) { case 1: inside = (c>>6)&1; if(inside) { if(c&0x04) xsign = -1; else xsign = 1; xpos = c&0x03; } break; case 2: if(inside) xpos = (xpos<<7) + (c&0x7f); break; case 3: if(inside) xpos = (xpos<<7) + (c&0x7f); break; case 4: if(inside) { if(c&0x04) ysign = -1; else ysign = 1; ypos = c&0x03; } break; case 5: if(inside) ypos = (ypos<<7) + (c&0x7f); break; case 6: if(inside) ypos = (ypos<<7) + (c&0x7f); break; case 7: if(inside) { pval = c&0x3f; if(c&0x40) pval = pval | 0xffffffc0; pval += 32; xpos = PSCALE*(xsign*xpos); ypos = PSCALE*(3000-(ysign*ypos)); if(xpos != oxpos) { mygl_changedevice(PENX,xpos); oxpos = xpos; } if(ypos != oypos) { mygl_changedevice(PENY,ypos); oypos = ypos; } } else pval = 0; if(pval != opval) { if(pval > MINPRESS+2) s1 = 1; if(pval < MINPRESS-2) s1 = 0; if(s1 != os1) { mygl_changedevice(PENBUTTON,s1); os1 = s1; } mygl_changedevice(PENPRESSURE,(4*pval)-639); opval = pval; } break; } phase++; c = getwchar(); if(c&0x80) { if(phase != 8) fprintf(stderr,"lost char"); phase = 1; } } } int cleft; unsigned char *bptr; unsigned char buf[512]; getwchar() { while(cleft == 0) { n = read(f,buf,512); if(n<0) { fprintf(stderr,"penmouse: bad read\n"); exit(1); } cleft = n; bptr = buf; } cleft--; return (*bptr++); } serialinit() { if (ioctl(f, TCGETA, &term) == -1) { fprintf(stderr,"ioctl(TCGETA) failed\n"); perror("init"); return(0); } sterm = term; /* change the modes */ term.c_iflag = 0; term.c_oflag = 0; term.c_lflag = 0; term.c_cflag = B9600 | CS8 | CREAD ; term.c_cc[VMIN] = 1; term.c_cc[VTIME] = 0; if (ioctl(f, TCSETA, &term) == -1) { fprintf(stderr,"ioctl(TCSETA) failed\n"); perror("init"); return(0); } } mygl_changedevice(dev,val) int dev, val; { #ifdef DEBUG printf("%d %d\n",dev,val); #else gl_changedevice(dev,val); #endif }