/**************************************************************************** * Test tool used to observe the behavior of buttons on a FreeBSD sysmouse * * device. * ****************************************************************************/ #include #include #include #include #include #include #include #include #define BTNSTATECHAR(a) ((a)?'u':'d') static int Inspect(int Fdesc, size_t PacketSize) { char ReadBuf[PacketSize]; ssize_t ReadSize; while((ReadSize=read(Fdesc, ReadBuf, PacketSize))==PacketSize) { struct timeval Time; if(gettimeofday(&Time, NULL)) { printf("can't get the time of day (%s)\n", strerror(errno)); return 1; } printf("%ld.%06ld Buttons: %c %c %c\n", Time.tv_sec, Time.tv_usec, BTNSTATECHAR(ReadBuf[0]&(1<<2)), BTNSTATECHAR(ReadBuf[0]&(1<<1)), BTNSTATECHAR(ReadBuf[0]&(1<<0))); fflush(stdout); } return 1; } int main(int argc, char *argv[]) { if(argc!=2) { printf("usage: %s \n", argv[0]); return 1; } int MouseFd=open(argv[1], O_RDONLY); if(MouseFd<0) { printf("can't open %s (%s)\n", argv[1], strerror(errno)); return 1; } int MouseLevel=0; if(ioctl(MouseFd, MOUSE_GETLEVEL, &MouseLevel)) { printf("can't get sysmouse operation level (%s)\n", strerror(errno)); return 1; } printf("Operating at level: %d\n", MouseLevel); switch(MouseLevel) { case 0: (void) Inspect(MouseFd, 5U); break; case 1: (void) Inspect(MouseFd, 8U); break; default: printf("unexpected mouse operation level\n"); return 1; } printf("short read or read error on %s (%s)\n", argv[1], strerror(errno)); return 1; } /* * Local Variables: * tab-width: 4 * End: */