summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c117
1 files changed, 117 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