Пример #1
0
void Time_Adj_S(BOOL direction)
{
	BYTE seconds, bcd10, bcd;
	
	Time_Pause(TRUE);
	Rtc_ReadFromRtc();

	bcdToDec(datetime._00h.bits.seconds10, datetime._00h.bits.seconds, &seconds);

	if(direction == TIME_UP)
	{
		if(seconds < 59) seconds++;
		else seconds = 0;
	}
	else
	{
		if(seconds > 0) seconds--;
		else seconds = 59;
	}

	decToBcd(&bcd10, &bcd, seconds);

	datetime._00h.bits.seconds = bcd;
	datetime._00h.bits.seconds10 = bcd10;

	Rtc_WriteToRtc();
	Time_Pause(FALSE);
}
Пример #2
0
void Time_Adj_Mi(BOOL direction)
{
	BYTE minutes, bcd10, bcd;

	Time_Pause(TRUE);
	Rtc_ReadFromRtc();

	bcdToDec(datetime._01h.bits.minutes10, datetime._01h.bits.minutes, &minutes);

	if(direction == TIME_UP)
	{
		if(minutes < 59) minutes++;
		else minutes = 0;
	}
	else
	{
		if(minutes > 0) minutes--;
		else minutes = 59;
	}

	decToBcd(&bcd10, &bcd, minutes);

	datetime._01h.bits.minutes = bcd;
	datetime._01h.bits.minutes10 = bcd10;

	Rtc_WriteToRtc();
	Time_Pause(FALSE);
}
Пример #3
0
void Time_Adj_1224hrs(BOOL h12)
{
	BYTE hours, bcd10, bcd;

	Time_Pause(TRUE);
	Rtc_ReadFromRtc();

	if(datetime._02h.bits_24hrs._1224hr != h12)
	{
		if(h12)
		{
			// Convert from 24h to 12h
			bcdToDec(datetime._02h.bits_24hrs.hours10, datetime._02h.bits_24hrs.hours, &hours);
			if(hours >= 12)
			{
				datetime._02h.bits_ampm.ampm = 1;
				if(hours > 12) hours -= 12;
			}
			else
			{
				datetime._02h.bits_ampm.ampm = 0;
				if(hours == 0) hours = 12;
			}
			decToBcd(&bcd10 , &bcd, hours);
			datetime._02h.bits_ampm.hours10 = bcd10;
			datetime._02h.bits_ampm.hours = bcd;
		}
		else
		{
			// Convert from 12h to 24h
			bcdToDec(datetime._02h.bits_ampm.hours10, datetime._02h.bits_ampm.hours, &hours);
			if(datetime._02h.bits_ampm.ampm == 1 && hours != 12)
			{
				hours += 12;
			}
			else if(datetime._02h.bits_ampm.ampm == 0 && hours == 12)
			{
				hours = 0;
			}
			decToBcd(&bcd10 , &bcd, hours);
			datetime._02h.bits_24hrs.hours10 = bcd10;
			datetime._02h.bits_24hrs.hours = bcd;
		}
	}

	datetime._02h.bits_24hrs._1224hr = h12;

	Rtc_WriteToRtc();
	Time_Pause(FALSE);
}
Пример #4
0
/**
  * @brief  Reset Chrono to zero.
  * @param  None.
  * @retval None.
  */
void Time_ResetMenu(void)
{
  LCD_SetCursorPos(LCD_LINE1, 0);
  LCD_Print(" Reset Chrono ? ");
  LCD_SetCursorPos(LCD_LINE2, 0);
  LCD_Print("<No        Yes>");

  /* Endless loop */
  while (1)
  {
    /* Check which key is pressed */
    Key = ReadJoystick();

    /* If "RIGHT" pushbutton is pressed */
    if (Key == JOY_RIGHT)
    {
      Time_Reset();

      Time_Pause();

      Restore_LastDisplay() ;
      /* Exit */
      return ;
    }

    /* If "LEFT" pushbutton is pressed */
    if (Key == JOY_LEFT)
    {
      Restore_LastDisplay() ;
      /* Exit */
      return ;
    }

  }
}
Пример #5
0
void Time_Adj_Y(BOOL direction)
{
	BYTE date, month, year, bcd10, bcd;

	Time_Pause(TRUE);
	Rtc_ReadFromRtc();

	bcdToDec(datetime._04h.bits.date10, datetime._04h.bits.date, &date);
	bcdToDec(datetime._05h.bits.month10, datetime._05h.bits.month, &month);
	bcdToDec(datetime._06h.bits.year10, datetime._06h.bits.year, &year);

	bcd10 = datetime._06h.bits.year10;
	bcd = datetime._06h.bits.year;

	if(direction == TIME_UP)
	{
		year++;
		if(isValidDate(date, month, year))
		{
			decToBcd(&bcd10, &bcd, year);
		}
	}
	else
	{
		year--;
		if(isValidDate(date, month, year))
		{
			decToBcd(&bcd10, &bcd, year);
		}
	}

	datetime._06h.bits.year10 = bcd10;
	datetime._06h.bits.year = bcd;

	Rtc_WriteToRtc();
	Time_Pause(FALSE);
}
Пример #6
0
/////////////////////////////
// Draw_Loop
//
// Loops updating the game window.
void Draw_Loop(void (*proc)(void *data), void (*draw)(void *data, float f),
			   void *data) {

	_proc_func = proc;
	_draw_func = draw;
	_data = data;
	if (_draw_looping) {
		return;
	}
	_draw_looping = 1;
#ifndef EMSCRIPTEN
	long long procTime1, procTime2, drawTime1, drawTime2;
	_accTime = proc_t_frame;
	procTime1 = drawTime1 = Time_GetTime();
	while (Draw_LoopIteration()) {

		// Wait to round draw_t_frame
		drawTime2 = Time_GetTime();
		Time_Pause(draw_t_frame - (drawTime2 - drawTime1));
		drawTime2 = Time_GetTime();
		drawTime1 = drawTime2;

		// Update time
		procTime2 = Time_GetTime();
		_accTime += procTime2 - procTime1;
		procTime1 = procTime2;
	}
#else
	_accTime = proc_t_frame;
	_procTime1 = Time_GetTime();
	if (_fps <= 50) {
		emscripten_set_main_loop(Draw_LoopIterationAux, _fps, 1);
	} else {
		emscripten_set_main_loop(Draw_LoopIterationAux, 0, 1);
	}
#endif
}
Пример #7
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
void main(void)
{
  /* Enable LSE */
  CLK_LSEConfig(CLK_LSE_ON);
  /* Wait for LSE clock to be ready */
  while (CLK_GetFlagStatus(CLK_FLAG_LSERDY) == RESET);
  
  /* wait for 1 second for the LSE Stabilisation */
  Delay_Seconds(1);

  /* Select LSE (32.768 KHz) as RTC clock source */
  CLK_RTCClockConfig(CLK_RTCCLKSource_LSE, CLK_RTCCLKDiv_1);
  CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);

  /*RTC Tamper Configuration*/
  Tamper_Init();

  /* Calendar Configuration */
  Calendar_Init();

  /* EvalBoard Configuration */
  EvalBoard_Init();

  /* RTC Time fields reset*/
  Time_Reset();

  /* RTC Time pause waiting for a press on SEL Key */
  Time_Pause();

  while (1)
  {
    EnterSafeCode();
    Time_Show(LCD_LINE2);
    ExitSafeCode();
  }
}
Пример #8
0
void Time_Adj_H(BOOL direction)
{
	BYTE hours, bcd10, bcd, minVal, maxVal;
	BOOL h12;

	Time_Pause(TRUE);
	Rtc_ReadFromRtc();

	h12 = datetime._02h.bits_24hrs._1224hr;

	// Check if ampm or 24h
	if(h12)
	{
		//12 hrs
		bcdToDec(datetime._02h.bits_ampm.hours10, datetime._02h.bits_ampm.hours, &hours);
		maxVal = 12;
		minVal = 1;
	}
	else
	{
		//24 hrs
		bcdToDec(datetime._02h.bits_24hrs.hours10, datetime._02h.bits_24hrs.hours, &hours);
		maxVal = 23;
		minVal = 0;
	}


	if(direction == TIME_UP)
	{
		if(hours < maxVal) hours++;
		else 
		{
			hours = minVal;
			if(h12) datetime._02h.bits_ampm.ampm = !datetime._02h.bits_ampm.ampm;
		}
	}
	else
	{
		if(hours > minVal) hours--;
		else 
		{
			hours = maxVal;
			if(h12) datetime._02h.bits_ampm.ampm = !datetime._02h.bits_ampm.ampm;
		}
	}

	decToBcd(&bcd10, &bcd, hours);

	if(h12)
	{
		datetime._02h.bits_ampm.hours = bcd;
		datetime._02h.bits_ampm.hours10 = bcd10;
	}
	else
	{
		datetime._02h.bits_24hrs.hours = bcd;
		datetime._02h.bits_24hrs.hours10 = bcd10;
	}
	
	Rtc_WriteToRtc();
	Time_Pause(FALSE);
}