Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
main.cpp@34:c0b8705f183d, 2018-01-07 (annotated)
- Committer:
- chills
- Date:
- Sun Jan 07 03:08:00 2018 +0000
- Revision:
- 34:c0b8705f183d
- Parent:
- 33:3b5096f0126a
- Child:
- 35:26b0a9b55d82
2018_01_07 03:04; All serial commands and time based commands working.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 6:97f586597310 | 1 | /* |
thomasmorris | 6:97f586597310 | 2 | ELEC 351 Group T |
thomasmorris | 6:97f586597310 | 3 | Team Members : Christopher Hills, Thomas Morris |
thomasmorris | 32:8f2795716e97 | 4 | Current Verision 15 |
thomasmorris | 29:64b1f95a807c | 5 | Overiew: Working Tasks 1,2,4,5,6,7,8,10,11,12,13 |
thomasmorris | 8:0e4481b64353 | 6 | |
thomasmorris | 12:536eca338ae8 | 7 | Last Revision: Added Mail Box to serial |
thomasmorris | 8:0e4481b64353 | 8 | Todo: |
thomasmorris | 12:536eca338ae8 | 9 | make a mailbox within SD card, LCD, network so they can be used from within |
thomasmorris | 12:536eca338ae8 | 10 | Fix the network so it uses the mail box data. |
thomasmorris | 6:97f586597310 | 11 | */ |
thomasmorris | 6:97f586597310 | 12 | |
thomasmorris | 25:36699ed589ab | 13 | #include "SETUP.hpp" |
chills | 24:7d2da96e05ad | 14 | |
chills | 33:3b5096f0126a | 15 | Mutex Time_Lock_Main; |
chills | 33:3b5096f0126a | 16 | |
chills | 33:3b5096f0126a | 17 | void Network() //Interrupt service routine for handling the timeout |
thomasmorris | 8:0e4481b64353 | 18 | { |
thomasmorris | 25:36699ed589ab | 19 | |
chills | 13:db857b3744c6 | 20 | } |
thomasmorris | 31:4a88bf97b53e | 21 | void LCD_Write_Year() |
thomasmorris | 12:536eca338ae8 | 22 | { |
chills | 33:3b5096f0126a | 23 | Time_Lock_Main.lock(); |
chills | 33:3b5096f0126a | 24 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 25 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 26 | int Years = 1900 + Time_Pointer->tm_year; |
chills | 33:3b5096f0126a | 27 | Time_Lock_Main.unlock(); |
thomasmorris | 31:4a88bf97b53e | 28 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 29 | ss << Years; |
thomasmorris | 31:4a88bf97b53e | 30 | string Year_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 31 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 32 | LCD.Write_String("Set Year"); |
thomasmorris | 31:4a88bf97b53e | 33 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 34 | LCD.Write_String(Year_String); |
thomasmorris | 30:4cde05cc7c4f | 35 | } |
thomasmorris | 25:36699ed589ab | 36 | |
thomasmorris | 31:4a88bf97b53e | 37 | void LCD_Write_Month() |
thomasmorris | 31:4a88bf97b53e | 38 | { |
chills | 33:3b5096f0126a | 39 | Time_Lock_Main.lock(); |
chills | 33:3b5096f0126a | 40 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 41 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 42 | int Months = 1 + Time_Pointer->tm_mon; |
chills | 33:3b5096f0126a | 43 | Time_Lock_Main.unlock(); |
thomasmorris | 31:4a88bf97b53e | 44 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 45 | ss << Months; |
thomasmorris | 31:4a88bf97b53e | 46 | string Month_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 47 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 48 | LCD.Write_String("Set Month"); |
thomasmorris | 31:4a88bf97b53e | 49 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 50 | LCD.Write_String(Month_String); |
thomasmorris | 31:4a88bf97b53e | 51 | } |
thomasmorris | 31:4a88bf97b53e | 52 | void LCD_Write_Day() |
thomasmorris | 31:4a88bf97b53e | 53 | { |
chills | 33:3b5096f0126a | 54 | Time_Lock_Main.lock(); |
chills | 33:3b5096f0126a | 55 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 56 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 57 | int Days = Time_Pointer->tm_mday; |
chills | 33:3b5096f0126a | 58 | Time_Lock_Main.unlock(); |
thomasmorris | 31:4a88bf97b53e | 59 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 60 | ss << Days; |
thomasmorris | 31:4a88bf97b53e | 61 | string Day_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 62 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 63 | LCD.Write_String("Set Day"); |
thomasmorris | 31:4a88bf97b53e | 64 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 65 | LCD.Write_String(Day_String); |
thomasmorris | 31:4a88bf97b53e | 66 | } |
thomasmorris | 31:4a88bf97b53e | 67 | |
thomasmorris | 31:4a88bf97b53e | 68 | |
thomasmorris | 31:4a88bf97b53e | 69 | void LCD_Write_Hour() |
thomasmorris | 30:4cde05cc7c4f | 70 | { |
chills | 33:3b5096f0126a | 71 | Time_Lock_Main.lock(); |
chills | 33:3b5096f0126a | 72 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 73 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 74 | int Hours = Time_Pointer->tm_hour; |
chills | 33:3b5096f0126a | 75 | Time_Lock_Main.unlock(); |
thomasmorris | 31:4a88bf97b53e | 76 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 77 | ss << Hours; |
thomasmorris | 31:4a88bf97b53e | 78 | string Hour_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 79 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 80 | LCD.Write_String("Set Hour"); |
thomasmorris | 31:4a88bf97b53e | 81 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 82 | LCD.Write_String(Hour_String); |
thomasmorris | 31:4a88bf97b53e | 83 | } |
thomasmorris | 31:4a88bf97b53e | 84 | void LCD_Write_Minute() |
thomasmorris | 31:4a88bf97b53e | 85 | { |
chills | 33:3b5096f0126a | 86 | Time_Lock_Main.lock(); |
chills | 33:3b5096f0126a | 87 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 88 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 89 | int Minutes = Time_Pointer->tm_min; |
chills | 33:3b5096f0126a | 90 | Time_Lock_Main.unlock(); |
thomasmorris | 31:4a88bf97b53e | 91 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 92 | ss << Minutes; |
thomasmorris | 31:4a88bf97b53e | 93 | string Minute_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 94 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 95 | LCD.Write_String("Set Minute"); |
thomasmorris | 31:4a88bf97b53e | 96 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 97 | LCD.Write_String(Minute_String); |
thomasmorris | 31:4a88bf97b53e | 98 | } |
thomasmorris | 31:4a88bf97b53e | 99 | void LCD_Write_Seconds() |
thomasmorris | 31:4a88bf97b53e | 100 | { |
chills | 33:3b5096f0126a | 101 | Time_Lock_Main.lock(); |
chills | 33:3b5096f0126a | 102 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 103 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 104 | int Seconds = Time_Pointer->tm_sec; |
chills | 33:3b5096f0126a | 105 | Time_Lock_Main.unlock(); |
thomasmorris | 31:4a88bf97b53e | 106 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 107 | ss << Seconds; |
thomasmorris | 31:4a88bf97b53e | 108 | string Second_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 109 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 110 | LCD.Write_String("Set Second"); |
thomasmorris | 31:4a88bf97b53e | 111 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 112 | LCD.Write_String(Second_String); |
thomasmorris | 7:dfe19413fdc2 | 113 | } |
thomasmorris | 30:4cde05cc7c4f | 114 | |
thomasmorris | 30:4cde05cc7c4f | 115 | void LCD_Output() |
chills | 34:c0b8705f183d | 116 | { |
thomasmorris | 30:4cde05cc7c4f | 117 | while(1) |
thomasmorris | 29:64b1f95a807c | 118 | { |
thomasmorris | 30:4cde05cc7c4f | 119 | Thread::wait(10);//Dont Delete |
thomasmorris | 30:4cde05cc7c4f | 120 | if(mode == 0)//Default mode |
thomasmorris | 30:4cde05cc7c4f | 121 | { |
chills | 34:c0b8705f183d | 122 | if(Log_Value == 1){cout << "In mode 0 " << endl;} |
chills | 33:3b5096f0126a | 123 | |
thomasmorris | 30:4cde05cc7c4f | 124 | Thread::wait(3000); |
chills | 33:3b5096f0126a | 125 | |
chills | 34:c0b8705f183d | 126 | sprintf (LCD_buffer, "%1.1f %1.1f %1.1f",Data_Active.get_temperature(),Data_Active.get_pressure(),Data_Active.get_light());//Used for converting to a sting |
chills | 33:3b5096f0126a | 127 | |
thomasmorris | 30:4cde05cc7c4f | 128 | LCD.DDRAM_Address(0x00); |
thomasmorris | 30:4cde05cc7c4f | 129 | LCD.Write_String("Temp Pres li"); |
thomasmorris | 30:4cde05cc7c4f | 130 | LCD.DDRAM_Address(0x40); |
thomasmorris | 30:4cde05cc7c4f | 131 | LCD.Write_String(LCD_buffer); |
thomasmorris | 25:36699ed589ab | 132 | |
thomasmorris | 30:4cde05cc7c4f | 133 | Thread::wait(3000); |
chills | 33:3b5096f0126a | 134 | |
chills | 33:3b5096f0126a | 135 | Time_Lock_Main.lock(); |
chills | 34:c0b8705f183d | 136 | time_t Time = Data_Active.get_time(); |
chills | 34:c0b8705f183d | 137 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 30:4cde05cc7c4f | 138 | LCD.Display_Clear(); |
chills | 33:3b5096f0126a | 139 | sprintf (LCD_buffer, "%d:%d %d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting |
chills | 33:3b5096f0126a | 140 | Time_Lock_Main.unlock(); |
chills | 33:3b5096f0126a | 141 | |
thomasmorris | 30:4cde05cc7c4f | 142 | LCD.DDRAM_Address(0x00); |
thomasmorris | 30:4cde05cc7c4f | 143 | LCD.Write_String("Current Time:"); |
thomasmorris | 30:4cde05cc7c4f | 144 | LCD.DDRAM_Address(0x40); |
thomasmorris | 30:4cde05cc7c4f | 145 | LCD.Write_String(LCD_buffer); |
thomasmorris | 31:4a88bf97b53e | 146 | |
thomasmorris | 31:4a88bf97b53e | 147 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 31:4a88bf97b53e | 148 | { |
thomasmorris | 31:4a88bf97b53e | 149 | mode = 1; |
thomasmorris | 31:4a88bf97b53e | 150 | } |
thomasmorris | 30:4cde05cc7c4f | 151 | } |
thomasmorris | 30:4cde05cc7c4f | 152 | else if(mode == 1)//Choose either date setting or time setting |
thomasmorris | 30:4cde05cc7c4f | 153 | { |
chills | 34:c0b8705f183d | 154 | if(Log_Value == 1){cout << "In Mode 1" << endl;} |
thomasmorris | 30:4cde05cc7c4f | 155 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 156 | while(1) |
thomasmorris | 31:4a88bf97b53e | 157 | { |
thomasmorris | 31:4a88bf97b53e | 158 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 159 | LCD.Write_String("Date Time"); |
thomasmorris | 31:4a88bf97b53e | 160 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 161 | LCD.Write_String("< >"); |
thomasmorris | 31:4a88bf97b53e | 162 | Thread::wait(1000); |
thomasmorris | 31:4a88bf97b53e | 163 | if(SW1.read() == 1) |
thomasmorris | 31:4a88bf97b53e | 164 | { |
thomasmorris | 31:4a88bf97b53e | 165 | mode = 2; |
thomasmorris | 31:4a88bf97b53e | 166 | break; |
thomasmorris | 31:4a88bf97b53e | 167 | } |
thomasmorris | 31:4a88bf97b53e | 168 | if(SW2.read() == 1) |
thomasmorris | 31:4a88bf97b53e | 169 | { |
thomasmorris | 31:4a88bf97b53e | 170 | mode = 5; |
thomasmorris | 31:4a88bf97b53e | 171 | break; |
thomasmorris | 31:4a88bf97b53e | 172 | } |
thomasmorris | 31:4a88bf97b53e | 173 | } |
thomasmorris | 30:4cde05cc7c4f | 174 | } |
thomasmorris | 30:4cde05cc7c4f | 175 | else if(mode == 2)//Set the Year |
thomasmorris | 30:4cde05cc7c4f | 176 | { |
chills | 34:c0b8705f183d | 177 | if(Log_Value == 1){cout << "In Mode 2" << endl;} |
thomasmorris | 31:4a88bf97b53e | 178 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 179 | while(1) |
thomasmorris | 31:4a88bf97b53e | 180 | { |
thomasmorris | 32:8f2795716e97 | 181 | LCD_Write_Year(); |
thomasmorris | 31:4a88bf97b53e | 182 | Thread::wait(1000); |
chills | 33:3b5096f0126a | 183 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 184 | { |
chills | 33:3b5096f0126a | 185 | mode = 3; |
chills | 33:3b5096f0126a | 186 | break; |
chills | 33:3b5096f0126a | 187 | } |
thomasmorris | 31:4a88bf97b53e | 188 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 189 | { |
thomasmorris | 31:4a88bf97b53e | 190 | Add_Year(); |
thomasmorris | 31:4a88bf97b53e | 191 | } |
thomasmorris | 31:4a88bf97b53e | 192 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 193 | { |
thomasmorris | 31:4a88bf97b53e | 194 | Subtract_Year(); |
thomasmorris | 31:4a88bf97b53e | 195 | } |
thomasmorris | 31:4a88bf97b53e | 196 | LCD_Write_Year(); |
thomasmorris | 31:4a88bf97b53e | 197 | } |
thomasmorris | 30:4cde05cc7c4f | 198 | } |
thomasmorris | 30:4cde05cc7c4f | 199 | else if(mode == 3)//Set the Month |
thomasmorris | 30:4cde05cc7c4f | 200 | { |
chills | 34:c0b8705f183d | 201 | if(Log_Value == 1){cout << "In Mode 3" << endl;} |
thomasmorris | 31:4a88bf97b53e | 202 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 203 | while(1) |
thomasmorris | 32:8f2795716e97 | 204 | { |
thomasmorris | 32:8f2795716e97 | 205 | LCD_Write_Month(); |
thomasmorris | 31:4a88bf97b53e | 206 | Thread::wait(1000); |
chills | 33:3b5096f0126a | 207 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 208 | { |
chills | 33:3b5096f0126a | 209 | mode = 4; |
chills | 33:3b5096f0126a | 210 | break; |
chills | 33:3b5096f0126a | 211 | } |
thomasmorris | 31:4a88bf97b53e | 212 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 213 | { |
thomasmorris | 31:4a88bf97b53e | 214 | Add_Month(); |
thomasmorris | 31:4a88bf97b53e | 215 | } |
thomasmorris | 31:4a88bf97b53e | 216 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 217 | { |
thomasmorris | 31:4a88bf97b53e | 218 | Subtract_Month(); |
thomasmorris | 32:8f2795716e97 | 219 | } |
chills | 33:3b5096f0126a | 220 | |
thomasmorris | 31:4a88bf97b53e | 221 | } |
thomasmorris | 30:4cde05cc7c4f | 222 | } |
thomasmorris | 30:4cde05cc7c4f | 223 | else if(mode == 4)//Set the Day |
thomasmorris | 30:4cde05cc7c4f | 224 | { |
chills | 34:c0b8705f183d | 225 | if(Log_Value == 1){cout << "In Mode 4" << endl;} |
thomasmorris | 31:4a88bf97b53e | 226 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 227 | while(1) |
thomasmorris | 32:8f2795716e97 | 228 | { |
thomasmorris | 32:8f2795716e97 | 229 | LCD_Write_Day(); |
thomasmorris | 31:4a88bf97b53e | 230 | Thread::wait(1000); |
chills | 33:3b5096f0126a | 231 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 232 | { |
chills | 33:3b5096f0126a | 233 | mode = 0; |
chills | 33:3b5096f0126a | 234 | break; |
chills | 33:3b5096f0126a | 235 | } |
thomasmorris | 31:4a88bf97b53e | 236 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 237 | { |
thomasmorris | 31:4a88bf97b53e | 238 | Add_Day(); |
thomasmorris | 31:4a88bf97b53e | 239 | } |
thomasmorris | 31:4a88bf97b53e | 240 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 241 | { |
thomasmorris | 31:4a88bf97b53e | 242 | Subtract_Day(); |
thomasmorris | 32:8f2795716e97 | 243 | } |
thomasmorris | 31:4a88bf97b53e | 244 | } |
thomasmorris | 30:4cde05cc7c4f | 245 | } |
thomasmorris | 30:4cde05cc7c4f | 246 | else if(mode == 5)//Set the Hour |
thomasmorris | 30:4cde05cc7c4f | 247 | { |
chills | 34:c0b8705f183d | 248 | if(Log_Value == 1){cout << "In Mode 5" << endl;} |
thomasmorris | 31:4a88bf97b53e | 249 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 250 | while(1) |
thomasmorris | 31:4a88bf97b53e | 251 | { |
thomasmorris | 32:8f2795716e97 | 252 | LCD_Write_Hour(); |
thomasmorris | 32:8f2795716e97 | 253 | Thread::wait(1000); |
chills | 33:3b5096f0126a | 254 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 255 | { |
chills | 33:3b5096f0126a | 256 | mode = 6; |
chills | 33:3b5096f0126a | 257 | break; |
chills | 33:3b5096f0126a | 258 | } |
thomasmorris | 31:4a88bf97b53e | 259 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 260 | { |
thomasmorris | 31:4a88bf97b53e | 261 | Add_Hour(); |
thomasmorris | 31:4a88bf97b53e | 262 | } |
thomasmorris | 31:4a88bf97b53e | 263 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 264 | { |
thomasmorris | 31:4a88bf97b53e | 265 | Subtract_Hour(); |
thomasmorris | 31:4a88bf97b53e | 266 | } |
thomasmorris | 31:4a88bf97b53e | 267 | } |
thomasmorris | 30:4cde05cc7c4f | 268 | } |
thomasmorris | 30:4cde05cc7c4f | 269 | else if(mode == 6)//Set the Minute |
thomasmorris | 30:4cde05cc7c4f | 270 | { |
chills | 34:c0b8705f183d | 271 | if(Log_Value == 1){cout << "In Mode 6" << endl;} |
thomasmorris | 31:4a88bf97b53e | 272 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 273 | while(1) |
thomasmorris | 31:4a88bf97b53e | 274 | { |
thomasmorris | 32:8f2795716e97 | 275 | LCD_Write_Minute(); |
thomasmorris | 32:8f2795716e97 | 276 | Thread::wait(1000); |
chills | 33:3b5096f0126a | 277 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 278 | { |
chills | 33:3b5096f0126a | 279 | mode = 7; |
chills | 33:3b5096f0126a | 280 | break; |
chills | 33:3b5096f0126a | 281 | } |
thomasmorris | 31:4a88bf97b53e | 282 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 283 | { |
thomasmorris | 31:4a88bf97b53e | 284 | Add_Minute(); |
thomasmorris | 31:4a88bf97b53e | 285 | } |
thomasmorris | 31:4a88bf97b53e | 286 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 287 | { |
thomasmorris | 31:4a88bf97b53e | 288 | Subtract_Minute(); |
thomasmorris | 32:8f2795716e97 | 289 | } |
thomasmorris | 31:4a88bf97b53e | 290 | } |
thomasmorris | 30:4cde05cc7c4f | 291 | } |
thomasmorris | 30:4cde05cc7c4f | 292 | else if(mode == 7)//Set the Seconds |
thomasmorris | 30:4cde05cc7c4f | 293 | { |
chills | 34:c0b8705f183d | 294 | if(Log_Value == 1){cout << "In Mode 7" << endl;} |
thomasmorris | 31:4a88bf97b53e | 295 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 296 | while(1) |
thomasmorris | 31:4a88bf97b53e | 297 | { |
thomasmorris | 32:8f2795716e97 | 298 | LCD_Write_Seconds(); |
thomasmorris | 32:8f2795716e97 | 299 | Thread::wait(1000); |
chills | 33:3b5096f0126a | 300 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 301 | { |
chills | 33:3b5096f0126a | 302 | mode = 0; |
chills | 33:3b5096f0126a | 303 | break; |
chills | 33:3b5096f0126a | 304 | } |
thomasmorris | 31:4a88bf97b53e | 305 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 306 | { |
thomasmorris | 31:4a88bf97b53e | 307 | Add_Second(); |
thomasmorris | 31:4a88bf97b53e | 308 | } |
thomasmorris | 31:4a88bf97b53e | 309 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 310 | { |
thomasmorris | 31:4a88bf97b53e | 311 | Subtract_Second(); |
thomasmorris | 32:8f2795716e97 | 312 | } |
thomasmorris | 31:4a88bf97b53e | 313 | } |
thomasmorris | 30:4cde05cc7c4f | 314 | } |
thomasmorris | 30:4cde05cc7c4f | 315 | else |
thomasmorris | 30:4cde05cc7c4f | 316 | { |
thomasmorris | 30:4cde05cc7c4f | 317 | mode == 0; |
thomasmorris | 7:dfe19413fdc2 | 318 | } |
thomasmorris | 7:dfe19413fdc2 | 319 | } |
thomasmorris | 7:dfe19413fdc2 | 320 | } |
thomasmorris | 29:64b1f95a807c | 321 | void Serial_Commands()//Used for getting input from the user to determine the opperations to perform |
thomasmorris | 22:eb4cc12087b2 | 322 | { |
chills | 24:7d2da96e05ad | 323 | string Serial_Input; |
chills | 34:c0b8705f183d | 324 | int A,B,C; |
thomasmorris | 25:36699ed589ab | 325 | while(1) { |
thomasmorris | 25:36699ed589ab | 326 | Serial_Input = "Blank"; |
chills | 24:7d2da96e05ad | 327 | cout << "Please type in a command" << endl; |
chills | 34:c0b8705f183d | 328 | |
chills | 34:c0b8705f183d | 329 | cin >> Serial_Input >> A >> B >> C; |
thomasmorris | 25:36699ed589ab | 330 | |
thomasmorris | 22:eb4cc12087b2 | 331 | if (Serial_Input == "Test") |
thomasmorris | 22:eb4cc12087b2 | 332 | { |
chills | 24:7d2da96e05ad | 333 | cout << "Test Confirmed" << endl; |
chills | 34:c0b8705f183d | 334 | cout << A << " " << B << " " << C << endl; |
thomasmorris | 30:4cde05cc7c4f | 335 | cout << "This is the time " << get_current_time() << endl; |
thomasmorris | 25:36699ed589ab | 336 | } |
thomasmorris | 25:36699ed589ab | 337 | else if(Serial_Input == "READALL") |
thomasmorris | 22:eb4cc12087b2 | 338 | { |
chills | 26:78f5e454e59f | 339 | cout << "Read All Confirmed " << Sample_Rate << endl; |
chills | 26:78f5e454e59f | 340 | Console_Output_Timer.attach(&Console_Output_ISR,Sample_Rate); |
thomasmorris | 25:36699ed589ab | 341 | } |
chills | 26:78f5e454e59f | 342 | else if(Serial_Input == "DELETEALL") |
chills | 26:78f5e454e59f | 343 | { |
chills | 27:807dd5660c4b | 344 | Sampling_Timer.detach(); |
chills | 27:807dd5660c4b | 345 | Console_Output_Timer.detach(); |
thomasmorris | 29:64b1f95a807c | 346 | for (int x = 0; x < mailsize; x++) |
thomasmorris | 29:64b1f95a807c | 347 | { |
chills | 34:c0b8705f183d | 348 | |
chills | 27:807dd5660c4b | 349 | } |
chills | 27:807dd5660c4b | 350 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 27:807dd5660c4b | 351 | cout << "Sampling Restarted" << endl; |
thomasmorris | 25:36699ed589ab | 352 | } |
chills | 27:807dd5660c4b | 353 | else if(Serial_Input == "READ") |
thomasmorris | 22:eb4cc12087b2 | 354 | { |
chills | 34:c0b8705f183d | 355 | for (int x = 0; x < A; x++) |
thomasmorris | 29:64b1f95a807c | 356 | { |
thomasmorris | 29:64b1f95a807c | 357 | Serial_Comms_Stealth_Mode(); |
chills | 34:c0b8705f183d | 358 | if(Log_Value == 1){cout << "Read " << x << " samples" << endl;} |
thomasmorris | 29:64b1f95a807c | 359 | } |
thomasmorris | 25:36699ed589ab | 360 | } |
chills | 26:78f5e454e59f | 361 | else if(Serial_Input == "DELETE") |
thomasmorris | 22:eb4cc12087b2 | 362 | { |
chills | 26:78f5e454e59f | 363 | Sampling_Timer.detach(); |
chills | 26:78f5e454e59f | 364 | Console_Output_Timer.detach(); |
chills | 34:c0b8705f183d | 365 | for (int x = 0; x < A; x++){ |
chills | 34:c0b8705f183d | 366 | if(Log_Value == 1){cout << "Deleted " << x << " samples" << endl;} |
chills | 26:78f5e454e59f | 367 | } |
chills | 26:78f5e454e59f | 368 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 26:78f5e454e59f | 369 | cout << "Sampling Restarted" << endl; |
thomasmorris | 25:36699ed589ab | 370 | } |
thomasmorris | 25:36699ed589ab | 371 | else if(Serial_Input == "SETDATE") |
chills | 26:78f5e454e59f | 372 | { |
chills | 34:c0b8705f183d | 373 | set_new_date(A,B,C); |
chills | 34:c0b8705f183d | 374 | } |
chills | 34:c0b8705f183d | 375 | else if(Serial_Input == "SETTIME") |
chills | 34:c0b8705f183d | 376 | { |
chills | 34:c0b8705f183d | 377 | set_new_time(A,B,C); |
chills | 26:78f5e454e59f | 378 | } |
thomasmorris | 25:36699ed589ab | 379 | else if(Serial_Input == "SETT") |
thomasmorris | 22:eb4cc12087b2 | 380 | { |
chills | 34:c0b8705f183d | 381 | if(A >= 1){Sample_Rate = A;} |
chills | 26:78f5e454e59f | 382 | |
chills | 26:78f5e454e59f | 383 | Sampling_Timer.detach(); |
chills | 26:78f5e454e59f | 384 | Console_Output_Timer.detach(); |
chills | 26:78f5e454e59f | 385 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
thomasmorris | 25:36699ed589ab | 386 | } |
chills | 27:807dd5660c4b | 387 | else if(Serial_Input == "STATE") |
chills | 27:807dd5660c4b | 388 | { |
chills | 34:c0b8705f183d | 389 | if(A==0){Sampling_Timer.detach(); Console_Output_Timer.detach();} |
chills | 34:c0b8705f183d | 390 | if(A==1){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);} |
thomasmorris | 25:36699ed589ab | 391 | } |
chills | 34:c0b8705f183d | 392 | else if(Serial_Input == "LOGGING") |
chills | 26:78f5e454e59f | 393 | { |
chills | 34:c0b8705f183d | 394 | Log_Value = A; |
thomasmorris | 25:36699ed589ab | 395 | } |
thomasmorris | 25:36699ed589ab | 396 | else if(Serial_Input == "HELP")// Use this to display all of the availble commands |
thomasmorris | 25:36699ed589ab | 397 | { |
thomasmorris | 25:36699ed589ab | 398 | HELP(); |
thomasmorris | 22:eb4cc12087b2 | 399 | } |
chills | 26:78f5e454e59f | 400 | else if(Serial_Input == "STOP") |
chills | 26:78f5e454e59f | 401 | { |
thomasmorris | 28:09b5c46c8afd | 402 | Console_Output_Timer.detach(); //Stops Sampling |
chills | 26:78f5e454e59f | 403 | } |
thomasmorris | 30:4cde05cc7c4f | 404 | else if(Serial_Input == "Blank Blank") |
thomasmorris | 30:4cde05cc7c4f | 405 | { |
thomasmorris | 30:4cde05cc7c4f | 406 | cout << "Blank Blank complete" << endl; |
thomasmorris | 30:4cde05cc7c4f | 407 | } |
thomasmorris | 25:36699ed589ab | 408 | else |
thomasmorris | 22:eb4cc12087b2 | 409 | { |
chills | 26:78f5e454e59f | 410 | cout << "Please enter an acceptable command" << endl; |
thomasmorris | 22:eb4cc12087b2 | 411 | } |
thomasmorris | 22:eb4cc12087b2 | 412 | } |
thomasmorris | 22:eb4cc12087b2 | 413 | } |
chills | 34:c0b8705f183d | 414 | void Serial_Comms_Stealth_Mode() //Change this name |
thomasmorris | 29:64b1f95a807c | 415 | { |
chills | 34:c0b8705f183d | 416 | time_t Time = Data_Active.get_time(); |
chills | 34:c0b8705f183d | 417 | tm* Time_Pointer = localtime(&Time); |
chills | 34:c0b8705f183d | 418 | strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string |
chills | 34:c0b8705f183d | 419 | pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); |
chills | 34:c0b8705f183d | 420 | pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time |
chills | 34:c0b8705f183d | 421 | pc.printf("Temperature = %f\t", Data_Active.get_temperature()); //Print Temperature |
chills | 34:c0b8705f183d | 422 | pc.printf("Pressure = %f\t", Data_Active.get_pressure()); //Print Pressure |
chills | 34:c0b8705f183d | 423 | pc.printf("Light = %f\n\r", Data_Active.get_light()); //Print Light |
thomasmorris | 29:64b1f95a807c | 424 | |
thomasmorris | 29:64b1f95a807c | 425 | Green_led.Toggle(); |
chills | 34:c0b8705f183d | 426 | |
thomasmorris | 29:64b1f95a807c | 427 | } |
chills | 24:7d2da96e05ad | 428 | void Serial_Comms()//Thread for Serial Communications |
thomasmorris | 5:2594b953f111 | 429 | { |
thomasmorris | 25:36699ed589ab | 430 | while(1) { |
thomasmorris | 28:09b5c46c8afd | 431 | Thread::signal_wait(SerialCommsTime);//Stupid 0 Bug |
thomasmorris | 29:64b1f95a807c | 432 | Serial_Comms_Stealth_Mode(); |
thomasmorris | 5:2594b953f111 | 433 | } |
thomasmorris | 5:2594b953f111 | 434 | } |
thomasmorris | 5:2594b953f111 | 435 | |
thomasmorris | 28:09b5c46c8afd | 436 | void Console_Output_ISR() {t2.signal_set(SerialCommsTime);} |
chills | 26:78f5e454e59f | 437 | void Sampling_ISR() {t1.signal_set(SamplingTime);} |
chills | 26:78f5e454e59f | 438 | |
chills | 26:78f5e454e59f | 439 | |
thomasmorris | 5:2594b953f111 | 440 | void Sample()//Samples the hardware and prints the result to the LCD |
thomasmorris | 5:2594b953f111 | 441 | { |
thomasmorris | 30:4cde05cc7c4f | 442 | while(1) |
thomasmorris | 30:4cde05cc7c4f | 443 | { |
chills | 10:46946784326d | 444 | Thread::signal_wait(SamplingTime); //Set the time between samples |
thomasmorris | 25:36699ed589ab | 445 | |
chills | 34:c0b8705f183d | 446 | Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature |
chills | 34:c0b8705f183d | 447 | Data_Active.set_pressure(sensor.getPressure()); //Read Pressure |
chills | 34:c0b8705f183d | 448 | Data_Active.set_light(adcIn.read()); //Read Light |
chills | 33:3b5096f0126a | 449 | |
chills | 33:3b5096f0126a | 450 | Time_Lock_Main.lock(); |
chills | 34:c0b8705f183d | 451 | time_t buffer_time = time(NULL); |
chills | 33:3b5096f0126a | 452 | Time_Lock_Main.unlock(); |
thomasmorris | 25:36699ed589ab | 453 | |
chills | 34:c0b8705f183d | 454 | Data_Active.set_time(buffer_time); |
thomasmorris | 25:36699ed589ab | 455 | |
thomasmorris | 5:2594b953f111 | 456 | Red_led.Toggle(); |
thomasmorris | 5:2594b953f111 | 457 | t1.signal_set(NotSamplingTime); |
thomasmorris | 5:2594b953f111 | 458 | } |
thomasmorris | 25:36699ed589ab | 459 | } |
thomasmorris | 25:36699ed589ab | 460 | int main() |
thomasmorris | 25:36699ed589ab | 461 | { |
noutram | 1:e1cf7663f5ff | 462 | //Greeting |
chills | 16:067916791a25 | 463 | pc.printf("Test Start"); |
chills | 16:067916791a25 | 464 | pc.printf("\n\r"); |
thomasmorris | 25:36699ed589ab | 465 | |
chills | 10:46946784326d | 466 | set_time(1512940530); //Set RTC time to December 10 2017 |
thomasmorris | 30:4cde05cc7c4f | 467 | |
chills | 10:46946784326d | 468 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 469 | |
chills | 20:cbb71f84cff9 | 470 | LCD.Initialise(); |
thomasmorris | 28:09b5c46c8afd | 471 | LCD.DDRAM_Address(0x00); |
thomasmorris | 29:64b1f95a807c | 472 | |
thomasmorris | 25:36699ed589ab | 473 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 474 | |
noutram | 3:a88838ff33e7 | 475 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 476 | if ( sd.init() != 0) { |
noutram | 1:e1cf7663f5ff | 477 | printf("Init failed \n"); |
thomasmorris | 28:09b5c46c8afd | 478 | LCD.Display_Clear(); |
thomasmorris | 28:09b5c46c8afd | 479 | LCD.Write_String("CANNOT INIT SD"); //Change me |
noutram | 1:e1cf7663f5ff | 480 | errorCode(FATAL); |
thomasmorris | 25:36699ed589ab | 481 | } |
noutram | 1:e1cf7663f5ff | 482 | //Create a filing system for SD Card |
thomasmorris | 25:36699ed589ab | 483 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 484 | |
noutram | 1:e1cf7663f5ff | 485 | //Open to WRITE |
noutram | 1:e1cf7663f5ff | 486 | FILE* fp = fopen("/sd/test.csv","a"); |
noutram | 1:e1cf7663f5ff | 487 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 488 | error("Could not open file for write\n"); |
thomasmorris | 28:09b5c46c8afd | 489 | LCD.Display_Clear(); |
thomasmorris | 28:09b5c46c8afd | 490 | LCD.Write_String("CANNOT OPEN FILE\n\n");//Change me |
noutram | 1:e1cf7663f5ff | 491 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 492 | } |
noutram | 3:a88838ff33e7 | 493 | //Last message before sampling begins |
thomasmorris | 28:09b5c46c8afd | 494 | LCD.Display_Clear(); |
chills | 33:3b5096f0126a | 495 | LCD.Write_String("Ready Player"); |
thomasmorris | 31:4a88bf97b53e | 496 | LCD.DDRAM_Address(0x40); |
chills | 33:3b5096f0126a | 497 | LCD.Write_String("One"); |
thomasmorris | 31:4a88bf97b53e | 498 | LCD.DDRAM_Address(0x00); |
thomasmorris | 25:36699ed589ab | 499 | |
thomasmorris | 25:36699ed589ab | 500 | |
thomasmorris | 25:36699ed589ab | 501 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 502 | //Run interrupt |
chills | 26:78f5e454e59f | 503 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 24:7d2da96e05ad | 504 | |
thomasmorris | 5:2594b953f111 | 505 | t1.start(Sample); |
chills | 26:78f5e454e59f | 506 | t2.start(Serial_Comms); |
thomasmorris | 30:4cde05cc7c4f | 507 | t3.start(LCD_Output); |
chills | 24:7d2da96e05ad | 508 | //t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 509 | t5.start(Serial_Commands); |
thomasmorris | 25:36699ed589ab | 510 | |
thomasmorris | 5:2594b953f111 | 511 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 512 | |
thomasmorris | 5:2594b953f111 | 513 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 514 | |
thomasmorris | 5:2594b953f111 | 515 | //Thread ID |
thomasmorris | 5:2594b953f111 | 516 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 517 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 518 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 519 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 520 | id5 = t5.gettid(); |
thomasmorris | 25:36699ed589ab | 521 | |
thomasmorris | 25:36699ed589ab | 522 | while (onBoardSwitch == 0) { |
thomasmorris | 25:36699ed589ab | 523 | |
noutram | 1:e1cf7663f5ff | 524 | } |
thomasmorris | 25:36699ed589ab | 525 | |
noutram | 1:e1cf7663f5ff | 526 | //Close File |
chills | 15:c1592fc1a501 | 527 | /* |
noutram | 1:e1cf7663f5ff | 528 | fclose(fp); |
thomasmorris | 25:36699ed589ab | 529 | |
noutram | 1:e1cf7663f5ff | 530 | //Close down |
noutram | 1:e1cf7663f5ff | 531 | sd.deinit(); |
noutram | 1:e1cf7663f5ff | 532 | printf("Unmounted...\n"); |
noutram | 1:e1cf7663f5ff | 533 | lcd.cls(); |
noutram | 1:e1cf7663f5ff | 534 | lcd.printf("Unmounted...\n\n"); |
chills | 15:c1592fc1a501 | 535 | */ |
thomasmorris | 25:36699ed589ab | 536 | |
noutram | 1:e1cf7663f5ff | 537 | while(true) { |
noutram | 1:e1cf7663f5ff | 538 | greenLED = 1; |
noutram | 1:e1cf7663f5ff | 539 | wait(0.5); |
noutram | 1:e1cf7663f5ff | 540 | greenLED = 0; |
thomasmorris | 25:36699ed589ab | 541 | wait(0.1); |
noutram | 0:36e89e3ed7c4 | 542 | } |
noutram | 0:36e89e3ed7c4 | 543 | } |