[comp.sys.mac.programmer] Serial interface replacement for mouse

kleinow@caen.engin.umich.edu (leonard kleinow) (03/19/90)

Here's a tricky one.  I have a pointing device (a glove) that sends about
a dozen bytes of data through its serial port to the mac indicating its
position in space and the positions of its fingers.  I want to be able to
move the cursor with this and use one of its fingers as the mouse button.
I wrote a program to get the data from the modem port, and stuff the
x and y positions in the low-memory cursor positions.  If I call this 
before WaitNextEvent each time through my main loop, the cursor does in
fact follow the glove around quite nicely.  (The routine SetMouse appeared
here some time ago.)
 
This is inadequate, however.  In order to be useful, I have to be able
to select from menus, hit buttons, etc.  Things like ModalDialog, GrowWindow,
TrackControl, MenuSelect, etc., all need "fixing".  Fight now, I have to
point the glove at the menubar, then press the mouse button and use the
mouse to select!
 
This will require some patch to the system, I think.  Is there some 
place these above-mentioned traps have in common I can patch?  Has
anyone done this already?
 
Thank you,
Leonard Kleinow
kleinow@caen.engin.umich.edu

tim@hoptoad.uucp (Tim Maroney) (03/20/90)

In article <1990Mar19.001639.28530@caen.engin.umich.edu>
kleinow@caen.engin.umich.edu (leonard kleinow) writes:
>Here's a tricky one.  I have a pointing device (a glove) that sends about
>a dozen bytes of data through its serial port to the mac indicating its
>position in space and the positions of its fingers.  I want to be able to
>move the cursor with this and use one of its fingers as the mouse button.
>I wrote a program to get the data from the modem port, and stuff the
>x and y positions in the low-memory cursor positions.  If I call this 
>before WaitNextEvent each time through my main loop, the cursor does in
>fact follow the glove around quite nicely.  (The routine SetMouse appeared
>here some time ago.)
 
Congratulations on finding the only valid use for the routine....

>This is inadequate, however.  In order to be useful, I have to be able
>to select from menus, hit buttons, etc.  Things like ModalDialog, GrowWindow,
>TrackControl, MenuSelect, etc., all need "fixing".  Fight now, I have to
>point the glove at the menubar, then press the mouse button and use the
>mouse to select!
> 
>This will require some patch to the system, I think.  Is there some 
>place these above-mentioned traps have in common I can patch?  Has
>anyone done this already?

Interesting project.  It should be fairly simple.  Presumably, you're
using a driver now that either fields a positional interrupt from the
glove or polls the glove for positional information.  When you get the
information, analyze it to see if the thumb is touching the forefinger
or whatever you've set up for a mouse button.  If it is, then set a
flag, otherwise clear the flag (might as well make it your own flag --
there's a system one, but you can patch around it and get better
compatibility).

If the flag was set and the "button" is "down", then don't do anything
else except for your usual position tracking.

If the flag was clear and the button is down, post a mouse-down event
using PostEvent.

If the flag was set and the button is up, then post a mouse-up event.

If the flag was clear and the button is up, then again there's nothing
to do.

The final piece of the solutions to patch Button so that it returns the
state of your flag rather than the state of the system flag.  The other
routines, such as WaitMouseUp, call Button to test the state, so you
shouldn't need to patch them as well.

If this helps, send me a freebie.  :-)
-- 
Tim Maroney, Mac Software Consultant, sun!hoptoad!tim, tim@toad.com

"Religion flourishes in greater purity without than with the aid
 of government." -- James Madison

urlichs@smurf.sub.org (Matthias Urlichs) (03/20/90)

In comp.sys.mac.programmer, article <much.too.long.C.News.ID>,
  kleinow@caen.engin.umich.edu (leonard kleinow) writes:
< Here's a tricky one.  I have a pointing device (a glove) that sends about
< a dozen bytes of data through its serial port to the mac indicating its
< position in space and the positions of its fingers.  I want to be able to
[...]

Open serial port.
Read the appropriate number of bytes from it, asynchronously, with a
completion routine which puts the bytes into the mouse coordinates and calls
said async Read again.

A little bit of assembler programming, no trap patches.
Clean except for the fact that you are poking into the mouse globals, which
probably can't be helped. (A recent tech note documents a more compatible way
to implement a pointer, but which seems only to work for ADB devices. Perhaps
if you install a fake ADB handler or something?)

For best results, install from an INIT so you can use it in every program, and
make a nice cdev interface to set parameters and stuff.

< This will require some patch to the system, I think.  Is there some 
< place these above-mentioned traps have in common I can patch?  Has
< anyone done this already?
<  
See above. You don't need to patch traps.

-- 
Matthias Urlichs

oster@well.sf.ca.us (David Phillip Oster) (03/21/90)

I wrote a the driver software for serial digitizing tablets once sold by Kurta.
You can use a serial device as a replacement for a mouse if you call your
SetMouse routine from the completion routine of the aysnchronous serial i/o
that is reading the serial port. Of course, you can't use a SetMouse that has
a Delay in it, and you can't change the cursor while it is busy. Setting the
button state is more of a problem since there is a VBL that resets it from the
hardware, and some VBL tasks look at the button state.
-- 
-- David Phillip Oster - Note new address. Old one has gone Bye Bye.
-- oster@well.sf.ca.us = {backbone}!well!oster