diff options
author | Brandon Low <lostlogic@rockbox.org> | 2006-03-18 22:42:02 +0000 |
---|---|---|
committer | Brandon Low <lostlogic@rockbox.org> | 2006-03-18 22:42:02 +0000 |
commit | ddf7c70a453465f387df2affa6c3a560e0920b11 (patch) | |
tree | 456e916b3b4b10a519cf77de40774a6446c65d4a | |
parent | 169cd33b3707ecfaea288c67dd39e586da93d795 (diff) | |
download | rockbox-ddf7c70a453465f387df2affa6c3a560e0920b11.tar.gz rockbox-ddf7c70a453465f387df2affa6c3a560e0920b11.zip |
Real Time Clock support in the WPS
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9105 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/gwps-common.c | 139 | ||||
-rw-r--r-- | apps/screens.c | 48 | ||||
-rw-r--r-- | firmware/export/rtc.h | 4 |
3 files changed, 168 insertions, 23 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index 1b0f44f57d..b250674d47 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
24 | #include "system.h" | 24 | #include "system.h" |
25 | #include "settings.h" | 25 | #include "settings.h" |
26 | #include "rtc.h" | ||
26 | #include "audio.h" | 27 | #include "audio.h" |
27 | #include "status.h" | 28 | #include "status.h" |
28 | #include "power.h" | 29 | #include "power.h" |
@@ -913,6 +914,144 @@ static char* get_tag(struct wps_data* wps_data, | |||
913 | return buf; | 914 | return buf; |
914 | } | 915 | } |
915 | break; | 916 | break; |
917 | #ifdef CONFIG_RTC | ||
918 | case 'c': /* Real Time Clock display */ | ||
919 | *flags |= WPS_REFRESH_DYNAMIC; | ||
920 | { | ||
921 | int value; | ||
922 | char *format = 0; | ||
923 | char *bufptr = buf; | ||
924 | struct tm* tm = get_time(); | ||
925 | int i; | ||
926 | for (i=1;/*break*/;i++) { | ||
927 | switch(tag[i]) | ||
928 | { | ||
929 | case 'a': /* abbreviated weekday name (Sun..Sat) */ | ||
930 | value = tm->tm_wday; | ||
931 | if (value > 6 || value < 0) continue; | ||
932 | value = snprintf( | ||
933 | bufptr,buf_size,"%s",str(dayname[value])); | ||
934 | bufptr += value; | ||
935 | buf_size -= value; | ||
936 | continue; | ||
937 | case 'b': /* abbreviated month name (Jan..Dec) */ | ||
938 | value = tm->tm_mon; | ||
939 | if (value > 11 || value < 0) continue; | ||
940 | value = snprintf( | ||
941 | bufptr,buf_size,"%s",str(monthname[value])); | ||
942 | bufptr += value; | ||
943 | buf_size -= value; | ||
944 | continue; | ||
945 | case 'd': /* day of month (01..31) */ | ||
946 | value = tm->tm_mday; | ||
947 | if (value > 31 || value < 1) continue; | ||
948 | format = "%02d"; | ||
949 | break; | ||
950 | case 'e': /* day of month, blank padded ( 1..31) */ | ||
951 | value = tm->tm_mday; | ||
952 | if (value > 31 || value < 1) continue; | ||
953 | format = "%2d"; | ||
954 | break; | ||
955 | case 'H': /* hour (00..23) */ | ||
956 | value = tm->tm_hour; | ||
957 | if (value > 23) continue; | ||
958 | format = "%02d"; | ||
959 | break; | ||
960 | case 'k': /* hour ( 0..23) */ | ||
961 | value = tm->tm_hour; | ||
962 | if (value > 23) continue; | ||
963 | format = "%2d"; | ||
964 | break; | ||
965 | case 'I': /* hour (01..12) */ | ||
966 | value = tm->tm_hour; | ||
967 | if (value > 23) continue; | ||
968 | value %= 12; | ||
969 | if (value == 0) value = 12; | ||
970 | format = "%02d"; | ||
971 | break; | ||
972 | case 'l': /* hour ( 1..12) */ | ||
973 | value = tm->tm_hour; | ||
974 | if (value > 23 || value < 0) continue; | ||
975 | value %= 12; | ||
976 | if (value == 0) value = 12; | ||
977 | format = "%2d"; | ||
978 | break; | ||
979 | case 'm': /* month (01..12) */ | ||
980 | value = tm->tm_mon; | ||
981 | if (value > 11 || value < 0) continue; | ||
982 | value++; | ||
983 | format = "%02d"; | ||
984 | break; | ||
985 | case 'M': /* minute (00..59) */ | ||
986 | value = tm->tm_min; | ||
987 | if (value > 59 || value < 0) continue; | ||
988 | format = "%02d"; | ||
989 | break; | ||
990 | case 'S': /* second (00..59) */ | ||
991 | value = tm->tm_sec; | ||
992 | if (value > 59 || value < 0) continue; | ||
993 | format = "%02d"; | ||
994 | break; | ||
995 | case 'y': /* last two digits of year (00..99) */ | ||
996 | value = tm->tm_year; | ||
997 | value %= 100; | ||
998 | format = "%02d"; | ||
999 | break; | ||
1000 | case 'Y': /* year (1970...) */ | ||
1001 | value = tm->tm_year; | ||
1002 | if (value > 199 || value < 100) continue; | ||
1003 | value += 1900; | ||
1004 | format = "%04d"; | ||
1005 | break; | ||
1006 | case 'p': /* upper case AM or PM indicator */ | ||
1007 | if (tm->tm_hour/12 == 0) format = "AM"; | ||
1008 | else format = "PM"; | ||
1009 | snprintf(bufptr,buf_size,"%s",format); | ||
1010 | bufptr += 2; | ||
1011 | buf_size -= 2; | ||
1012 | continue; | ||
1013 | case 'P': /* lower case am or pm indicator */ | ||
1014 | if (tm->tm_hour/12 == 0) format = "am"; | ||
1015 | else format = "pm"; | ||
1016 | snprintf(bufptr,buf_size,"%s",format); | ||
1017 | bufptr += 2; | ||
1018 | buf_size -= 2; | ||
1019 | continue; | ||
1020 | case 'u': /* day of week (1..7); 1 is Monday */ | ||
1021 | value = tm->tm_wday; | ||
1022 | if (value < 0 || value > 6) continue; | ||
1023 | value++; | ||
1024 | format = "%1d"; | ||
1025 | break; | ||
1026 | case 'w': /* day of week (0..6); 0 is Sunday */ | ||
1027 | value = tm->tm_wday; | ||
1028 | if (value < 0 || value > 6) continue; | ||
1029 | format = "%1d"; | ||
1030 | break; | ||
1031 | default: | ||
1032 | if (tag[i] == 'c') { | ||
1033 | i++; | ||
1034 | value = -1; | ||
1035 | break; | ||
1036 | } else if (tag[i] == '\n') { | ||
1037 | value = -1; | ||
1038 | break; | ||
1039 | } | ||
1040 | snprintf(bufptr,buf_size,"%c",tag[i]); | ||
1041 | bufptr++; | ||
1042 | buf_size--; | ||
1043 | continue; | ||
1044 | } /* switch */ | ||
1045 | if (value < 0) break; | ||
1046 | |||
1047 | value = snprintf(bufptr, buf_size, format, value); | ||
1048 | bufptr += value; | ||
1049 | buf_size -= value; | ||
1050 | } /* while */ | ||
1051 | *tag_len = i; | ||
1052 | return buf; | ||
1053 | } | ||
1054 | #endif /* CONFIG_RTC */ | ||
916 | } | 1055 | } |
917 | return NULL; | 1056 | return NULL; |
918 | } | 1057 | } |
diff --git a/apps/screens.c b/apps/screens.c index 2ac48e3788..f9867a2526 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -638,6 +638,31 @@ void charging_splash(void) | |||
638 | 638 | ||
639 | #if defined(HAVE_LCD_BITMAP) && defined (CONFIG_RTC) | 639 | #if defined(HAVE_LCD_BITMAP) && defined (CONFIG_RTC) |
640 | 640 | ||
641 | const int dayname[] = { | ||
642 | LANG_WEEKDAY_SUNDAY, | ||
643 | LANG_WEEKDAY_MONDAY, | ||
644 | LANG_WEEKDAY_TUESDAY, | ||
645 | LANG_WEEKDAY_WEDNESDAY, | ||
646 | LANG_WEEKDAY_THURSDAY, | ||
647 | LANG_WEEKDAY_FRIDAY, | ||
648 | LANG_WEEKDAY_SATURDAY | ||
649 | }; | ||
650 | |||
651 | const int monthname[] = { | ||
652 | LANG_MONTH_JANUARY, | ||
653 | LANG_MONTH_FEBRUARY, | ||
654 | LANG_MONTH_MARCH, | ||
655 | LANG_MONTH_APRIL, | ||
656 | LANG_MONTH_MAY, | ||
657 | LANG_MONTH_JUNE, | ||
658 | LANG_MONTH_JULY, | ||
659 | LANG_MONTH_AUGUST, | ||
660 | LANG_MONTH_SEPTEMBER, | ||
661 | LANG_MONTH_OCTOBER, | ||
662 | LANG_MONTH_NOVEMBER, | ||
663 | LANG_MONTH_DECEMBER | ||
664 | }; | ||
665 | |||
641 | /* little helper function for voice output */ | 666 | /* little helper function for voice output */ |
642 | static void say_time(int cursorpos, const struct tm *tm) | 667 | static void say_time(int cursorpos, const struct tm *tm) |
643 | { | 668 | { |
@@ -693,29 +718,6 @@ bool set_time_screen(const char* string, struct tm *tm) | |||
693 | unsigned int line_height, prev_line_height; | 718 | unsigned int line_height, prev_line_height; |
694 | int lastmode = lcd_get_drawmode(); | 719 | int lastmode = lcd_get_drawmode(); |
695 | 720 | ||
696 | static const int dayname[] = { | ||
697 | LANG_WEEKDAY_SUNDAY, | ||
698 | LANG_WEEKDAY_MONDAY, | ||
699 | LANG_WEEKDAY_TUESDAY, | ||
700 | LANG_WEEKDAY_WEDNESDAY, | ||
701 | LANG_WEEKDAY_THURSDAY, | ||
702 | LANG_WEEKDAY_FRIDAY, | ||
703 | LANG_WEEKDAY_SATURDAY | ||
704 | }; | ||
705 | static const int monthname[] = { | ||
706 | LANG_MONTH_JANUARY, | ||
707 | LANG_MONTH_FEBRUARY, | ||
708 | LANG_MONTH_MARCH, | ||
709 | LANG_MONTH_APRIL, | ||
710 | LANG_MONTH_MAY, | ||
711 | LANG_MONTH_JUNE, | ||
712 | LANG_MONTH_JULY, | ||
713 | LANG_MONTH_AUGUST, | ||
714 | LANG_MONTH_SEPTEMBER, | ||
715 | LANG_MONTH_OCTOBER, | ||
716 | LANG_MONTH_NOVEMBER, | ||
717 | LANG_MONTH_DECEMBER | ||
718 | }; | ||
719 | char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12}, | 721 | char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12}, |
720 | {24, 16, 24}, {54, 16, 18}, {78, 16, 12}}; | 722 | {24, 16, 24}, {54, 16, 18}, {78, 16, 12}}; |
721 | char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; | 723 | char daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
diff --git a/firmware/export/rtc.h b/firmware/export/rtc.h index 28a4a2636a..c7e3c4a96b 100644 --- a/firmware/export/rtc.h +++ b/firmware/export/rtc.h | |||
@@ -23,6 +23,10 @@ | |||
23 | 23 | ||
24 | #ifdef CONFIG_RTC | 24 | #ifdef CONFIG_RTC |
25 | 25 | ||
26 | extern const int dayname[]; | ||
27 | |||
28 | extern const int monthname[]; | ||
29 | |||
26 | /* Common functions for all targets */ | 30 | /* Common functions for all targets */ |
27 | void rtc_init(void); | 31 | void rtc_init(void); |
28 | int rtc_read_datetime(unsigned char* buf); | 32 | int rtc_read_datetime(unsigned char* buf); |