basic lightning detector with gps and sd card logging
Dependencies: AS3935 AdafruitGPS SDFileSystem TSI mbed ConfigFile
datetime.cpp@8:f8830b6c6d9b, 2015-06-30 (annotated)
- Committer:
- ftagius
- Date:
- Tue Jun 30 21:13:18 2015 +0000
- Revision:
- 8:f8830b6c6d9b
add code to use the rtc to keep track of time
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ftagius | 8:f8830b6c6d9b | 1 | #include "datetime.h" |
ftagius | 8:f8830b6c6d9b | 2 | #include "rtc_api.h" |
ftagius | 8:f8830b6c6d9b | 3 | #include "mbed.h" |
ftagius | 8:f8830b6c6d9b | 4 | |
ftagius | 8:f8830b6c6d9b | 5 | void SetDateTime |
ftagius | 8:f8830b6c6d9b | 6 | (int year = 2015 |
ftagius | 8:f8830b6c6d9b | 7 | ,int mon = 5 |
ftagius | 8:f8830b6c6d9b | 8 | ,int day = 26 |
ftagius | 8:f8830b6c6d9b | 9 | ,int hour = 10 |
ftagius | 8:f8830b6c6d9b | 10 | ,int min = 0 |
ftagius | 8:f8830b6c6d9b | 11 | ,int sec = 0 |
ftagius | 8:f8830b6c6d9b | 12 | ) |
ftagius | 8:f8830b6c6d9b | 13 | { |
ftagius | 8:f8830b6c6d9b | 14 | // struct tm Clock; |
ftagius | 8:f8830b6c6d9b | 15 | Clock.tm_year = year - 1900; |
ftagius | 8:f8830b6c6d9b | 16 | Clock.tm_mon = mon; |
ftagius | 8:f8830b6c6d9b | 17 | Clock.tm_mday = day; |
ftagius | 8:f8830b6c6d9b | 18 | Clock.tm_hour = hour; |
ftagius | 8:f8830b6c6d9b | 19 | Clock.tm_min = min; |
ftagius | 8:f8830b6c6d9b | 20 | Clock.tm_sec = sec; |
ftagius | 8:f8830b6c6d9b | 21 | time_t epoch = mktime(&Clock); |
ftagius | 8:f8830b6c6d9b | 22 | if (epoch == (time_t) -1) { |
ftagius | 8:f8830b6c6d9b | 23 | error("Error in clock setting\r\n"); |
ftagius | 8:f8830b6c6d9b | 24 | } |
ftagius | 8:f8830b6c6d9b | 25 | set_time(epoch); |
ftagius | 8:f8830b6c6d9b | 26 | } |
ftagius | 8:f8830b6c6d9b | 27 | |
ftagius | 8:f8830b6c6d9b | 28 | void ShowDateTime() |
ftagius | 8:f8830b6c6d9b | 29 | { |
ftagius | 8:f8830b6c6d9b | 30 | char str[32]; |
ftagius | 8:f8830b6c6d9b | 31 | time_t seconds = time(NULL); |
ftagius | 8:f8830b6c6d9b | 32 | struct tm *gpsd = localtime(&seconds); |
ftagius | 8:f8830b6c6d9b | 33 | struct tm *tminfo = localtime(&seconds); |
ftagius | 8:f8830b6c6d9b | 34 | |
ftagius | 8:f8830b6c6d9b | 35 | strftime(str, 32, "%F,%T", tminfo); |
ftagius | 8:f8830b6c6d9b | 36 | //printf("RTC: %s\r\n", str); |
ftagius | 8:f8830b6c6d9b | 37 | printf("%02d/%02d/%02d,", gpsd->tm_mon, gpsd->tm_mday, gpsd->tm_year+1900); |
ftagius | 8:f8830b6c6d9b | 38 | printf("%02d:%02d:%02d ", gpsd->tm_hour, gpsd->tm_min, gpsd->tm_sec); |
ftagius | 8:f8830b6c6d9b | 39 | } |
ftagius | 8:f8830b6c6d9b | 40 |