![](/media/cache/profiles/f0fcf351df4eb6786e9bb6fc4e2dee02.jpg.50x50_q85.jpg)
Time adjustment and display. Adjustment via Com line and Display on LCD.
Dependencies: mbed TextLCD CheckRTC
main.cpp@3:aff4a05d7a03, 2014-11-01 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Nov 01 02:25:31 2014 +0000
- Revision:
- 3:aff4a05d7a03
- Parent:
- 2:0e3642d50dcc
Added CheckRTC subroutine for Nucleo board external crystal support
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kenjiArai | 1:af3fc8a8eb57 | 1 | /* |
kenjiArai | 1:af3fc8a8eb57 | 2 | * mbed Application program |
kenjiArai | 1:af3fc8a8eb57 | 3 | * |
kenjiArai | 1:af3fc8a8eb57 | 4 | * Copyright (c) 2010-2014 Kenji Arai / JH1PJL |
kenjiArai | 1:af3fc8a8eb57 | 5 | * http://www.page.sannet.ne.jp/kenjia/index.html |
kenjiArai | 1:af3fc8a8eb57 | 6 | * http://mbed.org/users/kenjiArai/ |
kenjiArai | 1:af3fc8a8eb57 | 7 | * Created: March 27th, 2010 |
kenjiArai | 3:aff4a05d7a03 | 8 | * Revised: November 1st, 2014 |
kenjiArai | 1:af3fc8a8eb57 | 9 | * |
kenjiArai | 1:af3fc8a8eb57 | 10 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
kenjiArai | 1:af3fc8a8eb57 | 11 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE |
kenjiArai | 1:af3fc8a8eb57 | 12 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
kenjiArai | 1:af3fc8a8eb57 | 13 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
kenjiArai | 1:af3fc8a8eb57 | 14 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
kenjiArai | 1:af3fc8a8eb57 | 15 | */ |
kenjiArai | 1:af3fc8a8eb57 | 16 | |
kenjiArai | 3:aff4a05d7a03 | 17 | //#define USE_TEXT_LCD |
kenjiArai | 3:aff4a05d7a03 | 18 | |
kenjiArai | 1:af3fc8a8eb57 | 19 | // Include --------------------------------------------------------------------------------------- |
kenjiArai | 0:b3d6027d4ef2 | 20 | #include "mbed.h" |
kenjiArai | 3:aff4a05d7a03 | 21 | #ifdef USE_TEXT_LCD |
kenjiArai | 0:b3d6027d4ef2 | 22 | #include "TextLCD.h" |
kenjiArai | 3:aff4a05d7a03 | 23 | #endif |
kenjiArai | 3:aff4a05d7a03 | 24 | #include "CheckRTC.h" |
kenjiArai | 0:b3d6027d4ef2 | 25 | |
kenjiArai | 1:af3fc8a8eb57 | 26 | // Object ---------------------------------------------------------------------------------------- |
kenjiArai | 1:af3fc8a8eb57 | 27 | Serial pc(USBTX, USBRX); |
kenjiArai | 1:af3fc8a8eb57 | 28 | DigitalOut myled1(LED1); // Assign LED1 output port |
kenjiArai | 3:aff4a05d7a03 | 29 | #ifdef USE_TEXT_LCD |
kenjiArai | 1:af3fc8a8eb57 | 30 | TextLCD lcd(p22, p21, p8, p7, p6, p5,TextLCD::LCD40x2); // rs, e, d4-d7 |
kenjiArai | 3:aff4a05d7a03 | 31 | #endif |
kenjiArai | 1:af3fc8a8eb57 | 32 | |
kenjiArai | 1:af3fc8a8eb57 | 33 | // RAM ------------------------------------------------------------------------------------------- |
kenjiArai | 1:af3fc8a8eb57 | 34 | |
kenjiArai | 1:af3fc8a8eb57 | 35 | // ROM / Constant data --------------------------------------------------------------------------- |
kenjiArai | 1:af3fc8a8eb57 | 36 | |
kenjiArai | 1:af3fc8a8eb57 | 37 | // Function prototypes --------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 38 | void msg_hlp (void); |
kenjiArai | 3:aff4a05d7a03 | 39 | void chk_and_set_time(char *ptr); |
kenjiArai | 3:aff4a05d7a03 | 40 | void put_rn (void); |
kenjiArai | 3:aff4a05d7a03 | 41 | void put_r (void); |
kenjiArai | 3:aff4a05d7a03 | 42 | int xatoi (char **str, int32_t *res); |
kenjiArai | 3:aff4a05d7a03 | 43 | void get_line (char *buff, int len); |
kenjiArai | 1:af3fc8a8eb57 | 44 | |
kenjiArai | 1:af3fc8a8eb57 | 45 | // Definition ------------------------------------------------------------------------------------ |
kenjiArai | 3:aff4a05d7a03 | 46 | #define BAUD(x) pc.baud(x) |
kenjiArai | 3:aff4a05d7a03 | 47 | #define GETC(x) pc.getc(x) |
kenjiArai | 3:aff4a05d7a03 | 48 | #define PUTC(x) pc.putc(x) |
kenjiArai | 3:aff4a05d7a03 | 49 | #define PRINTF(...) pc.printf(__VA_ARGS__) |
kenjiArai | 3:aff4a05d7a03 | 50 | #define READABLE(x) pc.readable(x) |
kenjiArai | 1:af3fc8a8eb57 | 51 | |
kenjiArai | 3:aff4a05d7a03 | 52 | #ifdef USE_TEXT_LCD |
kenjiArai | 3:aff4a05d7a03 | 53 | #define L_CLS(x) lcd.cls(x) |
kenjiArai | 3:aff4a05d7a03 | 54 | #define L_LOC(x,y) lcd.locate(0, 0); |
kenjiArai | 3:aff4a05d7a03 | 55 | #define L_PRINTF(...) lcd.printf(__VA_ARGS__) |
kenjiArai | 3:aff4a05d7a03 | 56 | #else |
kenjiArai | 3:aff4a05d7a03 | 57 | #define L_CLS(x) {;} |
kenjiArai | 3:aff4a05d7a03 | 58 | #define L_LOC(x,y) {;} |
kenjiArai | 3:aff4a05d7a03 | 59 | #define L_PRINTF(...) {;} |
kenjiArai | 3:aff4a05d7a03 | 60 | #endif |
kenjiArai | 3:aff4a05d7a03 | 61 | |
kenjiArai | 3:aff4a05d7a03 | 62 | #define STYLE1 |
kenjiArai | 3:aff4a05d7a03 | 63 | //#define STYLE2 |
kenjiArai | 1:af3fc8a8eb57 | 64 | //#define STYLE_COM |
kenjiArai | 0:b3d6027d4ef2 | 65 | |
kenjiArai | 1:af3fc8a8eb57 | 66 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 1:af3fc8a8eb57 | 67 | // Control Program |
kenjiArai | 1:af3fc8a8eb57 | 68 | //------------------------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 69 | // Help Massage |
kenjiArai | 3:aff4a05d7a03 | 70 | void msg_hlp (void) |
kenjiArai | 3:aff4a05d7a03 | 71 | { |
kenjiArai | 3:aff4a05d7a03 | 72 | PRINTF("t - Check and set RTC"); |
kenjiArai | 3:aff4a05d7a03 | 73 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 74 | PRINTF("/ - Show time every second (Esc -> hit any key)"); |
kenjiArai | 3:aff4a05d7a03 | 75 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 76 | PRINTF("? - Help"); |
kenjiArai | 3:aff4a05d7a03 | 77 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 78 | } |
kenjiArai | 3:aff4a05d7a03 | 79 | |
kenjiArai | 3:aff4a05d7a03 | 80 | int main() |
kenjiArai | 3:aff4a05d7a03 | 81 | { |
kenjiArai | 3:aff4a05d7a03 | 82 | char *ptr; |
kenjiArai | 3:aff4a05d7a03 | 83 | char linebuf[64]; |
kenjiArai | 3:aff4a05d7a03 | 84 | char buf[40]; |
kenjiArai | 3:aff4a05d7a03 | 85 | time_t seconds; |
kenjiArai | 3:aff4a05d7a03 | 86 | |
kenjiArai | 3:aff4a05d7a03 | 87 | CheckRTC(); |
kenjiArai | 3:aff4a05d7a03 | 88 | L_CLS(); |
kenjiArai | 3:aff4a05d7a03 | 89 | L_LOC(0, 0); |
kenjiArai | 3:aff4a05d7a03 | 90 | L_LOC(0, 0); // 1st line top |
kenjiArai | 3:aff4a05d7a03 | 91 | // 1234567890123456789012345678901234567890 |
kenjiArai | 3:aff4a05d7a03 | 92 | L_PRINTF(" Waiting for time adjustment via com "); |
kenjiArai | 3:aff4a05d7a03 | 93 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 94 | seconds = time(NULL); |
kenjiArai | 3:aff4a05d7a03 | 95 | PRINTF("Current time is"); |
kenjiArai | 3:aff4a05d7a03 | 96 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 97 | #ifdef STYLE_COM |
kenjiArai | 3:aff4a05d7a03 | 98 | PRINTF("Time: %s", ctime(&seconds)); |
kenjiArai | 3:aff4a05d7a03 | 99 | #else |
kenjiArai | 3:aff4a05d7a03 | 100 | strftime(buf,40, "%I:%M:%S %p (%Y/%m/%d)", localtime(&seconds)); |
kenjiArai | 3:aff4a05d7a03 | 101 | PRINTF("Time: %s", buf); |
kenjiArai | 3:aff4a05d7a03 | 102 | #endif |
kenjiArai | 3:aff4a05d7a03 | 103 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 104 | PRINTF("Is it correct time?"); |
kenjiArai | 3:aff4a05d7a03 | 105 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 106 | PRINTF("YES -> please enter '/'"); |
kenjiArai | 3:aff4a05d7a03 | 107 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 108 | PRINTF("NO -> please enter t yy mm dd hh mm ss <ret>"); |
kenjiArai | 3:aff4a05d7a03 | 109 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 110 | PRINTF("e.g. >t 14 11 1 8 5 15<ret>"); |
kenjiArai | 3:aff4a05d7a03 | 111 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 112 | for (;;) { |
kenjiArai | 3:aff4a05d7a03 | 113 | put_r(); |
kenjiArai | 3:aff4a05d7a03 | 114 | PUTC('>'); |
kenjiArai | 3:aff4a05d7a03 | 115 | ptr = linebuf; |
kenjiArai | 3:aff4a05d7a03 | 116 | get_line(ptr, sizeof(linebuf)); |
kenjiArai | 3:aff4a05d7a03 | 117 | switch (*ptr++) { |
kenjiArai | 3:aff4a05d7a03 | 118 | //--------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 119 | // check and set RTC |
kenjiArai | 3:aff4a05d7a03 | 120 | //--------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 121 | case 't' : |
kenjiArai | 3:aff4a05d7a03 | 122 | put_r(); |
kenjiArai | 3:aff4a05d7a03 | 123 | chk_and_set_time(ptr); |
kenjiArai | 3:aff4a05d7a03 | 124 | break; |
kenjiArai | 3:aff4a05d7a03 | 125 | //--------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 126 | // check and set RTC |
kenjiArai | 3:aff4a05d7a03 | 127 | //--------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 128 | case '/' : |
kenjiArai | 3:aff4a05d7a03 | 129 | put_r(); |
kenjiArai | 3:aff4a05d7a03 | 130 | PRINTF("Current Time -> Plese see LCD also"); |
kenjiArai | 3:aff4a05d7a03 | 131 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 132 | while (1) { |
kenjiArai | 3:aff4a05d7a03 | 133 | if (READABLE()) { |
kenjiArai | 3:aff4a05d7a03 | 134 | break; |
kenjiArai | 3:aff4a05d7a03 | 135 | } |
kenjiArai | 3:aff4a05d7a03 | 136 | while ( seconds == time(NULL)) ; |
kenjiArai | 3:aff4a05d7a03 | 137 | seconds = time(NULL); |
kenjiArai | 3:aff4a05d7a03 | 138 | myled1 = !myled1; |
kenjiArai | 3:aff4a05d7a03 | 139 | L_CLS(); |
kenjiArai | 3:aff4a05d7a03 | 140 | L_LOC(0, 0); // 1st line top |
kenjiArai | 3:aff4a05d7a03 | 141 | L_PRINTF("It is %d sec since Jan.1,1970\n", seconds); |
kenjiArai | 3:aff4a05d7a03 | 142 | L_LOC(0, 1); // 2nd line top |
kenjiArai | 3:aff4a05d7a03 | 143 | #ifdef STYLE1 |
kenjiArai | 3:aff4a05d7a03 | 144 | // 27 Mar 2010 13:24:00 |
kenjiArai | 3:aff4a05d7a03 | 145 | strftime(buf,40, "%x %X ", localtime(&seconds)); |
kenjiArai | 3:aff4a05d7a03 | 146 | #endif |
kenjiArai | 3:aff4a05d7a03 | 147 | #ifdef STYLE2 |
kenjiArai | 3:aff4a05d7a03 | 148 | // 13:24:00 PM (2010/03/27) |
kenjiArai | 3:aff4a05d7a03 | 149 | strftime(buf,40, "%I:%M:%S %p (%Y/%m/%d)", localtime(&seconds)); |
kenjiArai | 3:aff4a05d7a03 | 150 | #endif |
kenjiArai | 3:aff4a05d7a03 | 151 | L_PRINTF("Time = %s", buf); |
kenjiArai | 3:aff4a05d7a03 | 152 | #ifdef STYLE_COM |
kenjiArai | 3:aff4a05d7a03 | 153 | PRINTF("Time: %s", ctime(&seconds)); |
kenjiArai | 3:aff4a05d7a03 | 154 | #else |
kenjiArai | 3:aff4a05d7a03 | 155 | PRINTF("Time: %s", buf); |
kenjiArai | 3:aff4a05d7a03 | 156 | #endif |
kenjiArai | 3:aff4a05d7a03 | 157 | put_rn(); |
kenjiArai | 3:aff4a05d7a03 | 158 | } |
kenjiArai | 3:aff4a05d7a03 | 159 | break; |
kenjiArai | 3:aff4a05d7a03 | 160 | //--------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 161 | // check and set RTC |
kenjiArai | 3:aff4a05d7a03 | 162 | //--------------------------------------------------------------------------------- |
kenjiArai | 3:aff4a05d7a03 | 163 | case '?' : |
kenjiArai | 3:aff4a05d7a03 | 164 | default : |
kenjiArai | 3:aff4a05d7a03 | 165 | put_r(); |
kenjiArai | 3:aff4a05d7a03 | 166 | msg_hlp(); |
kenjiArai | 3:aff4a05d7a03 | 167 | break; |
kenjiArai | 3:aff4a05d7a03 | 168 | } |
kenjiArai | 3:aff4a05d7a03 | 169 | } |
kenjiArai | 3:aff4a05d7a03 | 170 | } |
kenjiArai | 3:aff4a05d7a03 | 171 | |
kenjiArai | 1:af3fc8a8eb57 | 172 | // Put \r\n |
kenjiArai | 3:aff4a05d7a03 | 173 | void put_rn (void) |
kenjiArai | 0:b3d6027d4ef2 | 174 | { |
kenjiArai | 1:af3fc8a8eb57 | 175 | PUTC('\r'); |
kenjiArai | 1:af3fc8a8eb57 | 176 | PUTC('\n'); |
kenjiArai | 1:af3fc8a8eb57 | 177 | } |
kenjiArai | 1:af3fc8a8eb57 | 178 | |
kenjiArai | 1:af3fc8a8eb57 | 179 | // Put \r |
kenjiArai | 3:aff4a05d7a03 | 180 | void put_r (void) |
kenjiArai | 1:af3fc8a8eb57 | 181 | { |
kenjiArai | 1:af3fc8a8eb57 | 182 | PUTC('\r'); |
kenjiArai | 0:b3d6027d4ef2 | 183 | } |
kenjiArai | 0:b3d6027d4ef2 | 184 | |
kenjiArai | 1:af3fc8a8eb57 | 185 | // Change string -> number |
kenjiArai | 1:af3fc8a8eb57 | 186 | int xatoi (char **str, int32_t *res) |
kenjiArai | 1:af3fc8a8eb57 | 187 | { |
kenjiArai | 1:af3fc8a8eb57 | 188 | unsigned long val; |
kenjiArai | 1:af3fc8a8eb57 | 189 | unsigned char c, radix, s = 0; |
kenjiArai | 1:af3fc8a8eb57 | 190 | |
kenjiArai | 1:af3fc8a8eb57 | 191 | while ((c = **str) == ' ') { |
kenjiArai | 1:af3fc8a8eb57 | 192 | (*str)++; |
kenjiArai | 1:af3fc8a8eb57 | 193 | } |
kenjiArai | 1:af3fc8a8eb57 | 194 | if (c == '-') { |
kenjiArai | 1:af3fc8a8eb57 | 195 | s = 1; |
kenjiArai | 1:af3fc8a8eb57 | 196 | c = *(++(*str)); |
kenjiArai | 1:af3fc8a8eb57 | 197 | } |
kenjiArai | 1:af3fc8a8eb57 | 198 | if (c == '0') { |
kenjiArai | 1:af3fc8a8eb57 | 199 | c = *(++(*str)); |
kenjiArai | 1:af3fc8a8eb57 | 200 | if (c <= ' ') { |
kenjiArai | 1:af3fc8a8eb57 | 201 | *res = 0; |
kenjiArai | 1:af3fc8a8eb57 | 202 | return 1; |
kenjiArai | 1:af3fc8a8eb57 | 203 | } |
kenjiArai | 1:af3fc8a8eb57 | 204 | if (c == 'x') { |
kenjiArai | 1:af3fc8a8eb57 | 205 | radix = 16; |
kenjiArai | 1:af3fc8a8eb57 | 206 | c = *(++(*str)); |
kenjiArai | 1:af3fc8a8eb57 | 207 | } else { |
kenjiArai | 1:af3fc8a8eb57 | 208 | if (c == 'b') { |
kenjiArai | 1:af3fc8a8eb57 | 209 | radix = 2; |
kenjiArai | 1:af3fc8a8eb57 | 210 | c = *(++(*str)); |
kenjiArai | 1:af3fc8a8eb57 | 211 | } else { |
kenjiArai | 1:af3fc8a8eb57 | 212 | if ((c >= '0')&&(c <= '9')) { |
kenjiArai | 1:af3fc8a8eb57 | 213 | radix = 8; |
kenjiArai | 1:af3fc8a8eb57 | 214 | } else { |
kenjiArai | 1:af3fc8a8eb57 | 215 | return 0; |
kenjiArai | 1:af3fc8a8eb57 | 216 | } |
kenjiArai | 1:af3fc8a8eb57 | 217 | } |
kenjiArai | 1:af3fc8a8eb57 | 218 | } |
kenjiArai | 1:af3fc8a8eb57 | 219 | } else { |
kenjiArai | 1:af3fc8a8eb57 | 220 | if ((c < '1')||(c > '9')) { |
kenjiArai | 1:af3fc8a8eb57 | 221 | return 0; |
kenjiArai | 1:af3fc8a8eb57 | 222 | } |
kenjiArai | 1:af3fc8a8eb57 | 223 | radix = 10; |
kenjiArai | 1:af3fc8a8eb57 | 224 | } |
kenjiArai | 1:af3fc8a8eb57 | 225 | val = 0; |
kenjiArai | 1:af3fc8a8eb57 | 226 | while (c > ' ') { |
kenjiArai | 1:af3fc8a8eb57 | 227 | if (c >= 'a') { |
kenjiArai | 1:af3fc8a8eb57 | 228 | c -= 0x20; |
kenjiArai | 1:af3fc8a8eb57 | 229 | } |
kenjiArai | 1:af3fc8a8eb57 | 230 | c -= '0'; |
kenjiArai | 1:af3fc8a8eb57 | 231 | if (c >= 17) { |
kenjiArai | 1:af3fc8a8eb57 | 232 | c -= 7; |
kenjiArai | 1:af3fc8a8eb57 | 233 | if (c <= 9) { |
kenjiArai | 1:af3fc8a8eb57 | 234 | return 0; |
kenjiArai | 1:af3fc8a8eb57 | 235 | } |
kenjiArai | 1:af3fc8a8eb57 | 236 | } |
kenjiArai | 1:af3fc8a8eb57 | 237 | if (c >= radix) { |
kenjiArai | 1:af3fc8a8eb57 | 238 | return 0; |
kenjiArai | 1:af3fc8a8eb57 | 239 | } |
kenjiArai | 1:af3fc8a8eb57 | 240 | val = val * radix + c; |
kenjiArai | 1:af3fc8a8eb57 | 241 | c = *(++(*str)); |
kenjiArai | 1:af3fc8a8eb57 | 242 | } |
kenjiArai | 1:af3fc8a8eb57 | 243 | if (s) { |
kenjiArai | 1:af3fc8a8eb57 | 244 | val = -val; |
kenjiArai | 1:af3fc8a8eb57 | 245 | } |
kenjiArai | 1:af3fc8a8eb57 | 246 | *res = val; |
kenjiArai | 1:af3fc8a8eb57 | 247 | return 1; |
kenjiArai | 1:af3fc8a8eb57 | 248 | } |
kenjiArai | 1:af3fc8a8eb57 | 249 | |
kenjiArai | 1:af3fc8a8eb57 | 250 | // Get key input data |
kenjiArai | 1:af3fc8a8eb57 | 251 | void get_line (char *buff, int len) |
kenjiArai | 0:b3d6027d4ef2 | 252 | { |
kenjiArai | 0:b3d6027d4ef2 | 253 | char c; |
kenjiArai | 1:af3fc8a8eb57 | 254 | int idx = 0; |
kenjiArai | 1:af3fc8a8eb57 | 255 | |
kenjiArai | 1:af3fc8a8eb57 | 256 | for (;;) { |
kenjiArai | 1:af3fc8a8eb57 | 257 | c = GETC(); |
kenjiArai | 1:af3fc8a8eb57 | 258 | if (c == '\r') { |
kenjiArai | 1:af3fc8a8eb57 | 259 | buff[idx++] = c; |
kenjiArai | 1:af3fc8a8eb57 | 260 | break; |
kenjiArai | 1:af3fc8a8eb57 | 261 | } |
kenjiArai | 1:af3fc8a8eb57 | 262 | if ((c == '\b') && idx) { |
kenjiArai | 1:af3fc8a8eb57 | 263 | idx--; |
kenjiArai | 1:af3fc8a8eb57 | 264 | PUTC(c); |
kenjiArai | 1:af3fc8a8eb57 | 265 | PUTC(' '); |
kenjiArai | 1:af3fc8a8eb57 | 266 | PUTC(c); |
kenjiArai | 1:af3fc8a8eb57 | 267 | } |
kenjiArai | 1:af3fc8a8eb57 | 268 | if (((uint8_t)c >= ' ') && (idx < len - 1)) { |
kenjiArai | 1:af3fc8a8eb57 | 269 | buff[idx++] = c; |
kenjiArai | 1:af3fc8a8eb57 | 270 | PUTC(c); |
kenjiArai | 1:af3fc8a8eb57 | 271 | } |
kenjiArai | 1:af3fc8a8eb57 | 272 | } |
kenjiArai | 1:af3fc8a8eb57 | 273 | buff[idx] = 0; |
kenjiArai | 1:af3fc8a8eb57 | 274 | PUTC('\n'); |
kenjiArai | 0:b3d6027d4ef2 | 275 | } |
kenjiArai | 0:b3d6027d4ef2 | 276 | |
kenjiArai | 1:af3fc8a8eb57 | 277 | // RTC related subroutines |
kenjiArai | 1:af3fc8a8eb57 | 278 | void chk_and_set_time(char *ptr) |
kenjiArai | 1:af3fc8a8eb57 | 279 | { |
kenjiArai | 1:af3fc8a8eb57 | 280 | int32_t p1; |
kenjiArai | 1:af3fc8a8eb57 | 281 | struct tm t; |
kenjiArai | 1:af3fc8a8eb57 | 282 | time_t seconds; |
kenjiArai | 1:af3fc8a8eb57 | 283 | char buf[40]; |
kenjiArai | 1:af3fc8a8eb57 | 284 | |
kenjiArai | 1:af3fc8a8eb57 | 285 | if (xatoi(&ptr, &p1)) { |
kenjiArai | 3:aff4a05d7a03 | 286 | t.tm_year = (uint8_t)p1 + 100; |
kenjiArai | 1:af3fc8a8eb57 | 287 | PRINTF("Year:%d ",p1); |
kenjiArai | 1:af3fc8a8eb57 | 288 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:aff4a05d7a03 | 289 | t.tm_mon = (uint8_t)p1 - 1; |
kenjiArai | 1:af3fc8a8eb57 | 290 | PRINTF("Month:%d ",p1); |
kenjiArai | 1:af3fc8a8eb57 | 291 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:aff4a05d7a03 | 292 | t.tm_mday = (uint8_t)p1; |
kenjiArai | 1:af3fc8a8eb57 | 293 | PRINTF("Day:%d ",p1); |
kenjiArai | 1:af3fc8a8eb57 | 294 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:aff4a05d7a03 | 295 | t.tm_hour = (uint8_t)p1; |
kenjiArai | 1:af3fc8a8eb57 | 296 | PRINTF("Hour:%d ",p1); |
kenjiArai | 1:af3fc8a8eb57 | 297 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:aff4a05d7a03 | 298 | t.tm_min = (uint8_t)p1; |
kenjiArai | 1:af3fc8a8eb57 | 299 | PRINTF("Min:%d ",p1); |
kenjiArai | 1:af3fc8a8eb57 | 300 | xatoi( &ptr, &p1 ); |
kenjiArai | 3:aff4a05d7a03 | 301 | t.tm_sec = (uint8_t)p1; |
kenjiArai | 1:af3fc8a8eb57 | 302 | PRINTF("Sec: %d",p1); |
kenjiArai | 1:af3fc8a8eb57 | 303 | put_rn(); |
kenjiArai | 1:af3fc8a8eb57 | 304 | seconds = mktime(&t); |
kenjiArai | 1:af3fc8a8eb57 | 305 | set_time(seconds); |
kenjiArai | 1:af3fc8a8eb57 | 306 | } |
kenjiArai | 1:af3fc8a8eb57 | 307 | seconds = time(NULL); |
kenjiArai | 1:af3fc8a8eb57 | 308 | strftime(buf, 40, "%B %d,'%y, %H:%M:%S", localtime(&seconds)); |
kenjiArai | 1:af3fc8a8eb57 | 309 | PRINTF("Time: %s", buf); |
kenjiArai | 1:af3fc8a8eb57 | 310 | put_rn(); |
kenjiArai | 1:af3fc8a8eb57 | 311 | } |