From: jlb31348@uxa.cso.uiuc.edu (Jim Brain)
Subject: TECH: U of I Powerglove update 7-1-92 + new command post
Date: Wed, 1 Jul 1992 19:55:44 GMT
Organization: University of Illinois at Urbana


Ahhh, I have mastered the moment.  Last night's programming binge resulted in
the foundation for two glove support.  Now it looks like tonight or tommorrow
night, the two glove support will be a reality.  I have added all the necessary
commands to operate all the goodies, and I think I have outdone myself.  I
am still able to change stuff, but additions will be rare from now on unless
they are EXTREMELY small.  I am almost out a workspace.  I have packed SO
much functionality into this thing it is UNREAL.  All at little cost and NO
degradation of performance.  I will send out the revised code to all who asked
for it, and will post a new set of commands for the software people.  I need
someone to write a skeleton piece of software for the MAC that will dipslay
data from the modem port on the screen at 9600 baud.  I have also debugged
all of the commands and left very few to combat later.  I know the command
set post is pretty much a rehash of the older one, but please take a look at
the section on new commands.  I think you will be happy.  Also, let me stress
that the commands for the SEGA glasses are for those who do not have access
to the RTS/DTR pins through software, or do not want the hassle.  I have tested
the unit and it is hardware finished.  Please email me ASAP on corrections, as
the time is growing short.  I am trying to get my speed up to 30 frames a 
second, but 28 is the best I can do at the moment.  I KNOW EVERYONE wants 30
frames a second, but it may not be possible.  I will look into it some more.

I am so happy to have gotten this stuff done.  The code is very efficient, but
my compiler does not like the BSET,BCLR, BRSET, or BRCLR commands, so: does
anyone have a better assembler fro the IBM hat I can borrow?

Let me stress also that alow the new commands are available in Menelle
emulation mode.  The only commands that will change modes are 0x01-0x03, 'C'
,'R', and '?'.  Let me know what the synopsis is.  

Many have asked me how users will be able to hook up the I/O and A/D ports.
We can do it, or the manual will show you, the user, how to do it.  It is 
rather painless if you know how to solder.   That is a small worry at the
moment, considering the larger picture.  

I am looking for warehouses or stores still carrying the PG or the SEGA
glasses.  email if you know.

here is the command set.  Programmers: read this carefully.


The PowerGlove Serial Adapter II  Command Set:
 
        The PGSA II is designed to provide errorless communication with the
Mattel PowerGlove.  Also, this box was designed to allow users of programs
written for either AGE's original PGSA or Ron Minelli's Converter Box ]
Project to reuse their software without changes.  The emulation mode
assumes that the program attempting to use the converter will start
execution by putting the box into the appropriate mode (request or
continuous) and will set the emulation mode accordingly.  I encourage people
to write interrupt driven routines for platfroms other than the IBM PC,
since I already have a source for that platform.  I would also like to
gain the privilege of distributing these drivers to people who buy this box
for their own use.
 
Minelli Emulation:
 
        This emulation mode will enable use of the PGSA II as an equivalent
to the project box described by Ron Minelli.  The project is described in
detail in a file on karazm.math.edu entitled PGHC11. The commands used by
this emulation mode are as follows:
 
'C'     this command sent to the PGSA II will enable continuous download
        mode, where a new packet is sent out right after it is received from
        the PowerGlove.
 
'R'     This command sent to the PGSA II will enable Request mode, where
        a new packet is only sent when asked for one.
 
'?'     This command will request a packet in request mode.  It has no
        effect in continuous mode.
 
'+'     This command will enable the Deglitching filter as written by
        Dave Stamp.  It will deglitch the X and Y coordinates at this
        point.
 
'-'     This command will disable the deglitching filter.
 
 
The packet sent out in Minelli mode looks like the following:
 
        In continuous mode, the packets have the following data in them
 
   01 02 03 04 05       06   07
   A0 X  Y  Z  rotation flex switch
 
Where:
        A0 is the start byte (A0 hex)
        X  is the X coordinate
        Y  is the Y coordinate
        Z  is the Z coordinate
        rotation gives the angle of rotation divided by 30 degrees
        flex gives the values for the finger positions
        switch gives a value for what key is being pressed on the PG keypad
 
Flex is one byte divided as follows:
 
        7:6   5:4  3:2    1:0
        Thumb Fore Middle Ring
 
where each finger can have 4 positions:
 
00b     fully extended
01b     partially extended
10b     partially closed
11b     fully closed
 
In request mode, the packet is sent the same way, but the A0 byte is left off.
Therefore the packet length is 6 bytes.
 
 
The commands 'C', 'R', and '?' will put the PGSA II into this emulation mode.
The commands '+', and '-' will leave the PGSA II in its current emulation mode.
 
 
AGE Emulation:
 
        The AGE emulation mode will enable use of the PGSA II as the equivalent
to the AGE original PGSA.  In this mode the following commands apply:
 
0x01    This command will put the PGSA II in continuous mode.  It will send a
        packet as soon as it is received from the PowerGlove.
 
0x02    This command will put the PGSA II in request mode AND send out one
        packet of information.  To request another packet, one merely sends
        another 0x02.
 
0x04    This command will resend the default initialization template to
        the glove.  This template determines the resolution.
 
0x07    This command will reset the box to the following defaults:
 
        Deglitching: ON
        Rotation filter: ON
        Emulation: AGE
 
0x08    This command will turn on the rotation filter designed to smooth
        out the inherent twitching of the rotation value.
 
0x09    This command will turn off the rotation filter
 
 
 
The packet sent out in AGE mode looks like the following:
 
        In continuous mode, the packets have the following data in them
 
   01 02 03 04 05  06       07   08     09     10     11
   5F 5F X  Y  Z   rotation flex switch GSTAT1 GSTAT2 Receiver values
 
Where:
 
        5F 5F is the start string
        X  is the X coordinate
        Y  is the Y coordinate
        Z  is the Z coordinate
        rotation gives the angle of rotation divided by 30 degrees
        flex gives the values for the finger positions
        switch gives a value for what key is being pressed on the PG keypad
        GSTAT1 is (was) for future use
        GSTAT2 is (was) for future use
        Receiver values gives the status of receivers getting signals
 
 
Flex is one byte divided as follows:
 
        7:6   5:4  3:2    1:0
        Thumb Fore Middle Ring
 
where each finger can have 4 positions:
 
00b     fully extended
01b     partially extended
10b     partially closed
11b     fully closed
 
 
GSTAT2 is always zero (as far as I can tell), but GSTAT1 takes the value 01h
when the glove has not been calibrated (immediately after pwerup or reset, when
the fingers still need to be trained) and takes the value 00h otherwise.
 
In request mode, the packet is sent the SAME EXACT WAY, including the two
5fH characters at the beginning. Note this.
 
 
The commands 0x01 and 0x02 will put the PGSA II in AGE emulation mode.
All other commands will leave the PGSA in the same mode.
 
Use of The Box:
 
        The PGSA II is designed to allow users of existing programs designed
with either the PGSA or the Minelli Project to operate flawlessly.  This
provides the backward compatibility.  However, there are a few guidelines to
follow:
 
1:      Programs that put the box in strange modes will work fine, but the box
        may need to be reset before operating another program.   This is only
        applicable to programs that do not put the PGSA II back into the same
        state it was in when the program started.  Example.  Program A puts the
        PGSA II in request AGE mode and then exits without changing back to
        continuous mode. Program B starts, expecting to be getting continuous
        data (because that is the default state for the PGSA) and hangs because
        the box is inrequest mode.  This can be fixed by manually resetting or
        by sending the continuous command manually.
 
2:      Programs that expect the Box to emulate Minelli's Code immediately after
        reset will not work, since the PGSA II starts up in AGE emulation and
        needs a command to know what to switch to.  Solution.  Manually send
        the C or R commands.
 
As other potential problems arise, I will solve them.  At the moment, the
distribution disk will have a little program to send the commands without
needing a terminal program.  It will also have command switches for the
commands on the comand line.
 
 
        AS with most new products building on the laurels of older compatible
products, the PGSA II has a few new commands.  This is a revised list of the 
new commands available to the PGSA II user.  Here is the list:


0x0A	This will turn the first Powerglove on for input.  When a packet is
	requested, the data from the first glove will be displayed.

0x0B	This will turn off the first Powerglove for input.  When a packet is
	displayed, the info for the fist glove will not be shown.

0x0C	This turns on the second glove.

0x0D	This turns off the second glove.

0x0E	This turns on the 8 bit digital input readings.  When a packet is 
	requested, these 8 bits will be displayed in the packet.

0x0F	This turns off the 8 bit digital input readings.

0x10	This command turns on the readings from the first 4 A/D ports.  When
	this command is issued, the packet will contain values form the first  
	4 Analog to Digital ports.

0x11	This command turns off the readings from the first 4 A/D ports.

0x12	This command turns on the second 4 A/D ports.

0x13	This command turns off the second 4 A/D ports.

0x14	This command turns the left SEGA shutter black.

0x15	This command turns the left SEGA shutter clear.

0x16	This command turns the right SEGA shutter black.

0x17	This command turns the right SEGA shutter clear.

0x18	This command turns both SEGA shutters black.

0x19	This command turns both SEGA shutters clear.

0x1A	This command turns the left SEGA shutter black and the right one clear.

0x1B	This command turns the right SEGA shutter black and the left one clear.

0x1C	This command changes the baud rate rate.  The next byte received will
	be the new baud rate, as follows:

	On 9600 baud systems:

	0x01	9600 bps
	0x02	4800 bps
	0x03	2400 bps
	0x04	1200 bps
	0x05    0600 bps
	0x06	0300 bps
	0x07	0150 bps
	0x08	0075 bps

	On 38400 baud systems:

	0x01	38400 bps
	0x02	19200 bps
	0x03	09600 bps
	0x04	04800 bps
	0x05	02400 bps
	0x06	01200 bps
	0x07	00600 bps
	0x08	00300 bps

	The number received is decremented by one and then logically ANDed
	with 0x07, so any number above 0x08 will be normalized to the range
	0x01 to 0x08.

	I have not decided on the correct way to check that the user has 
	changed to the correct baud rate, but I will think of something.

0x1D	This command will change the chopping frequency of the SEGA
	shutter glasses from 16 Hz to 5 kHz.  The range may be decreased, as
	I want to make sure users cannot damage the SEGA glasses through
	software.  The next word after this command will be used as the
	new value.  

0x1E    This command will write data to the output Digital pins.  The next
	byte will be used as the value to place on the output port.



THE AMENDED PACKET STRUCTURE:

	Since this extra information must be presented to the user, I have
decided to include all the information from the PGSA II into a single packet.
When the PGSA II initially starts, it reads and displays information from the
first glove only, unless the first glove is not attached, and then it will
display only a nul packet, corresponding to two 0x5F bytes.  If the user 
enables the second glove, its packet, minus the header bytes, will succeed the
first glove info if present.  This continues on in the same fashion, with a
full, complete packet looking like this:

	5F 5F PG#1 PG#1 AD1-4 AD5-8 INPUTBYTE      	(for AGE emulation)

or:
	
	A0 PG#1 ...					(for Menelli continuous)

or:

	PG#1 ...					(for Menelli request)

(I am thinking of placing delimiters in the packet stream, but am unsure, so
email me if you think that is a good idea.)

 
Notice to those who write new programs:
 
        New programs written for either of the two boxes we intend to emulate,
or the PGSA II, should follow these general rules:
 
1:      Reset the box after finished using it.  This can be accomplished by
        sending the reset command on the PGSA and PGSA II boxes, or by putting
        the Minelli Box in Continuous mode with deglitching on.
 
2:      Have a menu to let users select which box they own.  At least provide
        command line switches to enable stuff for another box.
 
3:      Write programs that call one function to set the box into the mode you
        want and one function to get the data back.  That way, users can port \
        code from platform to another without major headaches.  We will be
        distributing code for many platforms to do this with instructions.
        (In C and Assembly, of course).
 
4:      If you write your own polling routine, be sure to escape out if
        you do not receive a valid data string in, say, 5 seconds.  This way,
        your code will not hang if a user forgets to put his box into the port
        or puts it into the wrong port.
 
5:      And this is a big one.  make sure you support all applicable RS-232
        ports.  I hate to grope around the back of my machine to rearrange
        cables,  and I hate to have two versions of the same program just to
        use either port.  We will let you specify th com port to use, but it
        is up to the author of the program to make this switch available to the
        end user.
 
6:      If you do data cruching or something else like that on the raw data,
        please make it disableable at the command prompt.  Things like
        extra smoothing of data should be able to be disabled if possible (
        This one is not as critical as the other ones

7:	This interface is very flexible, so exploit its features in your
	program.


There is not much more I can add.  I will try to add MIDI support as an add-on
hardware option, and I will make MAC users able to use this, but the code is
just about complete, as I have used 1.8 kilobytes of a maximum 2 kilobytes of
EEPROM.  I hope this makes everyone happy.


Jim Brain
 

-- 
Nothing is better than Eternal Happiness.             jlb31348@uxa.cso.uiuc.edu
A ham sandwich is better than nothing.                                Jim Brain
Therefore, a ham sandwich is better than eternal happiness.
