CaryCoders
/
demo_SX1276_standalone
standalone sx1276 demo program
Fork of SX1276_GPS by
Diff: datetime.cpp
- Revision:
- 32:a2472bbe7c92
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/datetime.cpp Wed Jul 29 12:14:42 2015 +0000 @@ -0,0 +1,40 @@ +#include "datetime.h" +#include "rtc_api.h" +#include "mbed.h" + +void SetDateTime +(int year = 2015 +,int mon = 5 +,int day = 26 +,int hour = 10 +,int min = 0 +,int sec = 0 +) +{ + // struct tm Clock; + Clock.tm_year = year - 1900; + Clock.tm_mon = mon; + Clock.tm_mday = day; + Clock.tm_hour = hour; + Clock.tm_min = min; + Clock.tm_sec = sec; + time_t epoch = mktime(&Clock); + if (epoch == (time_t) -1) { + error("Error in clock setting\r\n"); + } + set_time(epoch); +} + +void ShowDateTime() +{ + char str[32]; + time_t seconds = time(NULL); + struct tm *gpsd = localtime(&seconds); + struct tm *tminfo = localtime(&seconds); + + strftime(str, 32, "%F,%T", tminfo); + //printf("RTC: %s\r\n", str); + printf("%02d/%02d/%02d,", gpsd->tm_mon, gpsd->tm_mday, gpsd->tm_year+1900); + printf("%02d:%02d:%02d ", gpsd->tm_hour, gpsd->tm_min, gpsd->tm_sec); +} + \ No newline at end of file