Programming the Logitech Serial mouse (LONG)
Stephen M. Youndt
steve at hacker.UUCP
Fri Dec 14 14:01:33 AEST 1990
About a month or so ago, I posted a message inquiring how I might read the
Logitech serial mouse that I use without resorting to X/windows. As it turns
out this endeavor has solved two problems. First, the source and text that
follow are, inasmuch as I can determine, absolutely correct. All I have is
the e-mail address, and I've been unable to find the persons name, but
whoever you are, Thank You very much!!!
Another thing that I've learned is that applications under VP/ix can hose over
the mouse and make it unreadable in this manner. I plan to call Logitech
tomorrow to determine how to set the mouse back to the default mode from Unix.
All I've been able to determine so far is that starting X with the mouse hosed
causes the graphics cursor to "hide" in the lower left corner of the screen.
The only way thus far to fix it is to unplug the mouse from the serial port,
allowing it to lose power.
When I have the info I need, I'll post source illustrating the other mouse
modes as well, and how to get into and out of those modes.
================================== Start of Text =============================
-->From uucp Tue Dec 4 19:16 EST 1990
-->>From zip.eecs.umich.edu!mknister Tue Dec 4 10:23:41 1990 remote from uunet
-->Received: from zip.eecs.umich.edu by uunet.UU.NET (5.61/1.14) with UUCP
--> id AA29021; Tue, 4 Dec 90 10:23:41 -0500
-->From: uunet!zip.eecs.umich.edu!mknister
-->Received: by mailrus.cc.umich.edu (5.61/1123-1.0)
--> id AA18072; Tue, 4 Dec 90 10:21:45 -0500
-->Received: from zip.eecs.umich.edu by umich.edu (5.61/1123-1.0)
--> id AA18324; Tue, 4 Dec 90 10:22:48 -0500
-->Received: from delhi.eecs.umich.edu by zip.eecs.umich.edu (5.61+++/3.00-gamma) id AA11348; Tue, 4 Dec 90 10:21:15 -0500
-->Message-Id: <9012041521.AA11348 at zip.eecs.umich.edu>
-->To: hacker!steve (Stephen M. Youndt)
-->Cc: umich!zip.eecs.umich.edu!mknister
-->Subject: Re: Serial mouse under Esix rev D
-->In-Reply-To: Your message of "30 Nov 90 15:53:14 GMT."
-->Date: Tue, 04 Dec 90 10:24:06 EST
-->Status: RO
-->
-->
-->Here's some info on using a serial (logitech/mouse systems) mouse. It
-->was all determined from experimentation, but it seems to be about
-->right.
-->
-->Configure the port at 1200 baud, no parity. Data comes in 5-byte
-->packets. The first byte contains mouse info, the last 4 are
-->horizontal/vertical mouse movements.
-->
-->The high 4 bits of byte 1 always seem to be 1000; this appears to be a
-->marker indicating the start of the 5-byte packet.
-->
-->The low 4 bits of byte 1 indicate mouse buttons:
-->
-->Byte 1: 1 0 0 0 0 X X X
--> | | |
--> | | |-- 0 if right mouse button down, 1 if up
--> | |---- 0 if middle mouse button down, 1 if up
--> |------ 0 if left mouse button down, 1 if up
-->
-->Byte 2 contains a signed number indicating the horizontal mouse
-->movement.
-->Byte 3 contains a signed number indicating the vertical mouse
-->movement.
-->Bytes 4 & 5 appear to be horizontal/vertical mouse movement again, but
-->at a lower resolution. I think you can ignore them.
-->
-->Here's some test code I wrote. hpos1/vpos1 keep track of the
-->horizontal/vertical mouse position using bytes 2 & 3. hpos2/vpos2 do
-->the same using bytes 4 & 5.
-->
-->#include <stdio.h>
-->#include <termio.h>
-->#include <fcntl.h>
-->
-->main(argc, argv)
-->int argc;
-->char **argv;
-->{
--> int fd, i, j, hpos1=0, hpos2=0, vpos1=0, vpos2=0;
--> char buf[100];
--> struct termio tty;
-->
--> fd = open(argv[1], O_RDONLY);
--> if (fd < 0) {
--> perror("open");
--> exit(-1);
--> }
-->
--> ioctl(fd,TCGETA,&tty);
--> tty.c_iflag = IGNBRK | IGNPAR ;
--> tty.c_oflag = 0;
--> tty.c_cflag = B1200 | CS8 | CSTOPB | CREAD;
--> tty.c_lflag = 0;
--> tty.c_cc[VTIME]=0;
--> tty.c_cc[VMIN]=1;
--> ioctl(fd,TCSETA,&tty);
-->
--> j = 0;
-->
--> while (1) {
--> i = read(fd, buf+j, 5);
--> if (i < 0) {
--> perror("read");
--> }
--> else {
--> j += i;
--> }
--> if (j >= 5) {
--> hpos1 += buf[1]; hpos2 += buf[3];
--> vpos1 += buf[2]; vpos2 += buf[4];
--> printf("BUTTONS:%2X ", (unsigned char) buf[0]);
--> printf("H(%3d/%3d) ", buf[1],buf[3]);
--> printf("V(%3d/%3d) ", buf[2],buf[4]);
--> printf("pos1=(%4d,%4d) ", hpos1, vpos1);
--> printf("pos2=(%4d,%4d) ", hpos2, vpos2);
--> printf("\n");
--> fflush(stdout);
-->
--> for (i=5; i<j; i++) buf[i-5] = buf[i];
--> j -= 5;
--> }
--> }
-->}
-->
=================================== End of Text ==============================
If there are any more questions regarding the operation of a Logitech serial
mouse, ask me in a few days and I'll probably know. Again, thanks to all of
those who expressed and interest and/or offered help. Later. -- SMY
--
Stephen M. Youndt / "Remember, no matter where you go,
uunet!hacker!steve / there you are." -- B. Banzai
More information about the Comp.unix.sysv386
mailing list