/* * Copyright 2003 by orc@pell.chi.il.us (David L. Parsons) * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies * and that both that copyright notice and this permission notice * appear in supporting documentation, and that the name of David L. * Parsons not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior * permission. David L. Parsons makes no representations about the * suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * * DAVID L. PARSONS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL DAVID L. PARSONS BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR * OTHER TORTIOUS ACTIONS, ARISING OUT OF OR IN CONNECTION WITH THE USE * OR PERFORMANCE OF THIS SOFTWARE. */ #include #include #include int mouse; struct mstate { int x, y; int flag; #define SW1 0x01 #define SW2 0x02 #define SW3 0x04 #define TEST 0x08 #define REL 0x10 #define SCHG 0x40 } ; struct mstate mpos = { 0, 0, 0 }; struct mstate mcur; void sw(char *name, int sw) { if ( (mpos.flag & sw) && !(mcur.flag & sw) ) printf("<%s up>", name); else if (mcur.flag & sw) printf("<%s>", name); } int packet() { unsigned char pkt[5]; unsigned char c[1]; int ct = 0; unsigned int x, y; while (read(mouse,c,1) == 1) { /* sync on first byte */ if (ct == 0) { if ((c[0] & 0xa0) != 0xa0) continue; } else { if ( (c[0] & 0x80) != 0) { ct = 0; continue; } } pkt[ct++] = c[0]; if (ct >= 5) break; } if (ct < 5) return 0; mcur.flag = pkt[0]; /* decode packet */ mcur.x = pkt[1] | (pkt[2] << 7); mcur.y = pkt[3] | (pkt[4] << 7); if (mcur.flag != mpos.flag /*|| mcur.x != mpos.x || mcur.y != mpos.y*/ ) { sw("sw1", SW1); sw("sw2", SW2); sw("sw3", SW3); if (mcur.flag & SCHG) printf(""); if (mcur.flag & TEST) printf(""); if (mcur.flag & REL) printf(""); #if 0 if ( (mcur.x != mpos.x) || (mcur.y != mpos.y) ) printf("x = %d, y = %d", mcur.x, mcur.y); #endif putchar('\n'); mpos = mcur; } return 1; } main(int argc, char **argv) { struct termios tty; int i; if ( (mouse = open(argv[1], O_RDWR)) == -1) { perror(argv[1]); exit(1); } puts("setting terminal speed"); tcgetattr(mouse, &tty); cfsetspeed(&tty, B19200); tcsetattr(mouse, TCSANOW, &tty); puts("initializing"); i = TIOCM_DTR|TIOCM_RTS; ioctl(mouse, TIOCMBIS, &i); usleep(500); i = TIOCM_RTS; ioctl(mouse, TIOCMBIC, &i); usleep(2); i = TIOCM_RTS; ioctl(mouse, TIOCMBIS, &i); usleep(20); write(mouse, "@C0", 3); puts("ready"); while (packet()) ; }