void set_time(void) { uint8_t mode = init_set_menu(2); uint8_t hour, min, sec; hour = time_h; min = time_m; sec = time_s; while (!check_timeout()) { if (just_pressed & 0x2) { just_pressed = 0; screenmutex++; if (mode == SET_TIME) { DEBUG(putstring("Set time hour")); // ok now its selected mode = SET_HOUR; // display instructions below print_menu_opts("change hr","set hour"); } else if (mode == SET_HOUR) { DEBUG(putstring("Set time min")); mode = SET_MIN; // display instructions below print_menu_opts("change min","set mins"); } else if (mode == SET_MIN) { DEBUG(putstring("Set time sec")); mode = SET_SEC; // display instructions below print_menu_opts("change sec","set secs"); } else { // done! DEBUG(putstring("done setting time")); mode = SET_TIME; // display instructions below print_menu_advance(); writei2ctime(sec, min, hour, 0, date_d, date_m, date_y); time_h = hour; time_m = min; time_s = sec; } print_time(hour,min,sec,mode); screenmutex--; } // was easter egg if ((just_pressed & 0x4) || (pressed & 0x4)) { just_pressed = 0; screenmutex++; if (mode == SET_HOUR) { hour = (hour+1) % 24; time_h = hour; } if (mode == SET_MIN) { min = (min+1) % 60; } if (mode == SET_SEC) { sec = (sec+1) % 60; } print_time(hour,min,sec,mode); screenmutex--; if (pressed & 0x4) delay_ms(200); } } }
void set_date(void) { uint8_t mode = SET_DATE; uint8_t day, month, year; day = date_d; month = date_m; year = date_y; display_menu(); screenmutex++; // put a small arrow next to 'set date' drawArrow(0, 27, MENU_INDENT -1); screenmutex--; timeoutcounter = INACTIVITYTIMEOUT; while (1) { if (just_pressed & 0x1) { // mode change return; } if (just_pressed || pressed) { timeoutcounter = INACTIVITYTIMEOUT; // timeout w/no buttons pressed after 3 seconds? } else if (!timeoutcounter) { //timed out! displaymode = SHOW_TIME; return; } if (just_pressed & 0x2) { just_pressed = 0; screenmutex++; if ((mode == SET_DATE) && ((region == REGION_US) || (region == DOW_REGION_US) || (region == DATELONG) || (region == DATELONG_DOW))) { DEBUG(putstring("Set date month")); // ok now its selected mode = SET_MONTH; // print the month inverted print_date(month,day,year,mode); // display instructions below displaySetAddress(0, 6); displayPutStr("Press + to change mon", NORMAL); displaySetAddress(0, 7); displayPutStr("Press SET to set mon.", NORMAL); } else if ((mode == SET_DATE) && ((region == REGION_EU) || (region == DOW_REGION_EU))) { DEBUG(putstring("Set date month")); // ok now its selected mode = SET_DAY; // print the day inverted print_date(month,day,year,mode); // display instructions below displaySetAddress(0, 6); displayPutStr("Press + to change day", NORMAL); displaySetAddress(0, 7); displayPutStr("Press SET to set date", NORMAL); } else if ((mode == SET_MONTH) && ((region == REGION_US) || (region == DOW_REGION_US) || (region == DATELONG) || (region == DATELONG_DOW))) { DEBUG(putstring("Set date day")); mode = SET_DAY; print_date(month,day,year,mode); // display instructions below displaySetAddress(0, 6); displayPutStr("Press + to change day", NORMAL); displaySetAddress(0, 7); displayPutStr("Press SET to set date", NORMAL); }else if ((mode == SET_DAY) && ((region == REGION_EU) || (region == DOW_REGION_EU))) { DEBUG(putstring("Set date month")); mode = SET_MONTH; print_date(month,day,year,mode); // display instructions below displaySetAddress(0, 6); displayPutStr("Press + to change mon", NORMAL); displaySetAddress(0, 7); displayPutStr("Press SET to set mon.", NORMAL); } else if ( ((mode == SET_DAY) && ((region == REGION_US) || (region == DOW_REGION_US) || (region == DATELONG) || (region == DATELONG_DOW))) || ((mode == SET_MONTH) && ((region == REGION_EU) || (region == DOW_REGION_EU))) ) { DEBUG(putstring("Set year")); mode = SET_YEAR; // print the date normal print_date(month,day,year,mode); // display instructions below displaySetAddress(0, 6); displayPutStr("Press + to change yr.", NORMAL); displaySetAddress(0, 7); displayPutStr("Press SET to set year", NORMAL); } else { // done! DEBUG(putstring("done setting date")); mode = SET_DATE; // print the seconds normal print_date(month,day,year,mode); // display instructions below displaySetAddress(0, 6); displayPutStr("Press MENU to advance", NORMAL); displaySetAddress(0, 7); displayPutStr("Press SET to set", NORMAL); date_y = year; date_m = month; date_d = day; writei2ctime(time_s, time_m, time_h, 0, date_d, date_m, date_y); init_crand(); } screenmutex--; } if ((just_pressed & 0x4) || (pressed & 0x4)) { just_pressed = 0; screenmutex++; if (mode == SET_MONTH) { month++; if (month >= 13) month = 1; if(month == 2) { if(leapyear(year) && (day > 29)) day = 29; else if (!leapyear(year) && (day > 28)) day = 28; } else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) { if(day > 30) day = 30; } print_date(month,day,year,mode); } if (mode == SET_DAY) { day++; if (day > 31) day = 1; if(month == 2) { if(leapyear(year) && (day > 29)) day = 1; else if (!leapyear(year) && (day > 28)) day = 1; } else if ((month == 4) || (month == 6) || (month == 9) || (month == 11)) { if(day > 30) day = 1; } print_date(month,day,year,mode); } if (mode == SET_YEAR) { year = (year+1) % 100; print_date(month,day,year,mode); } screenmutex--; if (pressed & 0x4) _delay_ms(200); } } }
void set_date(void) { uint8_t mode = init_set_menu(3); uint8_t day, month, year; day = date_d; month = date_m; year = date_y; while (!check_timeout()) { if (just_pressed & 0x2) { just_pressed = 0; screenmutex++; if (mode == SET_DATE) { DEBUG(putstring("Set date month/day, depending on region")); // ok now its selected mode = next_mode_setdate[region]; } else if (mode == SET_MONTH) { DEBUG(putstring("Set date day/year, depending on region")); mode = next_mode_setmonth[region]; } else if (mode == SET_DAY) { DEBUG(putstring("Set date month/year, depending on region")); mode = next_mode_setday[region]; } else { // done! DEBUG(putstring("done setting date")); mode = SET_DATE; //Update the DS1307 with set date. writei2ctime(time_s, time_m, time_h, 0, day, month, year); date_y = year; date_m = month; date_d = day; } //Print the instructions below print_monthday_help(mode); //Refresh the date. print_date(month,day,year,mode); screenmutex--; } if ((just_pressed & 0x4) || (pressed & 0x4)) { just_pressed = 0; screenmutex++; if (mode == SET_MONTH) { month++; } if (mode == SET_DAY) { day++; } if (mode == SET_YEAR) { year = (year+1) % 100; } add_month(&month, &day, year); print_date(month,day,year,mode); screenmutex--; if (pressed & 0x4) delay_ms(200); } } }