Subject: Re: standard interface

From: [email-masked] (John D Beutel)
Date: Wed, 9 Oct 91 17:36:34 EDT

> I uploaded source code for a PC...  I converted the ST code and fixed it up
> a little.

Wonderful!

> I was thinking, we should probably have a standard interface of
> some sort so that our code will be relatively compatible.  Here is my proposal:
> typedef struct _glove_data {
>    unsigned char dum0;
>    signed   char x,y,z;
>    unsigned char rot,fingers,keys,dum7,dum8,dum9,dumA,dumB;
>    } glove_data;
>  
> void Hires();
> void getglove(glove_data *);
> 
>  
> possibly better function names would be glove_init() and glove_sample()
> Also, the byte that I called "dum9" seems to be used to tell if the glove
> is not aimed at the receivers.  

That sounds good to me.  I would have favored the structure that
already comes from the "black box", since it's already been around,
but the data itself is exactly the same form so conversions should
be trivial, and the "black box" has no specific structure defined
(i.e., no names that I'm aware of).  So, I'd say lets use these names.
Should we define a whole .h file?  (E.g., constants for the bits in
keys, macros to mask and shift the two bits in fingers...)
I hate to start a senseless meta-discusion, but I don't want to go to
over-plan anything.

>   The other thing to start brainstorming about is
> how to solve the problem of the 5 long pauses.  Each one is 14 milliseconds,
> so you waste 70 milliseconds per sample.  Surely something useful could be
> squeezed into that time somehow.

I'm trying to solve that on the ST by using an internal timer to
generate an interrupt at the end of each long pause.  An ISR would
handle the protocol at each interrupt, and the CPU would be free to
do other things in the mean time.  Lately I've been talking about
it more than trying it, but in theory I should get it working.
I don't know if other computers have a similar capability,
but probably they do.

So, for the sake of implementations that take this approach,
I propose two more things:

void  glove_pre();		/* call > 80 ms previous to glove_sample() */
int   glove_pend;		/* boolean flags glove data as pending */

The glove_pre() is a function which should be called 80 ms or more
previous to glove_sample().  When the glove data is ready, the global
glove_pend will be set = 0, and then glove_sample() may be called.

For implementations like mine, glove_pre() will start the protocol
and set glove_pend = 1.  When an ISR finishes the protocol, it will
set glove_pend = 0, and glove_sample() will just be a dumby that
copies the glove_data into the given structure.

For implementations using busy loops or external hardware (e.g., 68HC11),
the glove_pre() will be a dumby function, glove_pend will always = 0,
and glove_sample() will really go get the data each time.

This will allow people to write programs that work both ways.
The code wouldn't be much more complicated than without glove_pre():

glove_data	gd;

glove_init();			/* hi-res mode */
glove_pre();			/* start first sample if we need to */
while( 1) {
	foo();			/* 80 ms worth of graphics stuff */
	while( glove_pend);	/* wait if we need to */
	glove_sample( &gd);	/* get the data (one way or the other) */
	glove_pre();		/* start the next sample if we need to */
}

Also, shouldn't we allow glove_init(), glove_pre(), and glove_sample()
to return error codes, at least for recognizable hardware errors?

--
J. David Beutel  11011011  [email-masked]  "I am, therefore I am."