Microsoft serial mouse with INTERACTIVE UNIX

Conor P. Cahill cpcahil at virtech.uucp
Sun Mar 24 07:54:57 AEST 1991


tim at gistdev.gist.com (Tim Larson) writes:
>However, in order to support the Microsoft serial mouse, I believe that I will 
>need to communicate with the mouse through /dev/tty00.  As I understand it I 
>will need to open the device and send protocol of some sort to the mouse which 
>will cause it to send back information about button status and mouse movement.

To work with a serial mouse you need to:

	1. open the tty port
	2. configure the tty port (ioctls - termio(7))
	3. reset and configure the mouse
	4. read and decrypt the port.

I have attached a piece of code that (if I remember correctly) does steps
3&4 for a microsoft mouse (I'm sure you can figure out how to do steps 1&2). 

		***** DISCLAIMER *****
I haven't touched this code in over a year and I don't know for sure if it
was still working with a microsoft mouse when I was done (I had been working
with other devices at the time).

Good luck.

	write(fd,"",1);				/* reset		*/
	sleep(1);
	write(fd,"@OTI*",5);			/* report when pressed	*/
	sleep(1);
	while( (rlen=read(fd,buffer,512)) > 0)
	{
		for(s=buffer, i=0; i < rlen; i++,s++)
		{
			if( (*s) & 0x40 )
			{
				new_left_btn = ((*s) & 0x20) == 0x20;
				new_right_btn = ((*s) & 0x10) == 0x10;
				chng_x	= ((*s) & 0x03) << 6;
				chng_y  = ((*s) & 0x0c) << 4;
				was = 1;
			}
			else if( was == 1 )
			{
				chng_x |= ( (*s) & 0x3f );
				total_chng_x += chng_x;
				was = 2;
			}
			else if( was == 2 )
			{
				chng_y |= ( (*s) & 0x3f );
				was = 0;
				total_chng_y += chng_y;

#ifdef ADJUST_GRANULARITY	
				/*
				 * If the button state changes, or we have
				 * moved at least divisor pixels...
				 * generate an output...
			 	 */
				if( (old_left_btn  != new_left_btn)  ||
				    (old_right_btn != new_right_btn) ||
				    (abs(total_chng_y) > divisor)    ||
				    (abs(total_chng_x) > divisor)     )
				{
					
					chng_x = total_chng_x / divisor;
					total_chng_x %= divisor;

					chng_y = total_chng_y / divisor;
					total_chng_y %= divisor;

					fprintf(stdout,"l%d r%d dx=%d dy=%d\n",
						new_left_btn, new_right_btn,
						chng_x, chng_y);
					old_left_btn = new_left_btn;
					old_right_btn = new_right_btn;
				}
#else
				fprintf(stdout," l=%d  r=%d   dx=%d   dy=%d\n",
					new_left_btn, new_right_btn,
					chng_x, chng_y);
#endif
					
			}
		}
	}
-- 
Conor P. Cahill            (703)430-9247        Virtual Technologies, Inc.
uunet!virtech!cpcahil                           46030 Manekin Plaza, Suite 160
                                                Sterling, VA 22170 



More information about the Comp.unix.sysv386 mailing list