![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: TIME.cpp
- Revision:
- 33:3b5096f0126a
- Parent:
- 31:4a88bf97b53e
- Child:
- 34:c0b8705f183d
--- a/TIME.cpp Sat Jan 06 23:10:13 2018 +0000 +++ b/TIME.cpp Sun Jan 07 00:45:11 2018 +0000 @@ -3,133 +3,111 @@ using namespace std; +Mutex Time_Lock; + int current_time_global = 0; int new_time = 0; int get_current_time() //Get Current Time { + Time_Lock.lock(); current_time_global = time(0); + Time_Lock.unlock(); return current_time_global; } void Add_Second() //Seconds to Seconds { + Time_Lock.lock(); new_time = time(0) + 1; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Subtract_Second() { + Time_Lock.lock(); new_time = time(0) - 1; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Add_Minute() //Minutes to Seconds { + Time_Lock.lock(); new_time = time(0) + 60; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Subtract_Minute() { + Time_Lock.lock(); new_time = time(0) - 60; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Add_Hour() //Hours to Seconds { + Time_Lock.lock(); new_time = time(0) + 3600; set_time(new_time); + Time_Lock.unlock(); } void Subtract_Hour() { + Time_Lock.lock(); new_time = time(0) - 3600; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Add_Day() //Days to Seconds { + Time_Lock.lock(); new_time = time(0) + 86400; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Subtract_Day() { + Time_Lock.lock(); new_time = time(0) - 86400; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Add_Month() //Months to Seconds { + Time_Lock.lock(); new_time = time(0) + 2629743; set_time(new_time); + Time_Lock.unlock(); } void Subtract_Month() { + Time_Lock.lock(); new_time = time(0) - 2629743; set_time(new_time); + Time_Lock.unlock(); } void Add_Year() //Years to Seconds { + Time_Lock.lock(); new_time = time(0) + 31556926; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } void Subtract_Year() { + Time_Lock.lock(); new_time = time(0) - 31556926; - set_time(new_time); + set_time(new_time); + Time_Lock.unlock(); } - -int LCD_Time_Get(string Unit) -{ - int temp_months = 0; - int temp_days = 0; - int temp_hours = 0; - int temp_minutes = 0; - int temp_seconds = 0; - - if(Unit == "Years") - { - int years = time(0) / year; - return (1970 + years); - } - else if(Unit == "Months") - { - int temp_months = time(0) / month; - int months = (temp_months % 12); - return (months + 1); - } - else if(Unit == "Days") - { - int temp_days = time(0) / day; - int days = fmod(temp_days,Days_In_Month); - return (days + 1); - } - else if(Unit == "Hours") - { - int temp_hours = time(0) / hour; - int hours = temp_hours % 24; - return hours; - } - else if(Unit == "Minutes") - { - int temp_minutes = time(0) / minute; - int minutes = temp_minutes % 60; - return minutes; - } - else if(Unit == "Seconds") - { - int temp_seconds = time(0) / second; - int seconds = temp_seconds % 60; - return seconds; - } - else - { - cout << "Wrong Input Passed to LCD Time Function" << endl; - } -} -