Ejemplo n.º 1
0
Archivo: date.c Proyecto: amd989/ezTOTP
// *************************************************************************************************
// @fn          add_day
// @brief       Add one day to current date. Called when clock changes from 23:59 to 00:00
// @param       none
// @return      none
// *************************************************************************************************
void add_day(void)
{
    // Add 1 day
    sDate.day++;

    // Check if day overflows into next month
    if (sDate.day > get_numberOfDays(sDate.month, sDate.year))
    {
        // Add 1 month and reset to day to 1
        sDate.day = 1;
        sDate.month++;

        // Check if month overflows into next year
        if (sDate.month > 12)
        {
            // Add 1 year and reset month and day to 1
            sDate.day = 1;
            sDate.month = 1;
            sDate.year++;
        }
    }

    // Indicate to display function that new value is available
    display.flag.full_update = 1;
}
Ejemplo n.º 2
0
Archivo: date.c Proyecto: amd989/ezTOTP
// *************************************************************************************************
// @fn          mx_date
// @brief       Date set routine.
// @param       line            LINE1, LINE2
// @return      none
// *************************************************************************************************
void mx_date(u8 line)
{
    u8 select;
    s32 day;
    s32 month;
    s32 year;
    s16 max_days;
    u8 *str;
    u8 *str1;

    // Clear display
    clear_display_all();

    // Convert global to local variables
    day = sDate.day;
    month = sDate.month;
    year = sDate.year;

    // Init value index
    select = 0;

    // Init display
    // LINE1: DD.MM (metric units) or MM.DD (English units)
    // LINE2: YYYY (will be drawn by set_value)

    if (sys.flag.use_metric_units)
    {
        str = int_to_array(day, 2, 0);
        display_chars(LCD_SEG_L1_3_2, str, SEG_ON);

        str1 = int_to_array(month, 2, 0);
        display_chars(LCD_SEG_L1_1_0, str1, SEG_ON);
    }
    else                        // English units
    {
        str = int_to_array(day, 2, 0);
        display_chars(LCD_SEG_L1_1_0, str, SEG_ON);

        str1 = int_to_array(month, 2, 0);
        display_chars(LCD_SEG_L1_3_2, str1, SEG_ON);
    }
    display_symbol(LCD_SEG_L1_DP1, SEG_ON);

    // Loop values until all are set or user breaks set
    while (1)
    {
        // Idle timeout: exit without saving
        if (sys.flag.idle_timeout)
            break;

        // Button STAR (short): save, then exit
        if (button.flag.star)
        {
            // Copy local variables to global variables
            sDate.day = day;
            sDate.month = month;
            sDate.year = year;

            // Full display update is done when returning from function
            break;
        }

        switch (select)
        {
            case 0:            // Set year
                set_value(&year, 4, 0, 2008, 2100, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE,
                          LCD_SEG_L2_3_0,
                          display_value);
                select = 1;
                break;
            case 1:            // Set month
                if (sys.flag.use_metric_units)
                {
                    set_value(
                        &month, 2, 0, 1, 12, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE +
                        SETVALUE_NEXT_VALUE, LCD_SEG_L1_1_0, display_value);
                }
                else           // English units
                {
                    set_value(
                        &month, 2, 0, 1, 12, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE +
                        SETVALUE_NEXT_VALUE, LCD_SEG_L1_3_2, display_value);
                }
                select = 2;
                break;
            case 2:            // Set day
                if (sys.flag.use_metric_units)
                {
                    set_value(
                        &day, 2, 0, 1, max_days, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE +
                        SETVALUE_NEXT_VALUE, LCD_SEG_L1_3_2, display_value);
                }
                else           // English units
                {
                    set_value(
                        &day, 2, 0, 1, max_days, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE +
                        SETVALUE_NEXT_VALUE, LCD_SEG_L1_1_0, display_value);
                }
                select = 0;
                break;
        }

        // Check if day is still valid, if not clamp to last day of current month
        max_days = get_numberOfDays(month, year);
        if (day > max_days)
            day = max_days;
    }

    // Clear button flag
    button.all_flags = 0;
}
Ejemplo n.º 3
0
// *************************************************************************************************
// @fn          mx_date
// @brief       Date set routine.
// @param       line		LINE1, LINE2
// @return      none
// *************************************************************************************************
void mx_date(line_t line)
{
#ifdef CONFIG_USE_SYNC_TOSET_TIME
	return;
#else
	u8 select;
	s32 day;
	s32 month;
	s32 year;
	s16 max_days;
	u8 * str;
			
	// Clear display
	clear_display_all();
			
	// Convert global to local variables
	day 	= sDate.day;
	month 	= sDate.month;
	year 	= sDate.year;
		
	// Init value index
	select = 0;	
	
	// Init display
	// LINE1: YYYY (will be drawn by set_value)
	// LINE2: MM  DD
	
	str = _itoa(day, 2, 1);
	display_chars(LCD_SEG_L2_1_0, str, SEG_ON);

	str = _itoa(month, 2, 1);
	display_chars(LCD_SEG_L2_5_4, str, SEG_ON);

	// Loop values until all are set or user breaks	set
	while(1) 
	{
		// Idle timeout: exit without saving 
		if (sys.flag.idle_timeout) break;

		// Button STAR (short): save, then exit 
		if (button.flag.star) 
		{
			// Copy local variables to global variables
			sDate.day = day;
			sDate.month = month;
			sDate.year = year;
			#ifdef CONFIG_SIDEREAL
			if(sSidereal_time.sync>0)
				sync_sidereal();
			#endif
            #if (CONFIG_DST > 0)
            dst_calculate_dates();
            #endif
			
			// Full display update is done when returning from function
			break;
		}

		switch (select)
		{
			case 0:		// Set year
						set_value(&year, 4, 0, 2008, 2100, SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L1_3_0, display_value1);
						select = 1;
						break;
			case 1:		// Set month
						set_value(&month, 2, 1, 1, 12, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_5_4, display_value1);
						select = 2;
						break;
			case 2:		// Set day
						set_value(&day, 2, 1, 1, max_days, SETVALUE_ROLLOVER_VALUE + SETVALUE_DISPLAY_VALUE + SETVALUE_NEXT_VALUE, LCD_SEG_L2_1_0, display_value1);
						select = 0;
						break;
		}
		
		// Check if day is still valid, if not clamp to last day of current month
		max_days = get_numberOfDays(month, year);
		if (day > max_days) day = max_days;
	}
	
	// Clear button flag
	button.all_flags = 0;
#endif
}
Ejemplo n.º 4
0
// *************************************************************************************************
// @fn          display_date
// @brief       Display date in DD.MM format (metric units) or MM.DD (English units).
// @param       line_t line			LINE1, LINE2
//				update_t update		DISPLAY_LINE_UPDATE_FULL, DISPLAY_LINE_UPDATE_PARTIAL
// @return      none
// *************************************************************************************************
void display_date(line_t line, update_t update)
{
#ifdef CONFIG_DAY_OF_WEEK
	const u8 weekDayStr[7][3] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
#endif
	u8 * str;
	
	if (update == DISPLAY_LINE_UPDATE_FULL)
	{
		switch (sDate.view)
		{
			case 0: //WWW.DD
				// Convert day to string
#ifdef CONFIG_DAY_OF_WEEK
				str = _itoa(sDate.day, 2, 1);
				display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);

				//pfs BEGIN replace year display with day of week
				//pfs algorith from http://klausler.com/new-dayofweek.html
				#define BASE_YEAR 2001 // not a leap year, so no need to add 1
				u8 skew;
				skew = (sDate.year - BASE_YEAR)+(sDate.year - BASE_YEAR)/4; // compute number of leap years since BASE_YEAR
				if ((29 == get_numberOfDays(2, sDate.year)) && (sDate.month < 3))
				  skew--; // if this is a leap year but before February 29
				skew = (skew + sDate.day); // add day of current month
				//add this month's skew value
				switch(sDate.month) {
				  case 5:
					skew += 1;
					break;
				  case 8:
					skew += 2;
					break;
				  case 2:
				  case 3:
				  case 11:
					skew += 3;
					break;
				  case 6:
					skew += 4;
					break;
				  case 9:
				  case 12:
					skew += 5;
					break;
				  case 4:
				  case 7:
					skew += 6;
					break;
				  default:  //January and October
					break;
				}
				skew = skew%7;
				str = (u8 *)weekDayStr[skew];
				display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_4_2), str, SEG_ON);
				display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
				break;
#else
				// skip this view
				sDate.view++;
#endif
			case 1: //MM  DD
				// Convert day to string
				display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
				// display date
#ifndef CONFIG_METRIC_ONLY
				if (!sys.flag.use_metric_units) {
					str = _itoa(sDate.day, 2, 0);
					display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);

					// Convert month to string
					str = _itoa(sDate.month, 2, 1);
					display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
				} else {
#else
				if (1) {
#endif
					str = _itoa(sDate.day, 2, 0);
					display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
					
					str = _itoa(sDate.month, 2, 0);
					display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);
				}
				break;
			case 2: //YYYY
				// Convert year to string
				str = _itoa(sDate.year, 4, 0);
				display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_3_0), str, SEG_ON);
				break;
			default:
				display_time(line, update);
				break;
		}
	}
	else if	(update == DISPLAY_LINE_UPDATE_PARTIAL)
	{
		if ((sDate.view == 3) || (display.flag.update_date))
			display_date(line, DISPLAY_LINE_UPDATE_FULL);
	}
	else if (update == DISPLAY_LINE_CLEAR)
	{
		// Do some display cleanup (or just do nothing if everything is OK)
		// This is NOT ONLY called on switch to next menu item
	}	
}
Ejemplo n.º 5
0
// *************************************************************************************************
// @fn          display_date
// @brief       Display date in DD.MM format (metric units) or MM.DD (English units).
// @param       u8 line                 LINE1, LINE2
//                              u8 update               DISPLAY_LINE_UPDATE_FULL,
// DISPLAY_LINE_UPDATE_PARTIAL
// @return      none
// *************************************************************************************************
void display_date(u8 line, u8 update)
{
#ifdef CONFIG_DAY_OF_WEEK
	const u8 weekDayStr[7][3] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
#endif
    u8 *str;

    if (update == DISPLAY_LINE_UPDATE_FULL)
    {
        switch (sDate.display)
		{
			case DISPLAY_DEFAULT_VIEW: //WWW.DD
				// Convert day to string
#ifdef CONFIG_DAY_OF_WEEK
				str = int_to_array(sDate.day, 2, 1);
				display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);

				//pfs BEGIN replace year display with day of week
				//pfs algorith from http://klausler.com/new-dayofweek.html
				#define BASE_YEAR 2001 // not a leap year, so no need to add 1
				u8 skew;
				skew = (sDate.year - BASE_YEAR)+(sDate.year - BASE_YEAR)/4; // compute number of leap years since BASE_YEAR
				if ((29 == get_numberOfDays(2, sDate.year)) && (sDate.month < 3))
				  skew--; // if this is a leap year but before February 29
				skew = (skew + sDate.day); // add day of current month
				//add this month's skew value
				switch(sDate.month) {
				  case 5:
					skew += 1;
					break;
				  case 8:
					skew += 2;
					break;
				  case 2:
				  case 3:
				  case 11:
					skew += 3;
					break;
				  case 6:
					skew += 4;
					break;
				  case 9:
				  case 12:
					skew += 5;
					break;
				  case 4:
				  case 7:
					skew += 6;
					break;
				  default:  //January and October
					break;
				}
				skew = skew%7;
				str = (u8 *)weekDayStr[skew];
				display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_4_2), str, SEG_ON);
				display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
				break;
#else
		               // Convert day to string
			        str = int_to_array(sDate.day, 2, 0);
			#ifndef CONFIG_METRIC_ONLY
			        if (sys.flag.use_metric_units)
		                {
			#endif
			                display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
			#ifndef CONFIG_METRIC_ONLY
		                }
		                else
			        {
			                display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);
		                }
			#endif

		               // Convert month to string
		               str = int_to_array(sDate.month, 2, 0);
			#ifndef CONFIG_METRIC_ONLY
		              if (sys.flag.use_metric_units)
		              {
			                display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);
		              }
        		      else
	                      {
			                display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
		              }
			#else
		              display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);
#endif //CONFIG_METRIC_ONLY

            // Display "." to separate day and month
		              display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
			      break;
#endif //CONFIG_DAY_OF_WEEK
            case DISPLAY_ALTERNATIVE_VIEW: //MM  DD
#ifdef CONFIG_DAY_OF_WEEK
		// Convert day to string
		display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_ON);
		// display date
		#ifndef CONFIG_METRIC_ONLY
		if (!sys.flag.use_metric_units) {
			str = int_to_array(sDate.day, 2, 0);
			display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);

			// Convert month to string
			str = int_to_array(sDate.month, 2, 1);
			display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
		} 
		else 
		#else
		if (1) 
		#endif //CONFIG_METRIC_ONLY
		{
			str = int_to_array(sDate.day, 2, 0);
			display_chars(switch_seg(line, LCD_SEG_L1_3_2, LCD_SEG_L2_3_2), str, SEG_ON);
					
			str = int_to_array(sDate.month, 2, 0);
			display_chars(switch_seg(line, LCD_SEG_L1_1_0, LCD_SEG_L2_1_0), str, SEG_ON);
		}
		break;
	    case DISPLAY_ALTERNATIVE2_VIEW: //YYYY
#endif //CONFIG_DAY_OF_WEEK
			// Convert year to string
			str = int_to_array(sDate.year, 4, 0);
			display_chars(switch_seg(line, LCD_SEG_L1_3_0, LCD_SEG_L2_3_0), str, SEG_ON);
	
			// Clear "."
	                display_symbol(switch_seg(line, LCD_SEG_L1_DP1, LCD_SEG_L2_DP), SEG_OFF);
		break;
		default:
			display_time(line, update);
			break;
	}
    }
    else if (update == DISPLAY_LINE_CLEAR)
    {
        // Show day and month on display when coming around next time
        sDate.display = DISPLAY_DEFAULT_VIEW;
    }
}