summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Low <lostlogic@rockbox.org>2006-03-18 22:42:02 +0000
committerBrandon Low <lostlogic@rockbox.org>2006-03-18 22:42:02 +0000
commitddf7c70a453465f387df2affa6c3a560e0920b11 (patch)
tree456e916b3b4b10a519cf77de40774a6446c65d4a
parent169cd33b3707ecfaea288c67dd39e586da93d795 (diff)
downloadrockbox-ddf7c70a453465f387df2affa6c3a560e0920b11.zip
rockbox-ddf7c70a453465f387df2affa6c3a560e0920b11.tar.gz
rockbox-ddf7c70a453465f387df2affa6c3a560e0920b11.tar.bz2
rockbox-ddf7c70a453465f387df2affa6c3a560e0920b11.tar.xz
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.c139
-rw-r--r--apps/screens.c48
-rw-r--r--firmware/export/rtc.h4
3 files changed, 168 insertions, 23 deletions
diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c
index 1b0f44f..b250674 100644
--- a/apps/gui/gwps-common.c
+++ b/apps/gui/gwps-common.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include "system.h"
#include "settings.h"
+#include "rtc.h"
#include "audio.h"
#include "status.h"
#include "power.h"
@@ -913,6 +914,144 @@ static char* get_tag(struct wps_data* wps_data,
return buf;
}
break;
+#ifdef CONFIG_RTC
+ case 'c': /* Real Time Clock display */
+ *flags |= WPS_REFRESH_DYNAMIC;
+ {
+ int value;
+ char *format = 0;
+ char *bufptr = buf;
+ struct tm* tm = get_time();
+ int i;
+ for (i=1;/*break*/;i++) {
+ switch(tag[i])
+ {
+ case 'a': /* abbreviated weekday name (Sun..Sat) */
+ value = tm->tm_wday;
+ if (value > 6 || value < 0) continue;
+ value = snprintf(
+ bufptr,buf_size,"%s",str(dayname[value]));
+ bufptr += value;
+ buf_size -= value;
+ continue;
+ case 'b': /* abbreviated month name (Jan..Dec) */
+ value = tm->tm_mon;
+ if (value > 11 || value < 0) continue;
+ value = snprintf(
+ bufptr,buf_size,"%s",str(monthname[value]));
+ bufptr += value;
+ buf_size -= value;
+ continue;
+ case 'd': /* day of month (01..31) */
+ value = tm->tm_mday;
+ if (value > 31 || value < 1) continue;
+ format = "%02d";
+ break;
+ case 'e': /* day of month, blank padded ( 1..31) */
+ value = tm->tm_mday;
+ if (value > 31 || value < 1) continue;
+ format = "%2d";
+ break;
+ case 'H': /* hour (00..23) */
+ value = tm->tm_hour;
+ if (value > 23) continue;
+ format = "%02d";
+ break;
+ case 'k': /* hour ( 0..23) */
+ value = tm->tm_hour;
+ if (value > 23) continue;
+ format = "%2d";
+ break;
+ case 'I': /* hour (01..12) */
+ value = tm->tm_hour;
+ if (value > 23) continue;
+ value %= 12;
+ if (value == 0) value = 12;
+ format = "%02d";
+ break;
+ case 'l': /* hour ( 1..12) */
+ value = tm->tm_hour;
+ if (value > 23 || value < 0) continue;
+ value %= 12;
+ if (value == 0) value = 12;
+ format = "%2d";
+ break;
+ case 'm': /* month (01..12) */
+ value = tm->tm_mon;
+ if (value > 11 || value < 0) continue;
+ value++;
+ format = "%02d";
+ break;
+ case 'M': /* minute (00..59) */
+ value = tm->tm_min;
+ if (value > 59 || value < 0) continue;
+ format = "%02d";
+ break;
+ case 'S': /* second (00..59) */
+ value = tm->tm_sec;
+ if (value > 59 || value < 0) continue;
+ format = "%02d";
+ break;
+ case 'y': /* last two digits of year (00..99) */
+ value = tm->tm_year;
+ value %= 100;
+ format = "%02d";
+ break;
+ case 'Y': /* year (1970...) */
+ value = tm->tm_year;
+ if (value > 199 || value < 100) continue;
+ value += 1900;
+ format = "%04d";
+ break;
+ case 'p': /* upper case AM or PM indicator */
+ if (tm->tm_hour/12 == 0) format = "AM";
+ else format = "PM";
+ snprintf(bufptr,buf_size,"%s",format);
+ bufptr += 2;
+ buf_size -= 2;
+ continue;
+ case 'P': /* lower case am or pm indicator */
+ if (tm->tm_hour/12 == 0) format = "am";
+ else format = "pm";
+ snprintf(bufptr,buf_size,"%s",format);
+ bufptr += 2;
+ buf_size -= 2;
+ continue;
+ case 'u': /* day of week (1..7); 1 is Monday */
+ value = tm->tm_wday;
+ if (value < 0 || value > 6) continue;
+ value++;
+ format = "%1d";
+ break;
+ case 'w': /* day of week (0..6); 0 is Sunday */
+ value = tm->tm_wday;
+ if (value < 0 || value > 6) continue;
+ format = "%1d";
+ break;
+ default:
+ if (tag[i] == 'c') {
+ i++;
+ value = -1;
+ break;
+ } else if (tag[i] == '\n') {
+ value = -1;
+ break;
+ }
+ snprintf(bufptr,buf_size,"%c",tag[i]);
+ bufptr++;
+ buf_size--;
+ continue;
+ } /* switch */
+ if (value < 0) break;
+
+ value = snprintf(bufptr, buf_size, format, value);
+ bufptr += value;
+ buf_size -= value;
+ } /* while */
+ *tag_len = i;
+ return buf;
+ }
+#endif /* CONFIG_RTC */
}
return NULL;
}
diff --git a/apps/screens.c b/apps/screens.c
index 2ac48e3..f9867a2 100644
--- a/apps/screens.c
+++ b/apps/screens.c
@@ -638,6 +638,31 @@ void charging_splash(void)
#if defined(HAVE_LCD_BITMAP) && defined (CONFIG_RTC)
+const int dayname[] = {
+ LANG_WEEKDAY_SUNDAY,
+ LANG_WEEKDAY_MONDAY,
+ LANG_WEEKDAY_TUESDAY,
+ LANG_WEEKDAY_WEDNESDAY,
+ LANG_WEEKDAY_THURSDAY,
+ LANG_WEEKDAY_FRIDAY,
+ LANG_WEEKDAY_SATURDAY
+};
+
+const int monthname[] = {
+ LANG_MONTH_JANUARY,
+ LANG_MONTH_FEBRUARY,
+ LANG_MONTH_MARCH,
+ LANG_MONTH_APRIL,
+ LANG_MONTH_MAY,
+ LANG_MONTH_JUNE,
+ LANG_MONTH_JULY,
+ LANG_MONTH_AUGUST,
+ LANG_MONTH_SEPTEMBER,
+ LANG_MONTH_OCTOBER,
+ LANG_MONTH_NOVEMBER,
+ LANG_MONTH_DECEMBER
+};
+
/* little helper function for voice output */
static void say_time(int cursorpos, const struct tm *tm)
{
@@ -693,29 +718,6 @@ bool set_time_screen(const char* string, struct tm *tm)
unsigned int line_height, prev_line_height;
int lastmode = lcd_get_drawmode();
- static const int dayname[] = {
- LANG_WEEKDAY_SUNDAY,
- LANG_WEEKDAY_MONDAY,
- LANG_WEEKDAY_TUESDAY,
- LANG_WEEKDAY_WEDNESDAY,
- LANG_WEEKDAY_THURSDAY,
- LANG_WEEKDAY_FRIDAY,
- LANG_WEEKDAY_SATURDAY
- };
- static const int monthname[] = {
- LANG_MONTH_JANUARY,
- LANG_MONTH_FEBRUARY,
- LANG_MONTH_MARCH,
- LANG_MONTH_APRIL,
- LANG_MONTH_MAY,
- LANG_MONTH_JUNE,
- LANG_MONTH_JULY,
- LANG_MONTH_AUGUST,
- LANG_MONTH_SEPTEMBER,
- LANG_MONTH_OCTOBER,
- LANG_MONTH_NOVEMBER,
- LANG_MONTH_DECEMBER
- };
char cursor[][3] = {{ 0, 8, 12}, {18, 8, 12}, {36, 8, 12},
{24, 16, 24}, {54, 16, 18}, {78, 16, 12}};
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 28a4a26..c7e3c4a 100644
--- a/firmware/export/rtc.h
+++ b/firmware/export/rtc.h
@@ -23,6 +23,10 @@
#ifdef CONFIG_RTC
+extern const int dayname[];
+
+extern const int monthname[];
+
/* Common functions for all targets */
void rtc_init(void);
int rtc_read_datetime(unsigned char* buf);