diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/settings.c | 30 | ||||
-rw-r--r-- | apps/settings_menu.c | 20 |
2 files changed, 26 insertions, 24 deletions
diff --git a/apps/settings.c b/apps/settings.c index 826d87ab60..274a124d31 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -553,8 +553,10 @@ void set_option(char* string, int* variable, char* options[], int numoptions ) | |||
553 | #ifdef HAVE_RTC | 553 | #ifdef HAVE_RTC |
554 | #define INDEX_X 0 | 554 | #define INDEX_X 0 |
555 | #define INDEX_Y 1 | 555 | #define INDEX_Y 1 |
556 | #define INDEX_WIDTH 2 | ||
556 | char *dayname[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; | 557 | char *dayname[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"}; |
557 | char cursor[][2]={{9, 1}, {12, 1}, {15, 1}, {9, 2}, {12, 2}, {15, 2}}; | 558 | char *monthname[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"}; |
559 | char cursor[][3]={{0, 1, 2}, {3, 1, 2}, {6, 1, 2}, {4, 2, 4}, {9, 2, 3}, {13, 2, 2}}; | ||
558 | char daysinmonth[]={31,28,31,30,31,30,31,31,30,31,30,31}; | 560 | char daysinmonth[]={31,28,31,30,31,30,31,31,30,31,30,31}; |
559 | 561 | ||
560 | void set_time(char* string, int timedate[]) | 562 | void set_time(char* string, int timedate[]) |
@@ -574,36 +576,36 @@ void set_time(char* string, int timedate[]) | |||
574 | 576 | ||
575 | while ( !done ) { | 577 | while ( !done ) { |
576 | /* calculate the number of days in febuary */ | 578 | /* calculate the number of days in febuary */ |
577 | realyear=timedate[5]+2000; | 579 | realyear=timedate[3]+2000; |
578 | if((realyear%4==0 && !(realyear%100 == 0)) || realyear%400 == 0) /* for february depends on year */ | 580 | if((realyear%4==0 && !(realyear%100 == 0)) || realyear%400 == 0) /* for february depends on year */ |
579 | daysinmonth[1]=29; | 581 | daysinmonth[1]=29; |
580 | else | 582 | else |
581 | daysinmonth[1]=28; | 583 | daysinmonth[1]=28; |
582 | 584 | ||
583 | /* fix day if month or year changed */ | 585 | /* fix day if month or year changed */ |
584 | timedate[3]=timedate[3]<daysinmonth[timedate[4]-1]?timedate[3]:daysinmonth[timedate[4]-1]; | 586 | timedate[5]=timedate[5]<daysinmonth[timedate[4]-1]?timedate[5]:daysinmonth[timedate[4]-1]; |
585 | 587 | ||
586 | /* calculate day of week */ | 588 | /* calculate day of week */ |
587 | julianday=0; | 589 | julianday=0; |
588 | for(i=0;i<timedate[4]-1;i++) { | 590 | for(i=0;i<timedate[4]-1;i++) { |
589 | julianday+=daysinmonth[i]; | 591 | julianday+=daysinmonth[i]; |
590 | } | 592 | } |
591 | julianday+=timedate[3]; | 593 | julianday+=timedate[5]; |
592 | timedate[6]=(realyear+julianday+(realyear-1)/4-(realyear-1)/100+(realyear-1)/400+7-1)%7; | 594 | timedate[6]=(realyear+julianday+(realyear-1)/4-(realyear-1)/100+(realyear-1)/400+7-1)%7; |
593 | 595 | ||
594 | snprintf(buffer, sizeof(buffer), "Time %02d:%02d:%02d", | 596 | snprintf(buffer, sizeof(buffer), "%02d:%02d:%02d", |
595 | timedate[0], | 597 | timedate[0], |
596 | timedate[1], | 598 | timedate[1], |
597 | timedate[2]); | 599 | timedate[2]); |
598 | lcd_puts(0,1,buffer); | 600 | lcd_puts(0,1,buffer); |
599 | 601 | ||
600 | snprintf(buffer, sizeof(buffer), "Date %s %02d.%02d.%02d", | 602 | snprintf(buffer, sizeof(buffer), "%s 20%02d %s %02d", |
601 | dayname[timedate[6]], | 603 | dayname[timedate[6]], |
602 | timedate[3], | 604 | timedate[3], |
603 | timedate[4], | 605 | monthname[timedate[4]-1], |
604 | timedate[5]); | 606 | timedate[5]); |
605 | lcd_puts(0,2,buffer); | 607 | lcd_puts(0,2,buffer); |
606 | lcd_invertrect(cursor[cursorpos][INDEX_X]*6,cursor[cursorpos][INDEX_Y]*8,12,8); | 608 | lcd_invertrect(cursor[cursorpos][INDEX_X]*6,cursor[cursorpos][INDEX_Y]*8,cursor[cursorpos][INDEX_WIDTH]*6,8); |
607 | lcd_puts(0,4,"ON to set"); | 609 | lcd_puts(0,4,"ON to set"); |
608 | lcd_puts(0,5,"OFF to revert"); | 610 | lcd_puts(0,5,"OFF to revert"); |
609 | lcd_update(); | 611 | lcd_update(); |
@@ -621,17 +623,17 @@ void set_time(char* string, int timedate[]) | |||
621 | min=0; | 623 | min=0; |
622 | steps=60; | 624 | steps=60; |
623 | break; | 625 | break; |
624 | case 3: /* day */ | 626 | case 3: /* year */ |
625 | min=1; | 627 | min=0; |
626 | steps=daysinmonth[timedate[4]-1]; | 628 | steps=100; |
627 | break; | 629 | break; |
628 | case 4: /* month */ | 630 | case 4: /* month */ |
629 | min=1; | 631 | min=1; |
630 | steps=12; | 632 | steps=12; |
631 | break; | 633 | break; |
632 | case 5: /* year */ | 634 | case 5: /* day */ |
633 | min=0; | 635 | min=1; |
634 | steps=100; | 636 | steps=daysinmonth[timedate[4]-1]; |
635 | break; | 637 | break; |
636 | } | 638 | } |
637 | } | 639 | } |
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 948f1eb180..b2ca475619 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -87,22 +87,22 @@ static void statusbar(void) | |||
87 | #ifdef HAVE_RTC | 87 | #ifdef HAVE_RTC |
88 | static void timedate_set(void) | 88 | static void timedate_set(void) |
89 | { | 89 | { |
90 | int timedate[7]; /* hour,minute,second,day,month,year,dayofweek */ | 90 | int timedate[7]; /* hour,minute,second,year,month,day,dayofweek */ |
91 | 91 | ||
92 | 92 | ||
93 | timedate[0] = rtc_read(0x03); /* hour */ | 93 | timedate[0] = rtc_read(0x03); /* hour */ |
94 | timedate[1] = rtc_read(0x02); /* minute */ | 94 | timedate[1] = rtc_read(0x02); /* minute */ |
95 | timedate[2] = rtc_read(0x01); /* second */ | 95 | timedate[2] = rtc_read(0x01); /* second */ |
96 | timedate[3] = rtc_read(0x05); /* day */ | 96 | timedate[3] = rtc_read(0x07); /* year */ |
97 | timedate[4] = rtc_read(0x06); /* month */ | 97 | timedate[4] = rtc_read(0x06); /* month */ |
98 | timedate[5] = rtc_read(0x07); /* year */ | 98 | timedate[5] = rtc_read(0x05); /* day */ |
99 | /* day of week not read, calculated */ | 99 | /* day of week not read, calculated */ |
100 | timedate[0] = ((timedate[0] & 0x70) >> 4) * 10 + (timedate[0] & 0x0f); /* hour */ | 100 | timedate[0] = ((timedate[0] & 0x70) >> 4) * 10 + (timedate[0] & 0x0f); /* hour */ |
101 | timedate[1] = ((timedate[1] & 0xf0) >> 4) * 10 + (timedate[1] & 0x0f); /* minute */ | 101 | timedate[1] = ((timedate[1] & 0xf0) >> 4) * 10 + (timedate[1] & 0x0f); /* minute */ |
102 | timedate[2] = ((timedate[2] & 0x30) >> 4) * 10 + (timedate[2] & 0x0f); /* second */ | 102 | timedate[2] = ((timedate[2] & 0x30) >> 4) * 10 + (timedate[2] & 0x0f); /* second */ |
103 | timedate[3] = ((timedate[3] & 0x30) >> 4) * 10 + (timedate[3] & 0x0f); /* day */ | 103 | timedate[3] = ((timedate[3] & 0x30) >> 4) * 10 + (timedate[3] & 0x0f); /* year */ |
104 | timedate[4] = ((timedate[4] & 0x30) >> 4) * 10 + (timedate[4] & 0x0f); /* month */ | 104 | timedate[4] = ((timedate[4] & 0x30) >> 4) * 10 + (timedate[4] & 0x0f); /* month */ |
105 | timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); /* year */ | 105 | timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); /* day */ |
106 | 106 | ||
107 | set_time("[Set time/date]",timedate); | 107 | set_time("[Set time/date]",timedate); |
108 | 108 | ||
@@ -110,16 +110,16 @@ static void timedate_set(void) | |||
110 | timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f; /* hour */ | 110 | timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f; /* hour */ |
111 | timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f; /* minute */ | 111 | timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f; /* minute */ |
112 | timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f; /* second */ | 112 | timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f; /* second */ |
113 | timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0x3f; /* day */ | 113 | timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0xff; /* year */ |
114 | timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f; /* month */ | 114 | timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f; /* month */ |
115 | timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0xff; /* year */ | 115 | timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0x3f; /* day */ |
116 | rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */ | 116 | rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */ |
117 | rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */ | 117 | rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */ |
118 | rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */ | 118 | rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */ |
119 | rtc_write(0x05, timedate[3] | (rtc_read(0x05) & 0xc0)); /* day */ | 119 | rtc_write(0x07, timedate[3]); /* year */ |
120 | rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */ | 120 | rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */ |
121 | rtc_write(0x07, timedate[5]); /* year */ | 121 | rtc_write(0x05, timedate[5] | (rtc_read(0x05) & 0xc0)); /* day */ |
122 | rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0x07)); /* dayofweek */ | 122 | rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0xf8)); /* dayofweek */ |
123 | rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */ | 123 | rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */ |
124 | } | 124 | } |
125 | } | 125 | } |