summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/settings.c117
-rw-r--r--apps/settings.h1
-rw-r--r--apps/settings_menu.c45
3 files changed, 163 insertions, 0 deletions
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 )
549 } 549 }
550 lcd_stop_scroll(); 550 lcd_stop_scroll();
551} 551}
552
553#ifdef HAVE_RTC
554#define INDEX_X 0
555#define INDEX_Y 1
556char *dayname[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
557char cursor[][2]={{9, 1}, {12, 1}, {15, 1}, {9, 2}, {12, 2}, {15, 2}};
558char daysinmonth[]={31,28,31,30,31,30,31,31,30,31,30,31};
559
560void set_time(char* string, int timedate[])
561{
562 bool done = false;
563 int button;
564 int min=0,steps=0;
565 int cursorpos=0;
566 int lastcursorpos=!cursorpos;
567 unsigned char buffer[19];
568 int realyear;
569 int julianday;
570 int i;
571
572 lcd_clear_display();
573 lcd_puts_scroll(0,0,string);
574
575 while ( !done ) {
576 /* calculate the number of days in febuary */
577 realyear=timedate[5]+2000;
578 if((realyear%4==0 && !(realyear%100 == 0)) || realyear%400 == 0) /* for february depends on year */
579 daysinmonth[1]=29;
580 else
581 daysinmonth[1]=28;
582
583 /* fix day if month or year changed */
584 timedate[3]=timedate[3]<daysinmonth[timedate[4]-1]?timedate[3]:daysinmonth[timedate[4]-1];
585
586 /* calculate day of week */
587 julianday=0;
588 for(i=0;i<timedate[4]-1;i++) {
589 julianday+=daysinmonth[i];
590 }
591 julianday+=timedate[3];
592 timedate[6]=(realyear+julianday+(realyear-1)/4-(realyear-1)/100+(realyear-1)/400+7-1)%7;
593
594 snprintf(buffer, sizeof(buffer), "Time %02d:%02d:%02d",
595 timedate[0],
596 timedate[1],
597 timedate[2]);
598 lcd_puts(0,1,buffer);
599
600 snprintf(buffer, sizeof(buffer), "Date %s %02d.%02d.%02d",
601 dayname[timedate[6]],
602 timedate[3],
603 timedate[4],
604 timedate[5]);
605 lcd_puts(0,2,buffer);
606 lcd_invertrect(cursor[cursorpos][INDEX_X]*6,cursor[cursorpos][INDEX_Y]*8,12,8);
607 lcd_puts(0,4,"ON to set");
608 lcd_puts(0,5,"OFF to revert");
609 lcd_update();
610
611 /* calculate the minimum and maximum for the number under cursor */
612 if(cursorpos!=lastcursorpos) {
613 lastcursorpos=cursorpos;
614 switch(cursorpos) {
615 case 0: /* hour */
616 min=0;
617 steps=24;
618 break;
619 case 1: /* minute */
620 case 2: /* second */
621 min=0;
622 steps=60;
623 break;
624 case 3: /* day */
625 min=1;
626 steps=daysinmonth[timedate[4]-1];
627 break;
628 case 4: /* month */
629 min=1;
630 steps=12;
631 break;
632 case 5: /* year */
633 min=0;
634 steps=100;
635 break;
636 }
637 }
638
639 button = button_get(true);
640 switch ( button ) {
641 case BUTTON_LEFT:
642 cursorpos=(cursorpos+6-1)%6;
643 break;
644 case BUTTON_RIGHT:
645 cursorpos=(cursorpos+6+1)%6;
646 break;
647 case BUTTON_UP:
648 timedate[cursorpos]=(timedate[cursorpos]+steps-min+1)%steps+min;
649 if(timedate[cursorpos] == 0) timedate[cursorpos]+=min;
650 break;
651 case BUTTON_DOWN:
652 timedate[cursorpos]=(timedate[cursorpos]+steps-min-1)%steps+min;
653 if(timedate[cursorpos] == 0) timedate[cursorpos]+=min;
654 break;
655 case BUTTON_ON:
656 done=true;
657 if (timedate[6] == 0) timedate[6]=7; /* rtc needs 1 .. 7 */
658 break;
659 case BUTTON_OFF:
660 done=true;
661 timedate[0]=-1;
662 break;
663 default:
664 break;
665 }
666 }
667}
668#endif
diff --git a/apps/settings.h b/apps/settings.h
index e66bf8f53d..a223e4914e 100644
--- a/apps/settings.h
+++ b/apps/settings.h
@@ -86,6 +86,7 @@ void set_int(char* string,
86 int step, 86 int step,
87 int min, 87 int min,
88 int max ); 88 int max );
89void set_time(char* string, int timedate[]);
89 90
90/* global settings */ 91/* global settings */
91extern struct user_settings global_settings; 92extern struct user_settings global_settings;
diff --git a/apps/settings_menu.c b/apps/settings_menu.c
index 7ab1b0479d..948f1eb180 100644
--- a/apps/settings_menu.c
+++ b/apps/settings_menu.c
@@ -33,6 +33,7 @@
33#include "backlight.h" 33#include "backlight.h"
34#include "playlist.h" /* for playlist_shuffle */ 34#include "playlist.h" /* for playlist_shuffle */
35#include "powermgmt.h" 35#include "powermgmt.h"
36#include "rtc.h"
36 37
37static void shuffle(void) 38static void shuffle(void)
38{ 39{
@@ -83,6 +84,47 @@ static void statusbar(void)
83} 84}
84#endif 85#endif
85 86
87#ifdef HAVE_RTC
88static void timedate_set(void)
89{
90 int timedate[7]; /* hour,minute,second,day,month,year,dayofweek */
91
92
93 timedate[0] = rtc_read(0x03); /* hour */
94 timedate[1] = rtc_read(0x02); /* minute */
95 timedate[2] = rtc_read(0x01); /* second */
96 timedate[3] = rtc_read(0x05); /* day */
97 timedate[4] = rtc_read(0x06); /* month */
98 timedate[5] = rtc_read(0x07); /* year */
99 /* day of week not read, calculated */
100 timedate[0] = ((timedate[0] & 0x70) >> 4) * 10 + (timedate[0] & 0x0f); /* hour */
101 timedate[1] = ((timedate[1] & 0xf0) >> 4) * 10 + (timedate[1] & 0x0f); /* minute */
102 timedate[2] = ((timedate[2] & 0x30) >> 4) * 10 + (timedate[2] & 0x0f); /* second */
103 timedate[3] = ((timedate[3] & 0x30) >> 4) * 10 + (timedate[3] & 0x0f); /* day */
104 timedate[4] = ((timedate[4] & 0x30) >> 4) * 10 + (timedate[4] & 0x0f); /* month */
105 timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); /* year */
106
107 set_time("[Set time/date]",timedate);
108
109 if(timedate[0] != -1) {
110 timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f; /* hour */
111 timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f; /* minute */
112 timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f; /* second */
113 timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0x3f; /* day */
114 timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f; /* month */
115 timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0xff; /* year */
116 rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */
117 rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */
118 rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */
119 rtc_write(0x05, timedate[3] | (rtc_read(0x05) & 0xc0)); /* day */
120 rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */
121 rtc_write(0x07, timedate[5]); /* year */
122 rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0x07)); /* dayofweek */
123 rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */
124 }
125}
126#endif
127
86void settings_menu(void) 128void settings_menu(void)
87{ 129{
88 int m; 130 int m;
@@ -99,6 +141,9 @@ void settings_menu(void)
99#ifdef HAVE_LCD_BITMAP 141#ifdef HAVE_LCD_BITMAP
100 { "Status bar", statusbar }, 142 { "Status bar", statusbar },
101#endif 143#endif
144#ifdef HAVE_RTC
145 { "Time/Date", timedate_set },
146#endif
102 }; 147 };
103 bool old_shuffle = global_settings.playlist_shuffle; 148 bool old_shuffle = global_settings.playlist_shuffle;
104 149