/*  @(#) $Header: $
 *
 * Test Philosophy:
 *    Demonstrate that the toggle has hysterisis and cycles
 *    thru its states.
 * Author:
 *	Allen Brown  http://brown.armoredpenguin.com/~abrown
 */

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

int main (void)
{
  int scanfreturn, lineno, returnval;
  char inpline[80];
  int command, togglemax, toggledelay, toggleimmediate, togglebutton;
  int instate, outstate;

  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, "%x%d%d%d%d",
			 &command,
			 &togglemax,
			 &toggledelay,
			 &toggleimmediate,
			 &togglebutton);
    if( scanfreturn != 5)
    { // Number of scanned vars must match what we expect.
      printf("toggleswitch_t: wrong # values line %d: '%s', %d.\n",
	     lineno, inpline, scanfreturn);
    } else {
      if( command )
	{
	  toggleswitch_init(&outstate,
			    (unsigned char)togglemax,
			    (unsigned char)toggledelay,
			    (unsigned char)toggleimmediate,
			    (unsigned char)togglebutton);
	  returnval = togglemax;
	  instate = outstate;
	} else {
	  instate = outstate;
	  returnval=toggleswitch(&outstate,
			     (unsigned char)togglemax,
			     (unsigned char)toggledelay,
			     (unsigned char)toggleimmediate,
			     (unsigned char)togglebutton);
	}

      printf("line %3d: tog(0x%04x,%d,%d,%d,%d) -> (0x%04x,,,) -> %d.\n",
	     lineno, (int)instate,
	     togglemax,
	     toggledelay,
	     toggleimmediate,
	     togglebutton,
	     (int)outstate, returnval);
      fflush(stdout);
    } // else
  } // while

  return (0);
} // main
/*
 * $Log: toggleswitch_t.c,v $
 *
 */

