Contains necessary classes and functions for ELEC351

/media/uploads/Luka_Danilovic/elec_315_prototype_assembly.jpg

Committer:
Luka_Danilovic
Date:
Sun Dec 24 21:50:10 2017 +0000
Revision:
1:4825c27dfbc9
Parent:
0:f44c89c33601
Child:
2:e2b885367ba8
DT: FINISHED AND COMMENTED

Who changed what in which revision?

UserRevisionLine numberNew 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 0:f44c89c33601 12 // Reasign time components to custom data type
Luka_Danilovic 0:f44c89c33601 13 this-> date_time.sec = tempTimeInfo->tm_sec;
Luka_Danilovic 0:f44c89c33601 14 this-> date_time.min = tempTimeInfo->tm_min;
Luka_Danilovic 0:f44c89c33601 15 this-> date_time.hr = tempTimeInfo->tm_hour;
Luka_Danilovic 0:f44c89c33601 16
Luka_Danilovic 0:f44c89c33601 17 // Reasign date components to custom data type
Luka_Danilovic 0:f44c89c33601 18 this-> date_time.day = tempTimeInfo->tm_mday;
Luka_Danilovic 1:4825c27dfbc9 19 this-> date_time.mnt = 1+tempTimeInfo->tm_mon; // Months indexed at 1
Luka_Danilovic 0:f44c89c33601 20 this-> date_time.yr = 1900 + tempTimeInfo->tm_year; // Years since epoch
Luka_Danilovic 0:f44c89c33601 21
Luka_Danilovic 0:f44c89c33601 22 return date_time; // Return custom data type containing Date & Time
Luka_Danilovic 0:f44c89c33601 23 }
Luka_Danilovic 0:f44c89c33601 24
Luka_Danilovic 0:f44c89c33601 25
Luka_Danilovic 0:f44c89c33601 26 void C_DT::setT(int hr, int min, int sec) // Updates RTC time
Luka_Danilovic 0:f44c89c33601 27 {
Luka_Danilovic 0:f44c89c33601 28 time_t secondsElapsed; // Object of type time_t
Luka_Danilovic 0:f44c89c33601 29 struct tm *tempTimeInfo; // Pointer to a embeded structure containing calendar dates
Luka_Danilovic 0:f44c89c33601 30
Luka_Danilovic 0:f44c89c33601 31 time(&secondsElapsed); // Get time is seconds since epoch.
Luka_Danilovic 0:f44c89c33601 32 tempTimeInfo = localtime (&secondsElapsed); // Convert current epoch time to calendar time acounting for timezones & daylight saving
Luka_Danilovic 0:f44c89c33601 33
Luka_Danilovic 0:f44c89c33601 34 tempTimeInfo->tm_sec = sec; // Update seconds
Luka_Danilovic 0:f44c89c33601 35 tempTimeInfo->tm_min = min; // Update minutes
Luka_Danilovic 0:f44c89c33601 36 tempTimeInfo->tm_hour = hr; // Update hours
Luka_Danilovic 0:f44c89c33601 37
Luka_Danilovic 0:f44c89c33601 38 secondsElapsed = mktime(tempTimeInfo); // Convert to epoch time
Luka_Danilovic 0:f44c89c33601 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::setD(int yr, int mnt, int day) // Updates RTC date
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 1:4825c27dfbc9 51 tempTimeInfo->tm_mday = day; // Update day
Luka_Danilovic 1:4825c27dfbc9 52 tempTimeInfo->tm_mon = mnt - 1; // Update month / Indexed at 0
Luka_Danilovic 1:4825c27dfbc9 53 tempTimeInfo->tm_year = yr - 1900 ; // Update year / Years since epoch
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 0:f44c89c33601 57 }
Luka_Danilovic 0:f44c89c33601 58