fuck this
Dependencies: BMP280
TimeInterface.cpp@25:a2aedb498b27, 2018-01-10 (annotated)
- Committer:
- mwthewsey
- Date:
- Wed Jan 10 03:57:59 2018 +0000
- Revision:
- 25:a2aedb498b27
- Parent:
- 11:b538e73841ae
Final Submission
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mwthewsey | 10:261f2b69c4c7 | 1 | #include "mbed.h" |
mwthewsey | 10:261f2b69c4c7 | 2 | #include "TimeInterface.h" |
mwthewsey | 10:261f2b69c4c7 | 3 | |
mwthewsey | 10:261f2b69c4c7 | 4 | void SetDate(int DD, int MM, int YYYY) |
mwthewsey | 10:261f2b69c4c7 | 5 | { |
mwthewsey | 10:261f2b69c4c7 | 6 | time_t currentTime = time(0); //Get the currenttime |
mwthewsey | 10:261f2b69c4c7 | 7 | tm* current_tm = localtime(¤tTime); //Convert the time integer to a stuct |
mwthewsey | 10:261f2b69c4c7 | 8 | tm newtime = *current_tm; //structure holding new time |
mwthewsey | 10:261f2b69c4c7 | 9 | newtime.tm_year = YYYY - 1900; //Year since 1900 |
mwthewsey | 10:261f2b69c4c7 | 10 | newtime.tm_mon = MM - 1; //month of the year (0-11) |
mwthewsey | 10:261f2b69c4c7 | 11 | newtime.tm_mday = DD; //day of month |
mwthewsey | 10:261f2b69c4c7 | 12 | //All other parameters remain unchanged |
mwthewsey | 10:261f2b69c4c7 | 13 | |
mwthewsey | 10:261f2b69c4c7 | 14 | int timeint = mktime(&newtime); //Convert time strucutre to int |
mwthewsey | 10:261f2b69c4c7 | 15 | if (timeint == -1) |
mwthewsey | 10:261f2b69c4c7 | 16 | { |
mwthewsey | 10:261f2b69c4c7 | 17 | //error code |
mwthewsey | 10:261f2b69c4c7 | 18 | } else { |
mwthewsey | 10:261f2b69c4c7 | 19 | set_time(timeint); //Set the new time |
mwthewsey | 10:261f2b69c4c7 | 20 | } |
mwthewsey | 10:261f2b69c4c7 | 21 | } |
mwthewsey | 10:261f2b69c4c7 | 22 | |
mwthewsey | 10:261f2b69c4c7 | 23 | void SetTime(int HH, int mm, int ss) |
mwthewsey | 10:261f2b69c4c7 | 24 | { |
mwthewsey | 10:261f2b69c4c7 | 25 | time_t currentTime = time(0); //Get the currenttime |
mwthewsey | 10:261f2b69c4c7 | 26 | tm* current_tm = localtime(¤tTime); //Convert the time integer to a stuct |
mwthewsey | 10:261f2b69c4c7 | 27 | tm newtime = *current_tm; //structure holding new time |
mwthewsey | 10:261f2b69c4c7 | 28 | |
mwthewsey | 10:261f2b69c4c7 | 29 | newtime.tm_hour = HH; //Set hours |
mwthewsey | 10:261f2b69c4c7 | 30 | newtime.tm_min = mm; //Set mins |
mwthewsey | 10:261f2b69c4c7 | 31 | newtime.tm_sec = ss; //Set secs |
mwthewsey | 10:261f2b69c4c7 | 32 | //All other parameters remain unchanged |
mwthewsey | 10:261f2b69c4c7 | 33 | |
mwthewsey | 10:261f2b69c4c7 | 34 | int timeint = mktime(&newtime); //Convert time strucutre to int |
mwthewsey | 10:261f2b69c4c7 | 35 | if (timeint == -1) |
mwthewsey | 10:261f2b69c4c7 | 36 | { |
mwthewsey | 10:261f2b69c4c7 | 37 | //error code |
mwthewsey | 10:261f2b69c4c7 | 38 | } else { |
mwthewsey | 10:261f2b69c4c7 | 39 | set_time(timeint); //Set the new time |
mwthewsey | 10:261f2b69c4c7 | 40 | } |
mwthewsey | 10:261f2b69c4c7 | 41 | } |
mwthewsey | 10:261f2b69c4c7 | 42 | |
mwthewsey | 10:261f2b69c4c7 | 43 | struct tm ReturnDateTimeStruct(time_t seconds) |
mwthewsey | 10:261f2b69c4c7 | 44 | { |
mwthewsey | 10:261f2b69c4c7 | 45 | tm* ltm = localtime(&seconds); //Turn given time integer into time structure pointer |
mwthewsey | 11:b538e73841ae | 46 | ltm->tm_mon += 1; //adjust from the standard of 0-11 for months to 1-12 |
mwthewsey | 11:b538e73841ae | 47 | ltm->tm_year += 1900; |
mwthewsey | 10:261f2b69c4c7 | 48 | return *ltm; //Return the data held at this address. |
mwthewsey | 10:261f2b69c4c7 | 49 | } |