/* 
stopwatch.c: Use T2_StopWatch .

Compiler: BC++ 3.1, 
          Turbo C ++ 1.01(3.01) (free from http://community.borland.com/museum)
          MSC 6.0,
          MSVC 1.52.

Compile mode: Large

Project: stopwatch.c
         ..\..\Lib\(8000E.Lib,7188XAL.Lib,7188XBL.Lib,7188XCL.Lib or 7188EL.Lib)    
                                                                               
Hardware: 7188/8000

Note: Function used:
      
    T2_UpdateCurrentTimeTicks() --> To update the T2_StopWatchGetTime value
    		                    It must be called to get new *TimeTicks value every loop
    T2_StopWatchStart(&sw[N])  --> Start or reset Stopwatch, 
    Timer[0] ~ Timer [N]  --> User decides to use N StopWatch, and the timer is defined by user      
    value[N]=T2_StopWatchGetTime(&sw[N]) --> To read the StopWatch value 
		                             The T2_UpdateCurrentTimeTicks() function needs 
	                                     to be called to update the value
      

[10/Apr/2008] compiled by Hans
*/

#include<stdio.h>
#include "..\..\lib\vp2k.h"   

void main(void)
{
    int i;
    long Timer[10];
    unsigned long value[10];
    STOPWATCH sw[10]; 
    int quit=0;
    unsigned long beginTime,Gtime;
        
    InitLib(); //MUST CALL InitLib() first before use 8000 library 
    
    
    //Users define the necessary interval time 
    Timer[0]=1900;
    Timer[1]=2500;
    Timer[2]=3300;
    Timer[3]=4500;
    Timer[4]=8000;
    Timer[5]=3900;
    Timer[6]=10000;
       
    Print("\n\rTest StopWatch ...");    
    Print("\n\rPress 'q' to quit\n\r");
    
    //For first time, clear StopWatch value
    T2_UpdateCurrentTimeTicks();
    for(i=0;i<7;i++)
        T2_StopWatchStart(&sw[i]);       
        
    beginTime=GetTimeTicks(); //Begin the Global time
    while(!quit)
    {
        if(Kbhit())
        {
            switch(Getch())
            {
                case 'q':
                    quit=1;
                break;
            }
        }
        T2_UpdateCurrentTimeTicks(); //Update the T2_StopWatchGetTime value  
        value[0]=T2_StopWatchGetTime(&sw[0]); //Read the StopWatch value    
        //Print the Global time, the StopWatch interval time and Reset StopWatch         
        if(value[0]>=Timer[0])
        {
            Gtime=GetTimeTicks()-beginTime; //Count the Global time
            T2_StopWatchStart(&sw[0]); //Reset StopWatch
            Print("Timeticks[%lu], Fun0 [interval=%04lu] finished and reset \n",Gtime,value[0]);            
        }
        
        T2_UpdateCurrentTimeTicks();
        value[1]=T2_StopWatchGetTime(&sw[1]);
        if(value[1]>=Timer[1])
        {
        	Gtime=GetTimeTicks()-beginTime;
            T2_StopWatchStart(&sw[1]);
            Print("Timeticks[%lu], Fun1 [interval=%04lu] finished and reset \n",Gtime,value[1]);
        }
        
        T2_UpdateCurrentTimeTicks();
        value[2]=T2_StopWatchGetTime(&sw[2]);    
        if(value[2]>=Timer[2])
        {	
        	Gtime=GetTimeTicks()-beginTime;
            T2_StopWatchStart(&sw[2]);
            Print("Timeticks[%lu], Fun2 [interval=%04lu] finished and reset \n",Gtime,value[2]);
            
        }
        
        T2_UpdateCurrentTimeTicks();
        value[3]=T2_StopWatchGetTime(&sw[3]);
        if(value[3]>=Timer[3])
        {	
        	Gtime=GetTimeTicks()-beginTime;
            T2_StopWatchStart(&sw[3]);
            Print("Timeticks[%lu], Fun3 [interval=%04lu] finished and reset \n",Gtime,value[3]);
        }
        
        T2_UpdateCurrentTimeTicks();
        value[4]=T2_StopWatchGetTime(&sw[4]);
        if(value[4]>=Timer[4])
        {	
        	Gtime=GetTimeTicks()-beginTime;
            T2_StopWatchStart(&sw[4]);
            Print("Timeticks[%lu], Fun4 [interval=%04lu] finished and reset \n",Gtime,value[4]);
        }
        
        T2_UpdateCurrentTimeTicks();
        value[5]=T2_StopWatchGetTime(&sw[5]);
        if(value[5]>=Timer[5])
        {	
        	Gtime=GetTimeTicks()-beginTime;
            T2_StopWatchStart(&sw[5]);
            Print("Timeticks[%lu], Fun5 [interval=%04lu] finished and reset \n",Gtime,value[5]);
        }
        
        T2_UpdateCurrentTimeTicks();
        value[6]=T2_StopWatchGetTime(&sw[6]);
        if(value[6]>=Timer[6])
        {	
        	Gtime=GetTimeTicks()-beginTime;
            T2_StopWatchStart(&sw[6]);
            Print("Timeticks[%lu], Fun6 [interval=%04lu] finished and reset \n",Gtime,value[6]);
        }               
         
    }    
}

