X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp.git/blobdiff_plain/61b0cfe9df810db4fbca78e5f880d61c5063f324..142cb1002bb66e7cc183a8265f44c8d56ec54a9b:/avr/cmd_date.c diff --git a/avr/cmd_date.c b/avr/cmd_date.c index bc93efc..337d720 100644 --- a/avr/cmd_date.c +++ b/avr/cmd_date.c @@ -10,14 +10,19 @@ */ #include #include -#include #include #include #include -static const char * const weekdays[] = { - "Sun", "Mon", "Tues", "Wednes", "Thurs", "Fri", "Satur", +static const FLASH char * const FLASH weekdays[] = { + FSTR("Mon"), + FSTR("Tues"), + FSTR("Wednes"), + FSTR("Thurs"), + FSTR("Fri"), + FSTR("Satur"), + FSTR("Sun") }; int mk_date (const char *, struct rtc_time *); @@ -26,31 +31,26 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct rtc_time tm; int rcode = CMD_RET_SUCCESS; - + (void) cmdtp; (void) flag; switch (argc) { case 2: /* set date & time */ - if (strcmp_P(argv[1],PSTR("reset")) == 0) { - my_puts_P(PSTR("Reset RTC...\n")); - rtc_reset (); - } else { - /* initialize tm with current time */ - rcode = rtc_get (&tm); - - if(!rcode) { - /* insert new date & time */ - if (mk_date (argv[1], &tm) != 0) { - my_puts_P(PSTR("## Bad date format\n")); - break; - } - /* and write to RTC */ - rcode = rtc_set (&tm); - if(rcode) - my_puts_P(PSTR("## Set date failed\n")); - } else { - my_puts_P(PSTR("## Get date failed\n")); + /* initialize tm with current time */ + rcode = rtc_get (&tm); + + if(!rcode) { + /* insert new date & time */ + if (mk_date (argv[1], &tm) != 0) { + my_puts_P(PSTR("## Bad date format\n")); + break; } + /* and write to RTC */ + rcode = rtc_set (&tm); + if(rcode) + my_puts_P(PSTR("## Set date failed\n")); + } else { + my_puts_P(PSTR("## Get date failed\n")); } /* FALL TROUGH */ case 1: /* get date & time */ @@ -60,14 +60,14 @@ command_ret_t do_date(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) my_puts_P(PSTR("## Get date failed\n")); break; } - /* TODO: flash */ - printf_P(PSTR("Date: %4d-%02d-%02d (%sday) Time: %2d:%02d:%02d\n"), - tm.tm_year, tm.tm_mon, tm.tm_mday, - (tm.tm_wday<0 || tm.tm_wday>6) ? - "unknown " : weekdays[tm.tm_wday], + printf_P(PSTR("Date: %4d-%02d-%02d ("), + tm.tm_year, tm.tm_mon, tm.tm_mday); + my_puts_P( (tm.tm_wday<0 || tm.tm_wday>6) ? + PSTR("unknown ") : weekdays[tm.tm_wday]); + printf_P(PSTR("day) Time: %2d:%02d:%02d\n"), tm.tm_hour, tm.tm_min, tm.tm_sec); - break; + default: rcode = CMD_RET_USAGE; } @@ -185,4 +185,3 @@ int mk_date (const char *datestr, struct rtc_time *tmp) return (-1); } -