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