Ejemplo n.º 1
0
void time_up(utc_time_t *p_time, u32 sec)
{
  utc_time_t temp = *p_time;

  //add second
  if(sec > 0)
  {
    p_time->second = (temp.second + sec) % SECOND_PER_MINUTE;
    sec = (temp.second + sec) / SECOND_PER_MINUTE; //to minute
  }

  //add minute
  if(sec > 0)
  {
    p_time->minute = (temp.minute + sec) % MINUTE_PER_HOUR;
    sec = (temp.minute + sec) / MINUTE_PER_HOUR; //to hour
  }
  
  //add hour
  if(sec > 0)
  {
    p_time->hour = (temp.hour + sec) % HOUR_PER_DAY;
    sec = (temp.hour + sec) / HOUR_PER_DAY;  //to day
    add_day(p_time, sec);
  }
}
int main() try{
	Date today;
	init_day(today, 1978, 6, 25);
	Date tomorrow = today;
	add_day(tomorrow, 1);
	cout << tomorrow;
}
catch (Invalid) {
	error("Invalid date");
}
Ejemplo n.º 3
0
TEST(question1_test4, days_test)
{	
	actual_date.year=2012;
	actual_date.month=12;
	actual_date.day=31;
	add_day(actual_date); //add day
	expected_date.year=2013;
	expected_date.month=1;
	expected_date.day=1;	
	CHECK_DATES(expected_date,actual_date);
}
// *************************************************************************************************
// @fn          clock_tick
// @brief       Add 1 second to system time and to display time
// @param       none
// @return      none
// *************************************************************************************************
void clock_tick(void)
{
	// Use sTime.drawFlag to minimize display updates
	// sTime.drawFlag = 1: second
	// sTime.drawFlag = 2: minute, second
	// sTime.drawFlag = 3: hour, minute
	sTime.drawFlag = 1;

	// Increase global system time
	sTime.system_time++;

	// Add 1 second
	sTime.second++;

	// Add 1 minute
	if (sTime.second == 60)
	{
		sTime.second = 0;
		sTime.minute++;
		sTime.drawFlag++;

		// Add 1 hour
		if (sTime.minute == 60)
		{
			sTime.minute = 0;
			sTime.hour++;
			sTime.drawFlag++;

			// Add 1 day
			if (sTime.hour == 24)
			{
				sTime.hour = 0;
				add_day();
			}
		}
	}

	// Set clock update flag
	display.flag.update_time = 1;
}
Ejemplo n.º 5
0
// *************************************************************************************************
// @fn          clock_tick
// @brief       Add 1 second to system time and to display time
// @param       none
// @return      none
// *************************************************************************************************
void clock_tick(void)
{
	// Use sTime.drawFlag to minimize display updates
	// sTime.drawFlag = 1: second
	// sTime.drawFlag = 2: minute, second
	// sTime.drawFlag = 3: hour, minute
	sTime.drawFlag = 1;

	// Increase global system time
	sTime.system_time++;

	// Add 1 second
	sTime.second++;

	// Add 1 minute
	if (sTime.second == 60)
	{
		sTime.second = 0;
		sTime.minute++;
		sTime.drawFlag++;

		// Add 1 hour
		if (sTime.minute == 60)
		{
			sTime.minute = 0;
			sTime.hour++;
			sTime.drawFlag++;

			// Add 1 day
			if (sTime.hour == 24)
			{
				sTime.hour = 0;
				add_day();
				#ifdef CONFIG_SCHEDULE
				sSchedule.state = SCHEDULE_ENABLED;
				#endif
			}
		}
	}
}
Ejemplo n.º 6
0
// *************************************************************************************************
// @fn          clock_tick
// @brief       Add 1 second to system time and to display time
// @param       none
// @return      none
// *************************************************************************************************
void clock_tick(void)
{
    // Use sTime.drawFlag to minimize display updates
    // sTime.drawFlag = 1: second
    // sTime.drawFlag = 2: minute, second
    // sTime.drawFlag = 3: hour, minute
    sTime.drawFlag = 1;

    // Increase global system time
    sTime.system_time++;

    // Add 1 second
    sTime.second++;

    // Add 1 minute
    if (sTime.second == 60)
    {
        sTime.second = 0;
        sTime.minute++;
        sTime.drawFlag++;

        // Add 1 hour
        if (sTime.minute == 60)
        {
            sTime.minute = 0;
            sTime.hour++;
            sTime.drawFlag++;

            // Add 1 day
            if (sTime.hour == 24)
            {
                sTime.hour = 0;
		if(sday < 180) sday++;//sidereal day offsets
                add_day();
            }
        }
    }
}
Ejemplo n.º 7
0
void f()
{
  Date today;
  init_day(today, 12, 24, 2005);
  add_day(today, 1);
}
Ejemplo n.º 8
0
// *************************************************************************************************
// @fn          clock_tick
// @brief       Add 1 second to system time and to display time
// @param       none
// @return      none
// *************************************************************************************************
void clock_tick(void)
{
    // Use sTime.drawFlag to minimize display updates
    // sTime.drawFlag = 1: second
    // sTime.drawFlag = 2: minute, second
    // sTime.drawFlag = 3: hour, minute
    sTime.drawFlag = 1;

    // Increase global system time
    sTime.system_time++;

    // Add 1 second
    sTime.second++;


    // Add 1 minute
    if (sTime.second == 60)
    {
        sTime.second = 0;
        sTime.minute++;
        sTime.drawFlag++;
        if (buzzer_flag == 1)
        {
        	time_limit++;
        	if (time_limit >= 5)
        	{
        		status_code |= MEDICINE;
        		buzzer_flag = 0;
        		//stop_buzzer();
        	}
        }
        // Add 1 hour
        if (sTime.minute == 60)
        {
            sTime.minute = 0;
            sTime.hour++;
            sTime.drawFlag++;

            // Add 1 day
            if (sTime.hour == 24)
            {
                sTime.hour = 0;
                add_day();
            }
        }
    }

    if (alarm1_hr == sTime.hour ||
    		alarm2_hr == sTime.hour ||
			alarm3_hr == sTime.hour ||
			alarm4_hr == sTime.hour ||
			alarm5_hr == sTime.hour ||
			alarm6_hr == sTime.hour ||
			alarm7_hr == sTime.hour ||
			alarm8_hr == sTime.hour)
    {
		if (alarm1_min == sTime.minute ||
				alarm2_min == sTime.minute ||
				alarm3_min == sTime.minute ||
				alarm4_min == sTime.minute ||
				alarm5_min == sTime.minute ||
				alarm6_min == sTime.minute ||
				alarm7_min == sTime.minute ||
				alarm8_min == sTime.minute)
		{
			//start_buzzer(127, 32767, 32767);
			buzzer_flag = 1;
			time_limit = 0;
		}
    }


    /*u8 alarm1_min = 99;
u8 alarm1_hr = 99;

u8 alarm2_min = 99;
u8 alarm2_hr = 99;

u8 alarm3_min = 99;
u8 alarm3_hr = 99;

u8 alarm4_min = 99;
u8 alarm4_hr = 99;

u8 alarm5_min = 99;
u8 alarm5_hr = 99;

u8 alarm6_min = 99;
u8 alarm6_hr = 99;

u8 alarm7_min = 99;
u8 alarm7_hr = 99;

u8 alarm8_min = 99;
u8 alarm8_hr = 99;
*/


    // verificar se igual a uma das horas da lista e soar buzzer ate que o velho desative


}
Ejemplo n.º 9
0
//++Date
Date& Gregorian::operator++(){
	add_day();
	return *this;
}
Ejemplo n.º 10
0
// *************************************************************************************************
// @fn          clock_tick
// @brief       Add 1 second to system time and to display time
// @param       none
// @return      none
// *************************************************************************************************
void clock_tick(void) 
{
    // Use sTime.drawFlag to minimize display updates
	// sTime.drawFlag = 1: second
	// sTime.drawFlag = 2: minute, second
	// sTime.drawFlag = 3: hour, minute
	sTime.drawFlag = 1;

	// Increase global system time
	sTime.system_time++;

	// Add 1 second
	sTime.second++;
	
	// Add 1 minute
	if (sTime.second == 60)
	{
		// Check Unified Clock System
		check_ucs();
		
		sTime.second = 0;
		sTime.minute++;
		sTime.drawFlag++;

		// Add 1 hour	
		if (sTime.minute == 60)
		{
			sTime.minute = 0;
			sTime.hour++;
			sTime.drawFlag++;

			// Add 1 day
			if (sTime.hour == 24)
			{
				sTime.hour = 0;
				add_day();
				// Check for start of weekly correction midnight between Sunday and Monday
				if(sDate.DayOfWeek == 1) { TimeCorrectionFlag = 2; }  
				// Check for start of daily correction every midnight
				else { TimeCorrectionFlag = 1; }
			    
			    // Check for start of DST (Daylight saving time) correction
			    if(DST_AutoFlag == DST_AUTO)
			    {
			        if (sys.flag.use_metric_units)      // Europe
			        {
			            // Last Sunday in March
			            if((sDate.month == 3) && (sDate.day >= 25) && (sDate.DayOfWeek == 0))
			            {
			                DST_CorrectionFlag = 1;     // Switch to DST during summer
			            }
			            // Last Sunday in October
			            if((sDate.month == 10) && (sDate.day >= 25) && (sDate.DayOfWeek == 0))
			            {
			                DST_CorrectionFlag = 2;     // Switch to normal time during winter
			            }
			        }
			        else    // USA
			        {
			            // Second Sunday in March
			            if((sDate.month == 03) && (sDate.day >= 8) && (sDate.day <= 14) && (sDate.DayOfWeek == 0))
			            {
			                DST_CorrectionFlag = 3;     // Switch to DST during summer
			            }
			            // First Sunday in November
			            if((sDate.month == 11) && (sDate.day <= 7) && (sDate.DayOfWeek == 0))
			            {
			                DST_CorrectionFlag = 4;     // Switch to normal time during winter
			            }
			        }
			    }
			}
		}
	}
    
    // Time correction
    if(TimeCorrectionFlag != 0)
    {
        // Daily correction
        if(TimeCorrectionFlag == 1)
        {
            if((DailyCorr < 0) && (sTime.second == (u8)(DailyCorr * (-1))))
            {
                sTime.second = 0;
                TimeCorrectionFlag = 0;
            }
            if(DailyCorr > 0)
            {
                sTime.second = DailyCorr;
                TimeCorrectionFlag = 0;
            }
            if(DailyCorr == 0){ TimeCorrectionFlag = 0; }
        }
        // Weekly correction
        if(TimeCorrectionFlag == 2)
        {
            s8 WeeklyCorrTmp;
            
            WeeklyCorrTmp = WeeklyCorr + DailyCorr;
            
            if((WeeklyCorrTmp < 0) && (sTime.second == (u8)(WeeklyCorrTmp * (-1))))
            {
                sTime.second = 0;
                TimeCorrectionFlag = 0;
            }
            if(WeeklyCorr > 0)
            {
                sTime.second = (u8)WeeklyCorrTmp;
                TimeCorrectionFlag = 0;
            }
            if(WeeklyCorr == 0) { TimeCorrectionFlag = 0; }
        }
    }

    // DST (Daylight saving time) correction
    if(DST_CorrectionFlag != 0)
    {
        // Europe
        if((DST_CorrectionFlag == 1) && (sTime.hour == 2)) 
        { 
            DST_CorrectionFlag = 0; 
			sTime.hour++;
			sTime.drawFlag = 3;
        }
        if((DST_CorrectionFlag == 2) && (sTime.hour == 3)) 
        { 
            DST_CorrectionFlag = 0; 
			sTime.hour--;
			sTime.drawFlag = 3;
        }
        // USA
        if((DST_CorrectionFlag == 3) && (sTime.hour == 2)) 
        { 
            DST_CorrectionFlag = 0; 
			sTime.hour++;
			sTime.drawFlag = 3;
        }
        if((DST_CorrectionFlag == 4) && (sTime.hour == 2)) 
        { 
            DST_CorrectionFlag = 0; 
			sTime.hour--;
			sTime.drawFlag = 3;
        }
    }

	// Changes the backlight behavior: 
	// A short push of the button activates the backlight for about 4 seconds.
	if(BlOnFlag == 1)
        {
        BlTimeoutCounter++;
	    if(BlTimeoutCounter > 3)
            {
            BlOnFlag = 0;
            BlTimeoutCounter = 0;
//            display_symbol(LCD_ICON_HEART, SEG_ON);
            BUTTONS_DIR &= ~BUTTON_BACKLIGHT_PIN;
            BUTTONS_OUT &= ~BUTTON_BACKLIGHT_PIN;
            BUTTONS_DS &= ~BUTTON_BACKLIGHT_PIN;
            }
        }
 
 // show second on bottom display line but only in DATE menu
 if((ptrMenu_L2 == &menu_L2_Date) && (sDate.display == DISPLAY_ALTERNATIVE_VIEW_4) && (TimeAdjustmentFlag == 0))
 {
    // Display second
    display_chars(LCD_SEG_L2_1_0, itoa(sTime.second, 2, 0), SEG_ON);
 }
 cdtimer_tick();
 random_tick();
 //agility_tick();
 //number_storage_tick();
}