diff options
Diffstat (limited to 'apps/settings_menu.c')
-rw-r--r-- | apps/settings_menu.c | 71 |
1 files changed, 17 insertions, 54 deletions
diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 10d3665b97..7150dd239d 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c | |||
@@ -21,6 +21,7 @@ | |||
21 | 21 | ||
22 | #include <stdio.h> | 22 | #include <stdio.h> |
23 | #include <stdbool.h> | 23 | #include <stdbool.h> |
24 | #include <string.h> | ||
24 | 25 | ||
25 | #include "lcd.h" | 26 | #include "lcd.h" |
26 | #include "menu.h" | 27 | #include "menu.h" |
@@ -41,6 +42,7 @@ | |||
41 | #include "tree.h" | 42 | #include "tree.h" |
42 | #include "screens.h" | 43 | #include "screens.h" |
43 | #include "talk.h" | 44 | #include "talk.h" |
45 | #include "timefuncs.h" | ||
44 | #ifdef HAVE_LCD_BITMAP | 46 | #ifdef HAVE_LCD_BITMAP |
45 | #include "peakmeter.h" | 47 | #include "peakmeter.h" |
46 | #endif | 48 | #endif |
@@ -685,7 +687,8 @@ static bool trickle_charge(void) | |||
685 | #ifdef HAVE_RTC | 687 | #ifdef HAVE_RTC |
686 | static bool timedate_set(void) | 688 | static bool timedate_set(void) |
687 | { | 689 | { |
688 | int timedate[7]; /* hour,minute,second,year,month,day,dayofweek */ | 690 | struct tm tm; |
691 | int timedate[8]; | ||
689 | bool result; | 692 | bool result; |
690 | 693 | ||
691 | timedate[0] = rtc_read(0x03); /* hour */ | 694 | timedate[0] = rtc_read(0x03); /* hour */ |
@@ -695,67 +698,27 @@ static bool timedate_set(void) | |||
695 | timedate[4] = rtc_read(0x06); /* month */ | 698 | timedate[4] = rtc_read(0x06); /* month */ |
696 | timedate[5] = rtc_read(0x05); /* day */ | 699 | timedate[5] = rtc_read(0x05); /* day */ |
697 | 700 | ||
698 | /* day of week not read, calculated in set_time() */ | 701 | /* Make a local copy of the time struct */ |
699 | /* hour */ | 702 | memcpy(&tm, get_time(), sizeof(struct tm)); |
700 | timedate[0] = ((timedate[0] & 0x30) >> 4) * 10 + (timedate[0] & 0x0f); | ||
701 | /* minute */ | ||
702 | timedate[1] = ((timedate[1] & 0x70) >> 4) * 10 + (timedate[1] & 0x0f); | ||
703 | /* second */ | ||
704 | timedate[2] = ((timedate[2] & 0x70) >> 4) * 10 + (timedate[2] & 0x0f); | ||
705 | /* year */ | ||
706 | timedate[3] = ((timedate[3] & 0xf0) >> 4) * 10 + (timedate[3] & 0x0f); | ||
707 | /* month */ | ||
708 | timedate[4] = ((timedate[4] & 0x10) >> 4) * 10 + (timedate[4] & 0x0f); | ||
709 | /* day */ | ||
710 | timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f); | ||
711 | 703 | ||
712 | /* do some range checks */ | 704 | /* do some range checks */ |
713 | /* This prevents problems with time/date setting after a power loss */ | 705 | /* This prevents problems with time/date setting after a power loss */ |
714 | if (timedate[0] < 0 || timedate[0] > 23 || | 706 | if (!valid_time(&tm)) |
715 | timedate[1] < 0 || timedate[1] > 59 || | ||
716 | timedate[2] < 0 || timedate[2] > 59 || | ||
717 | timedate[3] < 0 || timedate[3] > 99 || | ||
718 | timedate[4] < 1 || timedate[4] > 12 || | ||
719 | timedate[5] < 1 || timedate[5] > 31) | ||
720 | { | 707 | { |
721 | /* hour */ | 708 | /* hour */ |
722 | timedate[0] = 0; | 709 | tm.tm_hour = 0; |
723 | /* minute */ | 710 | tm.tm_min = 0; |
724 | timedate[1] = 0; | 711 | tm.tm_sec = 0; |
725 | /* second */ | 712 | tm.tm_mday = 1; |
726 | timedate[2] = 0; | 713 | tm.tm_mon = 0; |
727 | /* year */ | 714 | tm.tm_wday = 1; |
728 | timedate[3] = 3; | 715 | tm.tm_year = 100; |
729 | /* month */ | ||
730 | timedate[4] = 1; | ||
731 | /* day */ | ||
732 | timedate[5] = 1; | ||
733 | } | 716 | } |
734 | 717 | ||
735 | result = set_time(str(LANG_TIME),timedate); | 718 | result = set_time_screen(str(LANG_TIME), &tm); |
736 | 719 | ||
737 | if(timedate[0] != -1) { | 720 | if(tm.tm_year != -1) { |
738 | /* hour */ | 721 | set_time(&tm); |
739 | timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f; | ||
740 | /* minute */ | ||
741 | timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f; | ||
742 | /* second */ | ||
743 | timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f; | ||
744 | /* year */ | ||
745 | timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0xff; | ||
746 | /* month */ | ||
747 | timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f; | ||
748 | /* day */ | ||
749 | timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0x3f; | ||
750 | |||
751 | rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */ | ||
752 | rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */ | ||
753 | rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */ | ||
754 | rtc_write(0x07, timedate[3]); /* year */ | ||
755 | rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */ | ||
756 | rtc_write(0x05, timedate[5] | (rtc_read(0x05) & 0xc0)); /* day */ | ||
757 | rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0xf8)); /* dayofweek */ | ||
758 | rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */ | ||
759 | } | 722 | } |
760 | return result; | 723 | return result; |
761 | } | 724 | } |