/*  @(#) $Header: $
 *
 * Test Philosophy:
 *    Demonstrate that the state machine cycles clockwise and counter.
 * Author:
 *	Allen Brown  http://brown.armoredpenguin.com/~abrown
 */

#include <stdio.h>
#include <math.h>
#define MAIN
#include "quadrature.h"

int main (void)
{
  int scanfreturn, lineno, returnval;
  char inpline[80];
  int senseintleft, senseintright;
  unsigned char senseleftA, senseleftB, senserightA, senserightB;
  unsigned char quadleftstate=0, quadrightstate=0;
  long ticksleft=0, ticksright=0;
  int error=0, action=0;

  lineno = 0;
  while( NULL !=		// Check if this is the end of the file.
	 (fgets(inpline, sizeof(inpline), stdin))) // Read a line of text
  {
    lineno++;
    // Parse the input line.
    scanfreturn = sscanf(inpline, "%d%d",
			 &senseintleft, &senseintright);
    senseleftA = (unsigned char)(0x02 & senseintleft) >> 1;
    senseleftB = (unsigned char)(0x01 & senseintleft);
    senserightA = (unsigned char)(0x02 & senseintright) >> 1;
    senserightB = (unsigned char)(0x01 & senseintright);
    if( scanfreturn != 2)
    { // Number of scanned vars must match what we expect.
      printf("quadrature_t: wrong # values line %d: '%s'\n", lineno, inpline);
    } else {
      quadrature( &quadleftstate, senseleftA, senseleftB, &ticksleft);
      quadrature( &quadrightstate, senserightA, senserightB, &ticksright);

      //      error = quadrature_error(quadleft);
      returnval=0;
      printf("line %3d: quad %d,%d -> (%x) ticks=(%05ld,%05ld),err=%x.\n",
	     lineno, (senseleftA<<1 | senseleftB), (senserightA<<1 | senserightB), returnval,
	     ticksleft, ticksright, error );
      fflush(stdout);
    } // else
  } // while

  return (0);
} // main
/*
 * $Log: quadrature_t.c,v $
 * Revision 1.11  2006/02/22 00:02:13  abrown
 * Split quadrature_nav functions out of quadrature.c and into navigate.c
 *
 * Revision 1.10  2006/02/21 07:26:55  abrown
 * In quadrature.c, switch from using internal sin/cos to using itrig.c.
 *
 * Revision 1.9  2006/02/20 18:07:48  abrown
 * Change the name quadrature_pair* to quadrature_nav* everywhere.
 *
 * Revision 1.8  2006/02/20 05:46:26  abrown
 * Eliminate any dependency of quadrature* on ifi code.
 *
 * Revision 1.7  2006/02/20 05:04:46  abrown
 * Write the quadrature_pair_* functions for navigation.
 *
 * Revision 1.6  2006/02/04 23:20:00  abrown
 * Don't check pulses, only distance.  Change calibration value to
 * correspond to the new calculation in quadrature_distance().
 *
 * Revision 1.5  2006/02/04 22:00:54  abrown
 * Even tho there is no malloc in MPLab I am able to simulate it in
 * quadrature_new() using a static array.  This eliminates
 * quadrature_new_1() and quadrature_new_2(), which were ugly warts.
 *
 * Revision 1.4  2006/01/30 00:39:57  abrown
 * Make the sense inputs bytes plus a separate number to indicate which bit.
 *
 * Revision 1.3  2006/01/28 00:30:31  abrown
 * Fix quadrature and its test.  It works now.
 *
 * Revision 1.2  2006/01/27 01:21:44  abrown
 * Make the tests actually test against a reference.
 *
 * Revision 1.1  2006/01/27 00:24:28  abrown
 * Add quadrature.
 *
 */

