Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
loggingMaster/dateAndTime.cpp@7:92b4783af1d2, 2018-01-09 (annotated)
- Committer:
- Luka_Danilovic
- Date:
- Tue Jan 09 15:47:08 2018 +0000
- Revision:
- 7:92b4783af1d2
- Parent:
- 2:e2b885367ba8
ELEC351 Library; LCD Driver not working due to a bug I could not diagnose. I suspect it is the initialization.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Luka_Danilovic | 0:f44c89c33601 | 1 | #include "mbed.h" |
| Luka_Danilovic | 0:f44c89c33601 | 2 | #include "dateAndTime.hpp" |
| Luka_Danilovic | 0:f44c89c33601 | 3 | |
| Luka_Danilovic | 0:f44c89c33601 | 4 | TDS_DT C_DT::getDT() // Returns TDS_DT Date & Time format |
| Luka_Danilovic | 0:f44c89c33601 | 5 | { |
| Luka_Danilovic | 0:f44c89c33601 | 6 | time_t secondsElapsed; // Object of type time_t |
| Luka_Danilovic | 0:f44c89c33601 | 7 | struct tm *tempTimeInfo; // Pointer to a embeded structure containing calendar dates |
| Luka_Danilovic | 0:f44c89c33601 | 8 | |
| Luka_Danilovic | 0:f44c89c33601 | 9 | time(&secondsElapsed); // Get time is seconds since epoch. Also hope people are ready for UNIX milenium bug |
| Luka_Danilovic | 0:f44c89c33601 | 10 | tempTimeInfo = localtime (&secondsElapsed); // Convert current epoch time to calendar time acounting for timezones & daylight saving |
| Luka_Danilovic | 0:f44c89c33601 | 11 | |
| Luka_Danilovic | 2:e2b885367ba8 | 12 | // Reasign date components to custom data type |
| Luka_Danilovic | 2:e2b885367ba8 | 13 | this-> date_time.day = tempTimeInfo->tm_mday; |
| Luka_Danilovic | 2:e2b885367ba8 | 14 | this-> date_time.mnt = 1+tempTimeInfo->tm_mon; // Months indexed at 1 |
| Luka_Danilovic | 2:e2b885367ba8 | 15 | this-> date_time.yr = 1900 + tempTimeInfo->tm_year; // Years since epoch |
| Luka_Danilovic | 2:e2b885367ba8 | 16 | |
| Luka_Danilovic | 0:f44c89c33601 | 17 | // Reasign time components to custom data type |
| Luka_Danilovic | 0:f44c89c33601 | 18 | this-> date_time.sec = tempTimeInfo->tm_sec; |
| Luka_Danilovic | 0:f44c89c33601 | 19 | this-> date_time.min = tempTimeInfo->tm_min; |
| Luka_Danilovic | 0:f44c89c33601 | 20 | this-> date_time.hr = tempTimeInfo->tm_hour; |
| Luka_Danilovic | 0:f44c89c33601 | 21 | |
| Luka_Danilovic | 2:e2b885367ba8 | 22 | return date_time; // Return custom data type containing Date & Time |
| Luka_Danilovic | 2:e2b885367ba8 | 23 | } |
| Luka_Danilovic | 2:e2b885367ba8 | 24 | |
| Luka_Danilovic | 2:e2b885367ba8 | 25 | |
| Luka_Danilovic | 7:92b4783af1d2 | 26 | void C_DT::setD(int day, int mnt, int yr) // Updates RTC date |
| Luka_Danilovic | 2:e2b885367ba8 | 27 | { |
| Luka_Danilovic | 2:e2b885367ba8 | 28 | time_t secondsElapsed; // Object of type time_t |
| Luka_Danilovic | 2:e2b885367ba8 | 29 | struct tm *tempTimeInfo; // Pointer to a embeded structure containing calendar dates |
| Luka_Danilovic | 0:f44c89c33601 | 30 | |
| Luka_Danilovic | 2:e2b885367ba8 | 31 | time(&secondsElapsed); // Get time is seconds since epoch. |
| Luka_Danilovic | 2:e2b885367ba8 | 32 | tempTimeInfo = localtime (&secondsElapsed); // Convert current epoch time to calendar time acounting for timezones & daylight saving |
| Luka_Danilovic | 2:e2b885367ba8 | 33 | |
| Luka_Danilovic | 2:e2b885367ba8 | 34 | tempTimeInfo->tm_mday = day; // Update day |
| Luka_Danilovic | 2:e2b885367ba8 | 35 | tempTimeInfo->tm_mon = mnt - 1; // Update month / Indexed at 0 |
| Luka_Danilovic | 2:e2b885367ba8 | 36 | tempTimeInfo->tm_year = yr - 1900 ; // Update year / Years since epoch |
| Luka_Danilovic | 2:e2b885367ba8 | 37 | |
| Luka_Danilovic | 2:e2b885367ba8 | 38 | secondsElapsed = mktime(tempTimeInfo); // Convert to epoch time |
| Luka_Danilovic | 2:e2b885367ba8 | 39 | set_time(secondsElapsed); // Update RTC |
| Luka_Danilovic | 0:f44c89c33601 | 40 | } |
| Luka_Danilovic | 0:f44c89c33601 | 41 | |
| Luka_Danilovic | 0:f44c89c33601 | 42 | |
| Luka_Danilovic | 0:f44c89c33601 | 43 | void C_DT::setT(int hr, int min, int sec) // Updates RTC time |
| Luka_Danilovic | 0:f44c89c33601 | 44 | { |
| Luka_Danilovic | 0:f44c89c33601 | 45 | time_t secondsElapsed; // Object of type time_t |
| Luka_Danilovic | 0:f44c89c33601 | 46 | struct tm *tempTimeInfo; // Pointer to a embeded structure containing calendar dates |
| Luka_Danilovic | 0:f44c89c33601 | 47 | |
| Luka_Danilovic | 0:f44c89c33601 | 48 | time(&secondsElapsed); // Get time is seconds since epoch. |
| Luka_Danilovic | 0:f44c89c33601 | 49 | tempTimeInfo = localtime (&secondsElapsed); // Convert current epoch time to calendar time acounting for timezones & daylight saving |
| Luka_Danilovic | 0:f44c89c33601 | 50 | |
| Luka_Danilovic | 0:f44c89c33601 | 51 | tempTimeInfo->tm_sec = sec; // Update seconds |
| Luka_Danilovic | 0:f44c89c33601 | 52 | tempTimeInfo->tm_min = min; // Update minutes |
| Luka_Danilovic | 0:f44c89c33601 | 53 | tempTimeInfo->tm_hour = hr; // Update hours |
| Luka_Danilovic | 0:f44c89c33601 | 54 | |
| Luka_Danilovic | 0:f44c89c33601 | 55 | secondsElapsed = mktime(tempTimeInfo); // Convert to epoch time |
| Luka_Danilovic | 0:f44c89c33601 | 56 | set_time(secondsElapsed); // Update RTC |
| Luka_Danilovic | 2:e2b885367ba8 | 57 | } |