A week or so ago I posted a request for help with connecting a mouse
on a Microport SysV system. Several people sent mail asking how I
got it to work so I thought I would post the solution since it is
very short. Mice run at 1200 baud, no parity, 1 stop bit and one
packet of information is 5 bytes
b dx1 dy1 dx2 dy2
where dx{n} and dy{n} are signed 8 bit numbers and b has the format
1 0 0 0 0 b1 b2 b3
and b{n} == 1 if the button is UP.
I don't claim the code below is great, it could easily be improved,
but it works.
john
-----
/* sinmple mouse routines */
#include <fcntl.h>
#include <stdio.h>
#include <termio.h>
static int mfd;
MouseInit()
{
struct termio t;
int i;
mfd = open("/dev/tty1",O_RDONLY);
if (mfd < 1) fprintf(stderr," couldn't open mouse \n");
i=ioctl(mfd,TCGETA, &t);
if (i < 0 ) fprintf(stderr,"ioctl error\n");
t.c_iflag = t.c_iflag & ~(IXON|IXOFF|ISTRIP|INLCR|IGNCR|ICRNL|IUCLC|INPCK);
t.c_cflag = B1200 | CS8 | CLOCAL | CREAD ;
t.c_lflag = 0;
i=ioctl(mfd,TCSETA, &t);
if (i < 0 ) fprintf(stderr,"ioctl error\n");
/* wait for mouse to send something then return change in x, y and theQuote:}
status of the buttons with bn==1 if the button is down
*/
MouseRead(dx, dy, b1, b2, b3)
int *dx, *dy, *b1, *b2, *b3;
{
unsigned char b;
char bs[4];
int j;
for (b=0; (b&0370) != 0200 ; ) read(mfd, &b, 1);
/* get here with button byte */
for (j=0; j<4; j++) read(mfd,&(bs[j]),1); /* get coords */
*b3 = (~b) & 1;
*b2 = (~(b>>1)) & 1;
*b1 = (~(b>>2)) & 1;
*dx = (int ) bs[0];
*dy = (int ) bs[1];
*dx = *dx + (int ) bs[2];
*dy = *dy + (int ) bs[3];
Quote:}