home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / info / uforce.lzh / Uforce.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-25  |  2.9 KB  |  93 lines

  1. /*
  2.  
  3.  Uforce.c - read a sample set from the Uforce
  4.  
  5.  Ethan Dicks  <erd@kumiss.UUCP>
  6.  
  7.  Version 1.0  24-Mar-1992
  8.  
  9. */
  10.  
  11. /*
  12.  
  13. The information provided about the Uforce was provided to me by Dave Capper
  14. and Stan Axelrod, the developers of the Uforce.  I was send a multi-page
  15. developers guide and was able to piece together the following code to
  16. wrest the information out of the device.  I was not required to sign any
  17. non-disclosure agreements, so I believe that I am permitted to pass along
  18. the following information...
  19.  
  20. "Uforce 101..."
  21.  
  22. The Uforce has 9 total IR emitters and detectors of which 8 may be active
  23. at any given time.  The four configuration switches are divided into
  24. two functional groups.  The first three select a sample mode which determines
  25. how the Uforce will present the data to the host and the last switch selects
  26. which of two particular sensors is active.  Seven of the eight possible
  27. arrangements of the first three config switches places the Uforce into
  28. "Threshold mode" wherin the device compares the values of the various
  29. sensors against known thresholds in ROM and provides the host with a standard
  30. NES 8 bit packet containing up/down/left/right/select/start/A/B information.
  31. When all three switches are down, the Uforce is placed into "Analog mode"
  32. wherin a multi-byte packet with raw information about each IR sensor
  33. is provided to the host.  The format is as follows... (all values in hex)
  34.  
  35.  Flag      S 7     S 6     S 5     S 4     S 3     S 2      S 1     S 0
  36. FC-FF*    01-FB    01-FB    01-FB    01-FB    01-FB    01-FB    01-FB    01-FB
  37.  
  38. FF = no buttons pressed
  39. FE = START pressed
  40. FD = SELECT pressed
  41. FC = START & SELECT pressed
  42.  
  43. The flag byte is easy to spot because it is always over FC.  If 00 is
  44. ever read, it should be discarded because the Uforce is still aquiring
  45. data (this can take up to 10 milliseconds to complete); 00 is never
  46. valid data.  There must be a 150 microsecond delay between bytes; this
  47. is an NES restriction.  Any routine which is able to read in a single
  48. byte from a standard NES controller can be used to read the Uforce in
  49. Analog mode; unlike the PowerGlove in hires mode, the Uforce uses fairly
  50. standard techniques for sending data back to the host.
  51.  
  52. The sensor map is arranged as follows...
  53.  
  54.     +------ 0 ------+
  55.     |   2        1    |
  56.     |        |
  57.     |   3        5   |
  58.     +---------------+
  59.     |   4            |
  60.     |        |
  61.     |   7        6   |
  62.     +------ 5 ------+
  63.  
  64. Sensor 5 is controlled by the right most config switch
  65.  
  66. */
  67. #ifdef AMIGA
  68. #include <exec/types.h>
  69. #endif
  70.  
  71. #include "UForce.h"
  72.  
  73. void query_Uforce(Uforce_data *g)
  74. {
  75.     register int i;
  76.     register UBYTE j;
  77.     register UBYTE *bp = (UBYTE *)g;
  78.  
  79. /* Sychronize the computer with the sample stream by waiting for a flag byte */
  80.     while ( (*bp = query_NES()) < U_FLAG_LO) {
  81.         delay(100);        /* delay in uSec */
  82.     }    
  83.  
  84.     bp++;                /* skip past flag byte */
  85.         
  86. /* Now, load the eight sensor values into the Uforce_data buffer */
  87.     for (i = 0; i < 8; i++) {
  88.         while ( (j = query_NES()) == U_SAMPLING)
  89.             printf("*");    /* print aquisition delay indicator */
  90.         *bp++ = j;        /* load sample into buffer */
  91.     }
  92. }
  93.