/* 
 * Thomas Pantzer: t_special_counter.cc, v0.4.7  8.6.99 16:32 
 * 
 * 
 * Copyright 1999 by Thomas Pantzer
 * 
 * Permission to use, copy, modify, and distribute this software for noncommercial 
 * use and without fee is hereby granted, provided that the above copyright notice 
 * appear in all copies and that both that copyright notice and this permission 
 * notice appear in supporting documentation, and that the name of the Author not be 
 * used in advertising or publicity pertaining to distribution of the software 
 * without specific, written prior permission. The Author makes no representations about
 * the suitability of this software for any purpose.  It is provided "as is" 
 * without expressed or implied warranty. 
 * 
 * 
 * pantec@isys2.informatik.uni-leipzig.de   (Thomas Pantzer) 
 * 
 */



#include "copyright.h"


#include "t_special_counter.h"




void t_special_counter::Init(unsigned long d, int f, int l)
{
	running = false;
	ticks = 0;
	F = f;
//	sum = d;
//	cnt = 1;

	avg.Init(l);
	avg.Add((double)d);
        
        time = (int)avg.Value(); 	
}


char t_special_counter::Start(char bools)
{
	if (running)
	   return false;

        if (bools)
	   {
	    running = true;
	    ticks = 0;
	    time = (int)(avg.Value() * (double)F);
	    return true;
	   }

        return false;
}

#define not(x)	(!(x))

void t_special_counter::Count(char bools)
{
	if not(running)
	   return;

        if (bools)
	   ticks++;

        if (time > 0)
	   time--;

        if ((time == 0) && (bools == false))
           Stop(); 
}

void t_special_counter::Stop(void)
{
	running = false;
        avg.Add((double)ticks);
//	cnt++;
//	sum += ticks; 
}


void t_special_counter::Done(void)
{
	avg.Done();
}








/**/
/**/
/**/
/**/
/**/
/**/
/**/
/**/
/*****  End Of File  ****************************/
