Angel David Yaguana Hernandez / Mbed 2 deprecated time_on_uart

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <string.h>
00005 #include <iostream>
00006 #include <math.h>
00007 #define MESSAGE_BUFFER_SIZE 1024
00008 //#include "lib_crc.h"
00009  
00010 Serial pc(USBTX, USBRX);
00011 DigitalOut ho(p26);
00012  
00013 char line = '\n';
00014 char c;
00015 char sav[40];
00016 char tstr[32];
00017 struct tm t;
00018 time_t seconds;
00019  
00020 void Display() {  //Getting Data and putting on LED Screen
00021     time_t seconds = time(NULL);
00022     strftime(tstr, 32,"%H:%M:%S", localtime(&seconds));
00023     pc.printf("%s\n\r", tstr);
00024     wait(0.95);
00025 }
00026  
00027 void input() {
00028     memset(sav, 0, 40);
00029     do {
00030         c = pc.getc();
00031         pc.putc (c);
00032         strcat(sav, &c);
00033     } while (c != ' ');
00034 }
00035  
00036 void TimeSet() {
00037  
00038     pc.printf("SET TIME\n\r");
00039     pc.printf("--------\n\n\r");
00040  
00041     do {
00042         pc.printf("Please input local time:\n\r");
00043         pc.printf("YYYY MM DD HH MM SS\n\r");
00044  
00045         input();
00046         t.tm_year = atoi(sav);
00047         input();
00048         t.tm_mon  = atoi(sav);
00049         input();
00050         t.tm_mday = atoi(sav);
00051         input();
00052         t.tm_hour = atoi(sav);
00053         input();
00054         t.tm_min  = atoi(sav);
00055         input();
00056         t.tm_sec  = atoi(sav);
00057  
00058         pc.printf("\n\n\r");
00059         pc.printf("Is the time correct? [Y/N]\n\n\r");
00060         c=pc.getc();
00061     } while (c != 'Y');
00062  
00063     t.tm_year = t.tm_year - 1900;
00064     t.tm_mon = t.tm_mon - 1;
00065  
00066     set_time(mktime(&t));
00067 }
00068  
00069 int main () {
00070     TimeSet();
00071     pc.printf("ok...\n\n\r");
00072     while (1) {
00073         Display();
00074     }
00075 }