/****************************************************/
/* Constants and functions for the STOPWATCH module */
/****************************************************/

#ifndef STOPWATCH_LOADED
#include "stopwatch.h"
#endif

#ifndef SIMUL
int HUNDREDTHS_PER_INCREMENT = 25; /* 1/4 seconds */
#endif

/***** The \ZEROSTOPWATCHTIME\ constant *****/

STOPWATCH_TIME_TYPE ZERO_STOPWATCH_TIME = {0, 0, 0};

/***** The printing function for simulation *****/

#if defined SIMUL || defined SIMULRT

char* _STOPWATCH_TIME_TYPE_to_text (st)
STOPWATCH_TIME_TYPE st; {
   static char res[9];
   sprintf (res, "%d:%02d:%02d",
	    st.minutes, st.seconds, st.hundredths);
   return res;
}

#endif

/***** The INCREMENT_STOPWATCH_TIME function *****/

STOPWATCH_TIME_TYPE INCREMENT_STOPWATCH_TIME (st)
STOPWATCH_TIME_TYPE st; {
   st.hundredths += HUNDREDTHS_PER_INCREMENT;
   if (st.hundredths == HUNDREDTHS_PER_SECOND) {
     st.hundredths = 0;
     st.seconds ++;
     if (st.seconds == SECONDS_PER_MINUTE) {
       st.seconds = 0;
       st.minutes ++;
       if (st.minutes == MINUTES_PER_HOUR) 
         st.minutes = 0;
     }
   }
   return st;
}

/***** The STOPWATCH_BEEP function ****/

BEEP_TYPE STOPWATCH_BEEP (st)
STOPWATCH_TIME_TYPE st; {
   return (((st.hundredths == 0) &&
            (st.seconds == 0) &&
            (st.minutes % MINUTES_TO_BEEP == 0))
         ? STOPWATCH_BEEP_VALUE : NO_BEEP_VALUE);
}




