
/********************* Function Prototypes *******************/

void test_func(
void data_cycle(void);
void setup(void);

/*********************** Global Variables *********************/

long g_sample;
short sample_buf[10000];

/*********************************************************************************
	main
*******************************************************************************/
void main(void){
  char menukey;

  InitTT8(NO_WATCHDOG, TT8_TPU);   /* setup Model 8 for running C programs */
  TPUSetPin(0, 0);
  SimSetFSys(320000);           /* Slow down system clock */
  SerSetBaud(9600, 0);          /* Reset the baud rate */

  while(1)
  {

    printf("\n\n\nH2O Strobe Test Main Menu V1.1");
    printf("\n1 -- Log Data");
    printf("\n2 -- Offload Data");
    printf("\n9 -- Reset");

    QueryChar("\n\nEnter Selection: ", '0', "123459", &menukey);


    switch(menukey)
    {
      case '1':
	    data_cycle();
	    break;

      case '2':
	    offload_data();
	    break;

      case '9':
	    bc_reset();
	    break;
    }
  }


}	/* main() */


/***************************************************/

void data_cycle(void){
  ulong sample_time, next_sample_time;

  SerInFlush();
  sample_period = 180;   /* Period in secs */
  next_sample_time = time(0);
  printf("\nRunning...\n");

  while(1)
  {

  	g_sample++;
    if( g_sample >= 10000 ) return;

    next_sample_time += sample_period;
    while( time(0) <= next_sample_time )
    {
      delaysecs(1);
      if(SerByteAvail()) return;
    }
  }

  return;

}  /* End data_cycle() */


/***************************************************/

void offload_data(void)
{
	for(x=0; x<g_sample; x++)
	{
		printf("\n%d   %d", g_sample, sample_buf);
	}
}


/*********************************************/

void delaysecs(unsigned long delay_time)
{

  delay_time *= 1000;
  DelayMilliSecs(delay_time);
  return;
}

