From 3181f68eff2951029e56293e6003eff34c499584 Mon Sep 17 00:00:00 2001 From: Markus Braun Date: Fri, 9 Aug 2002 12:38:45 +0000 Subject: [PATCH] Added a time/date setting git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1645 a1c6a512-1295-4272-9138-f99709370657 --- apps/settings.c | 117 +++++++++++++++++++++++++++++++++++++++++++ apps/settings.h | 1 + apps/settings_menu.c | 45 +++++++++++++++++ 3 files changed, 163 insertions(+) diff --git a/apps/settings.c b/apps/settings.c index cda65aa9d6..826d87ab60 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -549,3 +549,120 @@ void set_option(char* string, int* variable, char* options[], int numoptions ) } lcd_stop_scroll(); } + +#ifdef HAVE_RTC +#define INDEX_X 0 +#define INDEX_Y 1 +char *dayname[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; +char cursor[][2]={{9, 1}, {12, 1}, {15, 1}, {9, 2}, {12, 2}, {15, 2}}; +char daysinmonth[]={31,28,31,30,31,30,31,31,30,31,30,31}; + +void set_time(char* string, int timedate[]) +{ + bool done = false; + int button; + int min=0,steps=0; + int cursorpos=0; + int lastcursorpos=!cursorpos; + unsigned char buffer[19]; + int realyear; + int julianday; + int i; + + lcd_clear_display(); + lcd_puts_scroll(0,0,string); + + while ( !done ) { + /* calculate the number of days in febuary */ + realyear=timedate[5]+2000; + if((realyear%4==0 && !(realyear%100 == 0)) || realyear%400 == 0) /* for february depends on year */ + daysinmonth[1]=29; + else + daysinmonth[1]=28; + + /* fix day if month or year changed */ + timedate[3]=timedate[3]> 4) * 10 + (timedate[0] & 0x0f); /* hour */ + timedate[1] = ((timedate[1] & 0xf0) >> 4) * 10 + (timedate[1] & 0x0f); /* minute */ + timedate[2] = ((timedate[2] & 0x30) >> 4) * 10 + (timedate[2] & 0x0f); /* second */ + timedate[3] = ((timedate[3] & 0x30) >> 4) * 10 + (timedate[3] & 0x0f); /* day */ + timedate[4] = ((timedate[4] & 0x30) >> 4) * 10 + (timedate[4] & 0x0f); /* month */ + timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); /* year */ + + set_time("[Set time/date]",timedate); + + if(timedate[0] != -1) { + timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f; /* hour */ + timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f; /* minute */ + timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f; /* second */ + timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0x3f; /* day */ + timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f; /* month */ + timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0xff; /* year */ + rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */ + rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */ + rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */ + rtc_write(0x05, timedate[3] | (rtc_read(0x05) & 0xc0)); /* day */ + rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */ + rtc_write(0x07, timedate[5]); /* year */ + rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0x07)); /* dayofweek */ + rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */ + } +} +#endif + void settings_menu(void) { int m; @@ -98,6 +140,9 @@ void settings_menu(void) #endif #ifdef HAVE_LCD_BITMAP { "Status bar", statusbar }, +#endif +#ifdef HAVE_RTC + { "Time/Date", timedate_set }, #endif }; bool old_shuffle = global_settings.playlist_shuffle;