Time: 17:33 Date: 10/12/2017 Description: Task 1,7,8 Currently Functioning
Dependencies: BME280 BMP280 TextLCD
Working Repository
TIME.cpp@50:3d61ca637399, 2018-01-09 (annotated)
- Committer:
- thomasmorris
- Date:
- Tue Jan 09 12:19:12 2018 +0000
- Revision:
- 50:3d61ca637399
- Parent:
- 34:c0b8705f183d
Dynamic Dating Working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 31:4a88bf97b53e | 1 | #include "TIME.hpp" |
thomasmorris | 31:4a88bf97b53e | 2 | |
thomasmorris | 31:4a88bf97b53e | 3 | |
thomasmorris | 31:4a88bf97b53e | 4 | using namespace std; |
thomasmorris | 31:4a88bf97b53e | 5 | |
chills | 33:3b5096f0126a | 6 | Mutex Time_Lock; |
chills | 33:3b5096f0126a | 7 | |
thomasmorris | 31:4a88bf97b53e | 8 | int current_time_global = 0; |
thomasmorris | 31:4a88bf97b53e | 9 | int new_time = 0; |
thomasmorris | 31:4a88bf97b53e | 10 | |
thomasmorris | 31:4a88bf97b53e | 11 | int get_current_time() //Get Current Time |
thomasmorris | 31:4a88bf97b53e | 12 | { |
chills | 33:3b5096f0126a | 13 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 14 | current_time_global = time(0); |
chills | 33:3b5096f0126a | 15 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 16 | return current_time_global; |
thomasmorris | 31:4a88bf97b53e | 17 | } |
thomasmorris | 31:4a88bf97b53e | 18 | |
chills | 34:c0b8705f183d | 19 | void set_new_date(int days, int months, int years) |
chills | 34:c0b8705f183d | 20 | { |
chills | 34:c0b8705f183d | 21 | time_t Time = time(NULL); |
chills | 34:c0b8705f183d | 22 | tm* Time_Pointer = localtime(&Time); |
chills | 34:c0b8705f183d | 23 | set_time(get_current_time() - year*(Time_Pointer->tm_year - 70) + year*(years - 1970)); |
chills | 34:c0b8705f183d | 24 | set_time(get_current_time() - month*Time_Pointer->tm_mon + month*(months - 1)); |
chills | 34:c0b8705f183d | 25 | set_time(get_current_time() - day*Time_Pointer->tm_mday + day*days); |
chills | 34:c0b8705f183d | 26 | } |
chills | 34:c0b8705f183d | 27 | |
chills | 34:c0b8705f183d | 28 | void set_new_time(int hours, int minutes, int seconds) |
chills | 34:c0b8705f183d | 29 | { |
chills | 34:c0b8705f183d | 30 | time_t Time = time(NULL); |
chills | 34:c0b8705f183d | 31 | tm* Time_Pointer = localtime(&Time); |
chills | 34:c0b8705f183d | 32 | set_time(get_current_time() - second*Time_Pointer->tm_sec + second*seconds); |
chills | 34:c0b8705f183d | 33 | set_time(get_current_time() - minute*Time_Pointer->tm_min + minute*minutes); |
chills | 34:c0b8705f183d | 34 | set_time(get_current_time() - hour*Time_Pointer->tm_hour + hour*hours); |
chills | 34:c0b8705f183d | 35 | } |
chills | 34:c0b8705f183d | 36 | |
thomasmorris | 31:4a88bf97b53e | 37 | void Add_Second() //Seconds to Seconds |
thomasmorris | 31:4a88bf97b53e | 38 | { |
chills | 33:3b5096f0126a | 39 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 40 | new_time = time(0) + 1; |
chills | 33:3b5096f0126a | 41 | set_time(new_time); |
chills | 33:3b5096f0126a | 42 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 43 | } |
thomasmorris | 31:4a88bf97b53e | 44 | |
thomasmorris | 31:4a88bf97b53e | 45 | void Subtract_Second() |
thomasmorris | 31:4a88bf97b53e | 46 | { |
chills | 33:3b5096f0126a | 47 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 48 | new_time = time(0) - 1; |
chills | 33:3b5096f0126a | 49 | set_time(new_time); |
chills | 33:3b5096f0126a | 50 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 51 | } |
thomasmorris | 31:4a88bf97b53e | 52 | |
thomasmorris | 31:4a88bf97b53e | 53 | void Add_Minute() //Minutes to Seconds |
thomasmorris | 31:4a88bf97b53e | 54 | { |
chills | 33:3b5096f0126a | 55 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 56 | new_time = time(0) + 60; |
chills | 33:3b5096f0126a | 57 | set_time(new_time); |
chills | 33:3b5096f0126a | 58 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 59 | } |
thomasmorris | 31:4a88bf97b53e | 60 | |
thomasmorris | 31:4a88bf97b53e | 61 | void Subtract_Minute() |
thomasmorris | 31:4a88bf97b53e | 62 | { |
chills | 33:3b5096f0126a | 63 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 64 | new_time = time(0) - 60; |
chills | 33:3b5096f0126a | 65 | set_time(new_time); |
chills | 33:3b5096f0126a | 66 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 67 | } |
thomasmorris | 31:4a88bf97b53e | 68 | |
thomasmorris | 31:4a88bf97b53e | 69 | void Add_Hour() //Hours to Seconds |
thomasmorris | 31:4a88bf97b53e | 70 | { |
chills | 33:3b5096f0126a | 71 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 72 | new_time = time(0) + 3600; |
thomasmorris | 31:4a88bf97b53e | 73 | set_time(new_time); |
chills | 33:3b5096f0126a | 74 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 75 | } |
thomasmorris | 31:4a88bf97b53e | 76 | |
thomasmorris | 31:4a88bf97b53e | 77 | void Subtract_Hour() |
thomasmorris | 31:4a88bf97b53e | 78 | { |
chills | 33:3b5096f0126a | 79 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 80 | new_time = time(0) - 3600; |
chills | 33:3b5096f0126a | 81 | set_time(new_time); |
chills | 33:3b5096f0126a | 82 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 83 | } |
thomasmorris | 31:4a88bf97b53e | 84 | |
thomasmorris | 31:4a88bf97b53e | 85 | void Add_Day() //Days to Seconds |
thomasmorris | 31:4a88bf97b53e | 86 | { |
chills | 33:3b5096f0126a | 87 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 88 | new_time = time(0) + 86400; |
chills | 33:3b5096f0126a | 89 | set_time(new_time); |
chills | 33:3b5096f0126a | 90 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 91 | } |
thomasmorris | 31:4a88bf97b53e | 92 | |
thomasmorris | 31:4a88bf97b53e | 93 | void Subtract_Day() |
thomasmorris | 31:4a88bf97b53e | 94 | { |
chills | 33:3b5096f0126a | 95 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 96 | new_time = time(0) - 86400; |
chills | 33:3b5096f0126a | 97 | set_time(new_time); |
chills | 33:3b5096f0126a | 98 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 99 | } |
thomasmorris | 31:4a88bf97b53e | 100 | |
thomasmorris | 31:4a88bf97b53e | 101 | void Add_Month() //Months to Seconds |
thomasmorris | 31:4a88bf97b53e | 102 | { |
chills | 33:3b5096f0126a | 103 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 104 | new_time = time(0) + 2629743; |
thomasmorris | 31:4a88bf97b53e | 105 | set_time(new_time); |
chills | 33:3b5096f0126a | 106 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 107 | } |
thomasmorris | 31:4a88bf97b53e | 108 | |
thomasmorris | 31:4a88bf97b53e | 109 | void Subtract_Month() |
thomasmorris | 31:4a88bf97b53e | 110 | { |
chills | 33:3b5096f0126a | 111 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 112 | new_time = time(0) - 2629743; |
thomasmorris | 31:4a88bf97b53e | 113 | set_time(new_time); |
chills | 33:3b5096f0126a | 114 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 115 | } |
thomasmorris | 31:4a88bf97b53e | 116 | |
thomasmorris | 31:4a88bf97b53e | 117 | void Add_Year() //Years to Seconds |
thomasmorris | 31:4a88bf97b53e | 118 | { |
chills | 33:3b5096f0126a | 119 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 120 | new_time = time(0) + 31556926; |
chills | 33:3b5096f0126a | 121 | set_time(new_time); |
chills | 33:3b5096f0126a | 122 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 123 | } |
thomasmorris | 31:4a88bf97b53e | 124 | |
thomasmorris | 31:4a88bf97b53e | 125 | void Subtract_Year() |
thomasmorris | 31:4a88bf97b53e | 126 | { |
chills | 33:3b5096f0126a | 127 | Time_Lock.lock(); |
thomasmorris | 31:4a88bf97b53e | 128 | new_time = time(0) - 31556926; |
chills | 33:3b5096f0126a | 129 | set_time(new_time); |
chills | 33:3b5096f0126a | 130 | Time_Lock.unlock(); |
thomasmorris | 31:4a88bf97b53e | 131 | } |