![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
main.cpp@40:d04aec00504f, 2018-01-08 (annotated)
- Committer:
- chills
- Date:
- Mon Jan 08 00:21:35 2018 +0000
- Revision:
- 40:d04aec00504f
- Parent:
- 39:5c499989d2b9
2018_01_08 00:18; All Serial Commands Working; Including Delete and Delete All
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" |
thomasmorris | 38:8d86e0d8a816 | 15 | #include "FIFO.hpp" |
thomasmorris | 38:8d86e0d8a816 | 16 | |
thomasmorris | 38:8d86e0d8a816 | 17 | #define Do_Read_Data 1 |
thomasmorris | 38:8d86e0d8a816 | 18 | #define Dont_Read_Data 0 |
thomasmorris | 38:8d86e0d8a816 | 19 | #define Do_Delete_Data 1 |
thomasmorris | 38:8d86e0d8a816 | 20 | #define Dont_Delete_Data 0 |
chills | 24:7d2da96e05ad | 21 | |
chills | 33:3b5096f0126a | 22 | Mutex Time_Lock_Main; |
thomasmorris | 38:8d86e0d8a816 | 23 | Mutex Data_Buffer_Lock; |
thomasmorris | 38:8d86e0d8a816 | 24 | |
thomasmorris | 38:8d86e0d8a816 | 25 | int Write_Data(DATA Data_Store, int Write_Pointer) |
thomasmorris | 38:8d86e0d8a816 | 26 | { |
thomasmorris | 38:8d86e0d8a816 | 27 | Data_Buffer_Lock.lock();//Mutex Lock |
thomasmorris | 38:8d86e0d8a816 | 28 | |
thomasmorris | 38:8d86e0d8a816 | 29 | Data_Buffer[Write_Pointer] = Data_Store; |
thomasmorris | 38:8d86e0d8a816 | 30 | if(Write_Pointer < mailsize - 1) |
thomasmorris | 38:8d86e0d8a816 | 31 | { |
thomasmorris | 38:8d86e0d8a816 | 32 | Write_Pointer = Write_Pointer + 1; |
thomasmorris | 38:8d86e0d8a816 | 33 | } |
thomasmorris | 38:8d86e0d8a816 | 34 | else |
thomasmorris | 38:8d86e0d8a816 | 35 | { |
thomasmorris | 38:8d86e0d8a816 | 36 | Write_Pointer = 0; |
thomasmorris | 38:8d86e0d8a816 | 37 | } |
thomasmorris | 38:8d86e0d8a816 | 38 | Data_Buffer_Lock.unlock(); |
thomasmorris | 38:8d86e0d8a816 | 39 | return Write_Pointer; |
thomasmorris | 38:8d86e0d8a816 | 40 | |
thomasmorris | 38:8d86e0d8a816 | 41 | } |
thomasmorris | 38:8d86e0d8a816 | 42 | DATA Read_Data(int Read_Pointer) |
thomasmorris | 38:8d86e0d8a816 | 43 | { |
thomasmorris | 38:8d86e0d8a816 | 44 | Data_Buffer_Lock.lock(); |
thomasmorris | 38:8d86e0d8a816 | 45 | DATA Temp_Data = Data_Buffer[Read_Pointer]; |
thomasmorris | 38:8d86e0d8a816 | 46 | Data_Buffer_Lock.unlock(); |
thomasmorris | 38:8d86e0d8a816 | 47 | |
thomasmorris | 38:8d86e0d8a816 | 48 | return Temp_Data; |
thomasmorris | 38:8d86e0d8a816 | 49 | } |
thomasmorris | 38:8d86e0d8a816 | 50 | void Delete_Data(int Delete_Pointer) |
thomasmorris | 38:8d86e0d8a816 | 51 | { |
thomasmorris | 38:8d86e0d8a816 | 52 | Data_Buffer_Lock.lock(); |
thomasmorris | 38:8d86e0d8a816 | 53 | Data_Buffer[Delete_Pointer].set_all_zero(); |
thomasmorris | 38:8d86e0d8a816 | 54 | Data_Buffer_Lock.unlock(); |
thomasmorris | 38:8d86e0d8a816 | 55 | } |
thomasmorris | 35:26b0a9b55d82 | 56 | void Network() |
thomasmorris | 8:0e4481b64353 | 57 | { |
thomasmorris | 35:26b0a9b55d82 | 58 | while(1) |
thomasmorris | 35:26b0a9b55d82 | 59 | { |
thomasmorris | 35:26b0a9b55d82 | 60 | Thread::wait(5000);//Waits 5 seconds |
thomasmorris | 37:7c4d7f206039 | 61 | if(Log_Value==1){cout << "In Network Thread" << endl;} //Log this |
thomasmorris | 36:a0098306fc58 | 62 | |
thomasmorris | 36:a0098306fc58 | 63 | time_t Time = Data_Active.get_time(); |
thomasmorris | 36:a0098306fc58 | 64 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 36:a0098306fc58 | 65 | int temp_day = Time_Pointer->tm_mday; |
thomasmorris | 36:a0098306fc58 | 66 | int temp_month = (Time_Pointer->tm_mon+1); |
thomasmorris | 36:a0098306fc58 | 67 | int temp_year = (Time_Pointer->tm_year+1900); |
thomasmorris | 36:a0098306fc58 | 68 | |
thomasmorris | 36:a0098306fc58 | 69 | int temp_hours = Time_Pointer->tm_hour; |
thomasmorris | 36:a0098306fc58 | 70 | int temp_minute = Time_Pointer->tm_min; |
thomasmorris | 36:a0098306fc58 | 71 | |
thomasmorris | 36:a0098306fc58 | 72 | float temp_temperature = Data_Active.get_temperature(); |
thomasmorris | 36:a0098306fc58 | 73 | float temp_pressure = Data_Active.get_pressure(); |
thomasmorris | 36:a0098306fc58 | 74 | float temp_light = Data_Active.get_light(); |
thomasmorris | 36:a0098306fc58 | 75 | |
thomasmorris | 36:a0098306fc58 | 76 | |
thomasmorris | 36:a0098306fc58 | 77 | Networking(temp_day,temp_month,temp_year,temp_hours,temp_minute,temp_temperature,temp_pressure,temp_light); |
thomasmorris | 35:26b0a9b55d82 | 78 | } |
chills | 13:db857b3744c6 | 79 | } |
thomasmorris | 31:4a88bf97b53e | 80 | void LCD_Write_Year() |
thomasmorris | 12:536eca338ae8 | 81 | { |
chills | 33:3b5096f0126a | 82 | Time_Lock_Main.lock(); |
thomasmorris | 37:7c4d7f206039 | 83 | if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock taken"<<endl;} |
chills | 33:3b5096f0126a | 84 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 85 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 86 | int Years = 1900 + Time_Pointer->tm_year; |
chills | 33:3b5096f0126a | 87 | Time_Lock_Main.unlock(); |
thomasmorris | 37:7c4d7f206039 | 88 | if(Log_Value == 1){cout<<"In LCD_Write_Year Time lock released"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 89 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 90 | ss << Years; |
thomasmorris | 31:4a88bf97b53e | 91 | string Year_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 92 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 93 | LCD.Write_String("Set Year"); |
thomasmorris | 31:4a88bf97b53e | 94 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 95 | LCD.Write_String(Year_String); |
thomasmorris | 30:4cde05cc7c4f | 96 | } |
thomasmorris | 25:36699ed589ab | 97 | |
thomasmorris | 31:4a88bf97b53e | 98 | void LCD_Write_Month() |
thomasmorris | 31:4a88bf97b53e | 99 | { |
chills | 33:3b5096f0126a | 100 | Time_Lock_Main.lock(); |
thomasmorris | 37:7c4d7f206039 | 101 | if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock taken"<<endl;} |
chills | 33:3b5096f0126a | 102 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 103 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 104 | int Months = 1 + Time_Pointer->tm_mon; |
chills | 33:3b5096f0126a | 105 | Time_Lock_Main.unlock(); |
thomasmorris | 37:7c4d7f206039 | 106 | if(Log_Value == 1){cout<<"In LCD_Write_Month Time lock released"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 107 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 108 | ss << Months; |
thomasmorris | 31:4a88bf97b53e | 109 | string Month_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 110 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 111 | LCD.Write_String("Set Month"); |
thomasmorris | 31:4a88bf97b53e | 112 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 113 | LCD.Write_String(Month_String); |
thomasmorris | 31:4a88bf97b53e | 114 | } |
thomasmorris | 31:4a88bf97b53e | 115 | void LCD_Write_Day() |
thomasmorris | 31:4a88bf97b53e | 116 | { |
chills | 33:3b5096f0126a | 117 | Time_Lock_Main.lock(); |
thomasmorris | 37:7c4d7f206039 | 118 | if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock taken"<<endl;} |
chills | 33:3b5096f0126a | 119 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 120 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 121 | int Days = Time_Pointer->tm_mday; |
chills | 33:3b5096f0126a | 122 | Time_Lock_Main.unlock(); |
thomasmorris | 37:7c4d7f206039 | 123 | if(Log_Value == 1){cout<<"In LCD_Write_Day Time lock released"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 124 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 125 | ss << Days; |
thomasmorris | 31:4a88bf97b53e | 126 | string Day_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 127 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 128 | LCD.Write_String("Set Day"); |
thomasmorris | 31:4a88bf97b53e | 129 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 130 | LCD.Write_String(Day_String); |
thomasmorris | 31:4a88bf97b53e | 131 | } |
thomasmorris | 31:4a88bf97b53e | 132 | |
thomasmorris | 31:4a88bf97b53e | 133 | |
thomasmorris | 31:4a88bf97b53e | 134 | void LCD_Write_Hour() |
thomasmorris | 30:4cde05cc7c4f | 135 | { |
chills | 33:3b5096f0126a | 136 | Time_Lock_Main.lock(); |
thomasmorris | 37:7c4d7f206039 | 137 | if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock taken"<<endl;} |
chills | 33:3b5096f0126a | 138 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 139 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 140 | int Hours = Time_Pointer->tm_hour; |
chills | 33:3b5096f0126a | 141 | Time_Lock_Main.unlock(); |
thomasmorris | 37:7c4d7f206039 | 142 | if(Log_Value == 1){cout<<"In LCD_Write_Hour Time lock released"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 143 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 144 | ss << Hours; |
thomasmorris | 31:4a88bf97b53e | 145 | string Hour_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 146 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 147 | LCD.Write_String("Set Hour"); |
thomasmorris | 31:4a88bf97b53e | 148 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 149 | LCD.Write_String(Hour_String); |
thomasmorris | 31:4a88bf97b53e | 150 | } |
thomasmorris | 31:4a88bf97b53e | 151 | void LCD_Write_Minute() |
thomasmorris | 31:4a88bf97b53e | 152 | { |
chills | 33:3b5096f0126a | 153 | Time_Lock_Main.lock(); |
thomasmorris | 37:7c4d7f206039 | 154 | if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock taken"<<endl;} |
chills | 33:3b5096f0126a | 155 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 156 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 157 | int Minutes = Time_Pointer->tm_min; |
chills | 33:3b5096f0126a | 158 | Time_Lock_Main.unlock(); |
thomasmorris | 37:7c4d7f206039 | 159 | if(Log_Value == 1){cout<<"In LCD_Write_Minute Time lock released"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 160 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 161 | ss << Minutes; |
thomasmorris | 31:4a88bf97b53e | 162 | string Minute_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 163 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 164 | LCD.Write_String("Set Minute"); |
thomasmorris | 31:4a88bf97b53e | 165 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 166 | LCD.Write_String(Minute_String); |
thomasmorris | 31:4a88bf97b53e | 167 | } |
thomasmorris | 31:4a88bf97b53e | 168 | void LCD_Write_Seconds() |
thomasmorris | 31:4a88bf97b53e | 169 | { |
chills | 33:3b5096f0126a | 170 | Time_Lock_Main.lock(); |
thomasmorris | 37:7c4d7f206039 | 171 | if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock taken"<<endl;} |
chills | 33:3b5096f0126a | 172 | time_t Time = time(NULL); |
chills | 33:3b5096f0126a | 173 | tm* Time_Pointer = localtime(&Time); |
chills | 33:3b5096f0126a | 174 | int Seconds = Time_Pointer->tm_sec; |
chills | 33:3b5096f0126a | 175 | Time_Lock_Main.unlock(); |
thomasmorris | 37:7c4d7f206039 | 176 | if(Log_Value == 1){cout<<"In LCD_Write_Seconds Time lock released"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 177 | stringstream ss; |
thomasmorris | 31:4a88bf97b53e | 178 | ss << Seconds; |
thomasmorris | 31:4a88bf97b53e | 179 | string Second_String = ss.str(); |
thomasmorris | 31:4a88bf97b53e | 180 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 181 | LCD.Write_String("Set Second"); |
thomasmorris | 31:4a88bf97b53e | 182 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 183 | LCD.Write_String(Second_String); |
thomasmorris | 7:dfe19413fdc2 | 184 | } |
thomasmorris | 30:4cde05cc7c4f | 185 | |
thomasmorris | 30:4cde05cc7c4f | 186 | void LCD_Output() |
chills | 34:c0b8705f183d | 187 | { |
thomasmorris | 30:4cde05cc7c4f | 188 | while(1) |
thomasmorris | 29:64b1f95a807c | 189 | { |
thomasmorris | 30:4cde05cc7c4f | 190 | Thread::wait(10);//Dont Delete |
thomasmorris | 30:4cde05cc7c4f | 191 | if(mode == 0)//Default mode |
thomasmorris | 30:4cde05cc7c4f | 192 | { |
thomasmorris | 37:7c4d7f206039 | 193 | if(Log_Value == 1){cout << "In mode 0 " << endl;}//Log this |
chills | 33:3b5096f0126a | 194 | |
thomasmorris | 35:26b0a9b55d82 | 195 | Thread::wait(Default_Mode_Toggle_Time); |
thomasmorris | 37:7c4d7f206039 | 196 | if(Log_Value == 1){cout<<"Writing Data to LCD"<<endl;} |
chills | 34:c0b8705f183d | 197 | 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 | 198 | |
thomasmorris | 30:4cde05cc7c4f | 199 | LCD.DDRAM_Address(0x00); |
thomasmorris | 30:4cde05cc7c4f | 200 | LCD.Write_String("Temp Pres li"); |
thomasmorris | 30:4cde05cc7c4f | 201 | LCD.DDRAM_Address(0x40); |
thomasmorris | 30:4cde05cc7c4f | 202 | LCD.Write_String(LCD_buffer); |
thomasmorris | 25:36699ed589ab | 203 | |
thomasmorris | 35:26b0a9b55d82 | 204 | Thread::wait(Default_Mode_Toggle_Time); |
thomasmorris | 37:7c4d7f206039 | 205 | if(Log_Value == 1){cout<<"Writing Time and Date to LCD"<<endl;} |
chills | 33:3b5096f0126a | 206 | Time_Lock_Main.lock(); |
chills | 34:c0b8705f183d | 207 | time_t Time = Data_Active.get_time(); |
chills | 34:c0b8705f183d | 208 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 30:4cde05cc7c4f | 209 | LCD.Display_Clear(); |
chills | 33:3b5096f0126a | 210 | 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 | 211 | Time_Lock_Main.unlock(); |
chills | 33:3b5096f0126a | 212 | |
thomasmorris | 30:4cde05cc7c4f | 213 | LCD.DDRAM_Address(0x00); |
thomasmorris | 30:4cde05cc7c4f | 214 | LCD.Write_String("Current Time:"); |
thomasmorris | 30:4cde05cc7c4f | 215 | LCD.DDRAM_Address(0x40); |
thomasmorris | 30:4cde05cc7c4f | 216 | LCD.Write_String(LCD_buffer); |
thomasmorris | 31:4a88bf97b53e | 217 | |
thomasmorris | 37:7c4d7f206039 | 218 | if(Log_Value == 1){cout<<"Checking Switches for next mode"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 219 | if(SW1.read() & SW2.read() == 1) |
thomasmorris | 31:4a88bf97b53e | 220 | { |
thomasmorris | 31:4a88bf97b53e | 221 | mode = 1; |
thomasmorris | 31:4a88bf97b53e | 222 | } |
thomasmorris | 30:4cde05cc7c4f | 223 | } |
thomasmorris | 30:4cde05cc7c4f | 224 | else if(mode == 1)//Choose either date setting or time setting |
thomasmorris | 30:4cde05cc7c4f | 225 | { |
chills | 34:c0b8705f183d | 226 | if(Log_Value == 1){cout << "In Mode 1" << endl;} |
thomasmorris | 30:4cde05cc7c4f | 227 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 228 | while(1) |
thomasmorris | 31:4a88bf97b53e | 229 | { |
thomasmorris | 31:4a88bf97b53e | 230 | LCD.DDRAM_Address(0x00); |
thomasmorris | 31:4a88bf97b53e | 231 | LCD.Write_String("Date Time"); |
thomasmorris | 31:4a88bf97b53e | 232 | LCD.DDRAM_Address(0x40); |
thomasmorris | 31:4a88bf97b53e | 233 | LCD.Write_String("< >"); |
thomasmorris | 31:4a88bf97b53e | 234 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 235 | if(Log_Value == 1){cout<<"Checking SW1 to go to Date setting"<<endl;} |
thomasmorris | 37:7c4d7f206039 | 236 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 237 | { |
thomasmorris | 37:7c4d7f206039 | 238 | mode = 2;//Date Setting |
thomasmorris | 31:4a88bf97b53e | 239 | break; |
thomasmorris | 31:4a88bf97b53e | 240 | } |
thomasmorris | 37:7c4d7f206039 | 241 | if(Log_Value == 1){cout<<"Checking SW2 to go to Time setting"<<endl;} |
thomasmorris | 37:7c4d7f206039 | 242 | if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 243 | { |
thomasmorris | 37:7c4d7f206039 | 244 | mode = 5;//Time Setting |
thomasmorris | 31:4a88bf97b53e | 245 | break; |
thomasmorris | 31:4a88bf97b53e | 246 | } |
thomasmorris | 31:4a88bf97b53e | 247 | } |
thomasmorris | 30:4cde05cc7c4f | 248 | } |
thomasmorris | 30:4cde05cc7c4f | 249 | else if(mode == 2)//Set the Year |
thomasmorris | 30:4cde05cc7c4f | 250 | { |
chills | 34:c0b8705f183d | 251 | if(Log_Value == 1){cout << "In Mode 2" << endl;} |
thomasmorris | 31:4a88bf97b53e | 252 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 253 | while(1) |
thomasmorris | 31:4a88bf97b53e | 254 | { |
thomasmorris | 32:8f2795716e97 | 255 | LCD_Write_Year(); |
thomasmorris | 31:4a88bf97b53e | 256 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 257 | if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Month setting"<<endl;} |
chills | 33:3b5096f0126a | 258 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 259 | { |
chills | 33:3b5096f0126a | 260 | mode = 3; |
chills | 33:3b5096f0126a | 261 | break; |
chills | 33:3b5096f0126a | 262 | } |
thomasmorris | 37:7c4d7f206039 | 263 | if(Log_Value == 1){cout<<"Checking SW1 to add Year"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 264 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 265 | { |
thomasmorris | 31:4a88bf97b53e | 266 | Add_Year(); |
thomasmorris | 31:4a88bf97b53e | 267 | } |
thomasmorris | 37:7c4d7f206039 | 268 | if(Log_Value == 1){cout<<"Checking SW2 to subtract Year"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 269 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 270 | { |
thomasmorris | 31:4a88bf97b53e | 271 | Subtract_Year(); |
thomasmorris | 31:4a88bf97b53e | 272 | } |
thomasmorris | 31:4a88bf97b53e | 273 | LCD_Write_Year(); |
thomasmorris | 31:4a88bf97b53e | 274 | } |
thomasmorris | 30:4cde05cc7c4f | 275 | } |
thomasmorris | 30:4cde05cc7c4f | 276 | else if(mode == 3)//Set the Month |
thomasmorris | 30:4cde05cc7c4f | 277 | { |
chills | 34:c0b8705f183d | 278 | if(Log_Value == 1){cout << "In Mode 3" << endl;} |
thomasmorris | 31:4a88bf97b53e | 279 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 280 | while(1) |
thomasmorris | 32:8f2795716e97 | 281 | { |
thomasmorris | 32:8f2795716e97 | 282 | LCD_Write_Month(); |
thomasmorris | 31:4a88bf97b53e | 283 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 284 | if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go to Day setting"<<endl;} |
chills | 33:3b5096f0126a | 285 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 286 | { |
chills | 33:3b5096f0126a | 287 | mode = 4; |
chills | 33:3b5096f0126a | 288 | break; |
thomasmorris | 37:7c4d7f206039 | 289 | } |
thomasmorris | 37:7c4d7f206039 | 290 | if(Log_Value == 1){cout<<"Checking SW1 to add Month"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 291 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 292 | { |
thomasmorris | 31:4a88bf97b53e | 293 | Add_Month(); |
thomasmorris | 31:4a88bf97b53e | 294 | } |
thomasmorris | 37:7c4d7f206039 | 295 | if(Log_Value == 1){cout<<"Checking SW2 to subtract Month"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 296 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 297 | { |
thomasmorris | 31:4a88bf97b53e | 298 | Subtract_Month(); |
thomasmorris | 32:8f2795716e97 | 299 | } |
chills | 33:3b5096f0126a | 300 | |
thomasmorris | 31:4a88bf97b53e | 301 | } |
thomasmorris | 30:4cde05cc7c4f | 302 | } |
thomasmorris | 30:4cde05cc7c4f | 303 | else if(mode == 4)//Set the Day |
thomasmorris | 30:4cde05cc7c4f | 304 | { |
chills | 34:c0b8705f183d | 305 | if(Log_Value == 1){cout << "In Mode 4" << endl;} |
thomasmorris | 31:4a88bf97b53e | 306 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 307 | while(1) |
thomasmorris | 32:8f2795716e97 | 308 | { |
thomasmorris | 32:8f2795716e97 | 309 | LCD_Write_Day(); |
thomasmorris | 31:4a88bf97b53e | 310 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 311 | if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;} |
chills | 33:3b5096f0126a | 312 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 313 | { |
chills | 33:3b5096f0126a | 314 | mode = 0; |
chills | 33:3b5096f0126a | 315 | break; |
chills | 33:3b5096f0126a | 316 | } |
thomasmorris | 37:7c4d7f206039 | 317 | if(Log_Value == 1){cout<<"Checking SW1 to add Day"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 318 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 319 | { |
thomasmorris | 31:4a88bf97b53e | 320 | Add_Day(); |
thomasmorris | 31:4a88bf97b53e | 321 | } |
thomasmorris | 37:7c4d7f206039 | 322 | if(Log_Value == 1){cout<<"Checking SW2 to subtract Day"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 323 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 324 | { |
thomasmorris | 31:4a88bf97b53e | 325 | Subtract_Day(); |
thomasmorris | 32:8f2795716e97 | 326 | } |
thomasmorris | 31:4a88bf97b53e | 327 | } |
thomasmorris | 30:4cde05cc7c4f | 328 | } |
thomasmorris | 30:4cde05cc7c4f | 329 | else if(mode == 5)//Set the Hour |
thomasmorris | 30:4cde05cc7c4f | 330 | { |
chills | 34:c0b8705f183d | 331 | if(Log_Value == 1){cout << "In Mode 5" << endl;} |
thomasmorris | 31:4a88bf97b53e | 332 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 333 | while(1) |
thomasmorris | 31:4a88bf97b53e | 334 | { |
thomasmorris | 32:8f2795716e97 | 335 | LCD_Write_Hour(); |
thomasmorris | 32:8f2795716e97 | 336 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 337 | if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Minute setting"<<endl;} |
chills | 33:3b5096f0126a | 338 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 339 | { |
chills | 33:3b5096f0126a | 340 | mode = 6; |
chills | 33:3b5096f0126a | 341 | break; |
thomasmorris | 37:7c4d7f206039 | 342 | } |
thomasmorris | 37:7c4d7f206039 | 343 | if(Log_Value == 1){cout<<"Checking SW1 to add Hour"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 344 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 345 | { |
thomasmorris | 31:4a88bf97b53e | 346 | Add_Hour(); |
thomasmorris | 31:4a88bf97b53e | 347 | } |
thomasmorris | 37:7c4d7f206039 | 348 | if(Log_Value == 1){cout<<"Checking SW2 to subtract Hour"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 349 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 350 | { |
thomasmorris | 31:4a88bf97b53e | 351 | Subtract_Hour(); |
thomasmorris | 31:4a88bf97b53e | 352 | } |
thomasmorris | 31:4a88bf97b53e | 353 | } |
thomasmorris | 30:4cde05cc7c4f | 354 | } |
thomasmorris | 30:4cde05cc7c4f | 355 | else if(mode == 6)//Set the Minute |
thomasmorris | 30:4cde05cc7c4f | 356 | { |
chills | 34:c0b8705f183d | 357 | if(Log_Value == 1){cout << "In Mode 6" << endl;} |
thomasmorris | 31:4a88bf97b53e | 358 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 359 | while(1) |
thomasmorris | 31:4a88bf97b53e | 360 | { |
thomasmorris | 32:8f2795716e97 | 361 | LCD_Write_Minute(); |
thomasmorris | 32:8f2795716e97 | 362 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 363 | if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Seconds setting"<<endl;} |
chills | 33:3b5096f0126a | 364 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 365 | { |
chills | 33:3b5096f0126a | 366 | mode = 7; |
chills | 33:3b5096f0126a | 367 | break; |
chills | 33:3b5096f0126a | 368 | } |
thomasmorris | 37:7c4d7f206039 | 369 | if(Log_Value == 1){cout<<"Checking SW1 to add Minute"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 370 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 371 | { |
thomasmorris | 31:4a88bf97b53e | 372 | Add_Minute(); |
thomasmorris | 31:4a88bf97b53e | 373 | } |
thomasmorris | 37:7c4d7f206039 | 374 | if(Log_Value == 1){cout<<"Checking SW2 to subtract Minute"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 375 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 376 | { |
thomasmorris | 31:4a88bf97b53e | 377 | Subtract_Minute(); |
thomasmorris | 32:8f2795716e97 | 378 | } |
thomasmorris | 31:4a88bf97b53e | 379 | } |
thomasmorris | 30:4cde05cc7c4f | 380 | } |
thomasmorris | 30:4cde05cc7c4f | 381 | else if(mode == 7)//Set the Seconds |
thomasmorris | 30:4cde05cc7c4f | 382 | { |
chills | 34:c0b8705f183d | 383 | if(Log_Value == 1){cout << "In Mode 7" << endl;} |
thomasmorris | 31:4a88bf97b53e | 384 | LCD.Display_Clear(); |
thomasmorris | 31:4a88bf97b53e | 385 | while(1) |
thomasmorris | 31:4a88bf97b53e | 386 | { |
thomasmorris | 32:8f2795716e97 | 387 | LCD_Write_Seconds(); |
thomasmorris | 32:8f2795716e97 | 388 | Thread::wait(1000); |
thomasmorris | 37:7c4d7f206039 | 389 | if(Log_Value == 1){cout<<"Checking SW1 and SW2 to go Default setting"<<endl;} |
chills | 33:3b5096f0126a | 390 | if(SW1.read() & SW2.read() == 1) |
chills | 33:3b5096f0126a | 391 | { |
chills | 33:3b5096f0126a | 392 | mode = 0; |
chills | 33:3b5096f0126a | 393 | break; |
thomasmorris | 37:7c4d7f206039 | 394 | } |
thomasmorris | 37:7c4d7f206039 | 395 | if(Log_Value == 1){cout<<"Checking SW1 to add Second"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 396 | if(SW1.read() == 1 & SW2.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 397 | { |
thomasmorris | 31:4a88bf97b53e | 398 | Add_Second(); |
thomasmorris | 31:4a88bf97b53e | 399 | } |
thomasmorris | 37:7c4d7f206039 | 400 | if(Log_Value == 1){cout<<"Checking SW1 to subtract Second"<<endl;} |
thomasmorris | 31:4a88bf97b53e | 401 | else if(SW2.read() == 1 & SW1.read() == 0) |
thomasmorris | 31:4a88bf97b53e | 402 | { |
thomasmorris | 31:4a88bf97b53e | 403 | Subtract_Second(); |
thomasmorris | 32:8f2795716e97 | 404 | } |
thomasmorris | 31:4a88bf97b53e | 405 | } |
thomasmorris | 30:4cde05cc7c4f | 406 | } |
thomasmorris | 30:4cde05cc7c4f | 407 | else |
thomasmorris | 30:4cde05cc7c4f | 408 | { |
thomasmorris | 37:7c4d7f206039 | 409 | if(Log_Value == 1){cout<<"Mode Error occured mode now set to 0"<<endl;} |
thomasmorris | 35:26b0a9b55d82 | 410 | mode = 0; |
thomasmorris | 7:dfe19413fdc2 | 411 | } |
thomasmorris | 7:dfe19413fdc2 | 412 | } |
thomasmorris | 7:dfe19413fdc2 | 413 | } |
thomasmorris | 29:64b1f95a807c | 414 | void Serial_Commands()//Used for getting input from the user to determine the opperations to perform |
thomasmorris | 22:eb4cc12087b2 | 415 | { |
thomasmorris | 37:7c4d7f206039 | 416 | |
thomasmorris | 38:8d86e0d8a816 | 417 | char input[100]; |
thomasmorris | 25:36699ed589ab | 418 | while(1) { |
thomasmorris | 38:8d86e0d8a816 | 419 | |
thomasmorris | 37:7c4d7f206039 | 420 | if(Log_Value == 1){cout<<"In Serial_Commands"<<endl;} |
thomasmorris | 38:8d86e0d8a816 | 421 | for (int x = 0; x < 100; x++){input[x] = ' ';}; |
thomasmorris | 38:8d86e0d8a816 | 422 | |
thomasmorris | 37:7c4d7f206039 | 423 | cout << "Please type in a command" << endl;//Log this |
chills | 34:c0b8705f183d | 424 | |
thomasmorris | 38:8d86e0d8a816 | 425 | cin.getline(input,sizeof(input),'\r'); |
thomasmorris | 38:8d86e0d8a816 | 426 | |
thomasmorris | 38:8d86e0d8a816 | 427 | //READ ALL FIX THIS |
thomasmorris | 39:5c499989d2b9 | 428 | if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ' & input[5] == 'A' & input[6] == 'L' & input[7] == 'L') |
thomasmorris | 22:eb4cc12087b2 | 429 | { |
thomasmorris | 39:5c499989d2b9 | 430 | |
thomasmorris | 38:8d86e0d8a816 | 431 | if(Log_Value == 1){cout<<"READ ALL Confirmed"<<endl;} |
thomasmorris | 39:5c499989d2b9 | 432 | |
thomasmorris | 39:5c499989d2b9 | 433 | Data_Buffer_Lock.lock(); |
thomasmorris | 39:5c499989d2b9 | 434 | int Start_Address_Read_All = Write_Pointer; |
thomasmorris | 39:5c499989d2b9 | 435 | Data_Buffer_Lock.unlock(); |
thomasmorris | 39:5c499989d2b9 | 436 | |
thomasmorris | 39:5c499989d2b9 | 437 | for(int x_Read_All = (Start_Address_Read_All - mailsize); x_Read_All != Start_Address_Read_All; x_Read_All = x_Read_All ) |
thomasmorris | 39:5c499989d2b9 | 438 | { |
thomasmorris | 39:5c499989d2b9 | 439 | if(x_Read_All < 0){x_Read_All = x_Read_All + mailsize;} |
thomasmorris | 39:5c499989d2b9 | 440 | else {x_Read_All = x_Read_All;} |
thomasmorris | 39:5c499989d2b9 | 441 | |
chills | 40:d04aec00504f | 442 | DATA Serial_Read_All_Data = Read_Data(x_Read_All); |
thomasmorris | 39:5c499989d2b9 | 443 | |
chills | 40:d04aec00504f | 444 | time_t Time = Serial_Read_All_Data.get_time(); |
thomasmorris | 39:5c499989d2b9 | 445 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 39:5c499989d2b9 | 446 | |
thomasmorris | 39:5c499989d2b9 | 447 | strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string |
thomasmorris | 39:5c499989d2b9 | 448 | pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); |
thomasmorris | 39:5c499989d2b9 | 449 | pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time |
chills | 40:d04aec00504f | 450 | pc.printf("Temperature = %f\t", Serial_Read_All_Data.get_temperature()); //Print Temperature |
chills | 40:d04aec00504f | 451 | pc.printf("Pressure = %f\t", Serial_Read_All_Data.get_pressure()); //Print Pressure |
chills | 40:d04aec00504f | 452 | pc.printf("Light = %f\n\r", Serial_Read_All_Data.get_light()); //Print Light |
thomasmorris | 39:5c499989d2b9 | 453 | |
thomasmorris | 39:5c499989d2b9 | 454 | if(x_Read_All == mailsize - 1){x_Read_All = 0;} |
thomasmorris | 39:5c499989d2b9 | 455 | else {x_Read_All = x_Read_All + 1;} |
thomasmorris | 39:5c499989d2b9 | 456 | } |
thomasmorris | 38:8d86e0d8a816 | 457 | } |
thomasmorris | 38:8d86e0d8a816 | 458 | |
chills | 40:d04aec00504f | 459 | //DELETE - Might have to disable sampling during this |
chills | 40:d04aec00504f | 460 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ' & input[7] == 'A' & input[8] == 'L' & input[9] == 'L') |
chills | 26:78f5e454e59f | 461 | { |
thomasmorris | 38:8d86e0d8a816 | 462 | if(Log_Value == 1){cout<<"DELETE ALL Confirmed"<<endl;} |
chills | 40:d04aec00504f | 463 | |
chills | 40:d04aec00504f | 464 | Data_Buffer_Lock.lock(); |
chills | 40:d04aec00504f | 465 | int Start_Address = Write_Pointer; |
chills | 40:d04aec00504f | 466 | Data_Buffer_Lock.unlock(); |
chills | 40:d04aec00504f | 467 | |
chills | 40:d04aec00504f | 468 | for(int x_Delete_All = (Start_Address - mailsize); x_Delete_All != Start_Address; x_Delete_All = x_Delete_All) |
chills | 40:d04aec00504f | 469 | { |
chills | 40:d04aec00504f | 470 | if(x_Delete_All < 0){x_Delete_All = x_Delete_All + mailsize;} |
chills | 40:d04aec00504f | 471 | else {x_Delete_All = x_Delete_All;} |
chills | 40:d04aec00504f | 472 | |
chills | 40:d04aec00504f | 473 | Delete_Data(x_Delete_All); |
chills | 40:d04aec00504f | 474 | |
chills | 40:d04aec00504f | 475 | if(x_Delete_All == mailsize - 1){x_Delete_All = 0;} |
chills | 40:d04aec00504f | 476 | else {x_Delete_All = x_Delete_All + 1;} |
chills | 40:d04aec00504f | 477 | |
chills | 40:d04aec00504f | 478 | } |
thomasmorris | 38:8d86e0d8a816 | 479 | } |
thomasmorris | 38:8d86e0d8a816 | 480 | |
thomasmorris | 38:8d86e0d8a816 | 481 | //READ look into this |
thomasmorris | 38:8d86e0d8a816 | 482 | else if(input[0] == 'R' & input[1] == 'E' & input[2] == 'A' & input[3] == 'D' & input[4] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 483 | { |
thomasmorris | 38:8d86e0d8a816 | 484 | int NumberOfChars = 0; int ArrayAddress = 0; string ReadNumber; int NumberToRead; |
thomasmorris | 38:8d86e0d8a816 | 485 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
chills | 40:d04aec00504f | 486 | for(int x_Read=5; x_Read < NumberOfChars; x_Read++){ReadNumber += input[x_Read];} |
thomasmorris | 38:8d86e0d8a816 | 487 | stringstream Number(ReadNumber); |
thomasmorris | 38:8d86e0d8a816 | 488 | Number >> NumberToRead; |
thomasmorris | 38:8d86e0d8a816 | 489 | |
thomasmorris | 39:5c499989d2b9 | 490 | if(Log_Value == 1){cout<<"Getting Data"<<endl;} |
thomasmorris | 39:5c499989d2b9 | 491 | |
thomasmorris | 39:5c499989d2b9 | 492 | Data_Buffer_Lock.lock(); |
thomasmorris | 39:5c499989d2b9 | 493 | int Start_Address = Write_Pointer; |
thomasmorris | 39:5c499989d2b9 | 494 | Data_Buffer_Lock.unlock(); |
thomasmorris | 39:5c499989d2b9 | 495 | |
chills | 40:d04aec00504f | 496 | for(int x_Read = (Start_Address - NumberToRead); x_Read != Start_Address; x_Read = x_Read ) |
thomasmorris | 39:5c499989d2b9 | 497 | { |
chills | 40:d04aec00504f | 498 | if(x_Read < 0) {x_Read = x_Read + mailsize;} |
chills | 40:d04aec00504f | 499 | else {x_Read = x_Read;} |
thomasmorris | 39:5c499989d2b9 | 500 | |
chills | 40:d04aec00504f | 501 | DATA Serial_Read_Data = Read_Data(x_Read); |
thomasmorris | 39:5c499989d2b9 | 502 | |
thomasmorris | 39:5c499989d2b9 | 503 | time_t Time = Serial_Read_Data.get_time(); |
thomasmorris | 39:5c499989d2b9 | 504 | tm* Time_Pointer = localtime(&Time); |
thomasmorris | 39:5c499989d2b9 | 505 | |
thomasmorris | 39:5c499989d2b9 | 506 | strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string |
thomasmorris | 39:5c499989d2b9 | 507 | pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); |
thomasmorris | 39:5c499989d2b9 | 508 | pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time |
thomasmorris | 39:5c499989d2b9 | 509 | pc.printf("Temperature = %f\t", Serial_Read_Data.get_temperature()); //Print Temperature |
thomasmorris | 39:5c499989d2b9 | 510 | pc.printf("Pressure = %f\t", Serial_Read_Data.get_pressure()); //Print Pressure |
thomasmorris | 39:5c499989d2b9 | 511 | pc.printf("Light = %f\n\r", Serial_Read_Data.get_light()); //Print Light |
thomasmorris | 39:5c499989d2b9 | 512 | |
chills | 40:d04aec00504f | 513 | if(x_Read == mailsize - 1) {x_Read = 0;} |
chills | 40:d04aec00504f | 514 | else {x_Read = x_Read + 1;} |
thomasmorris | 39:5c499989d2b9 | 515 | |
thomasmorris | 39:5c499989d2b9 | 516 | Green_led.Toggle(); |
thomasmorris | 39:5c499989d2b9 | 517 | } |
thomasmorris | 39:5c499989d2b9 | 518 | //Serial_Comms_Data_Get(); |
thomasmorris | 38:8d86e0d8a816 | 519 | if(Log_Value == 1){cout << "Read " << NumberToRead << " samples" << endl;} |
thomasmorris | 38:8d86e0d8a816 | 520 | |
thomasmorris | 25:36699ed589ab | 521 | } |
thomasmorris | 38:8d86e0d8a816 | 522 | |
chills | 40:d04aec00504f | 523 | //DELETE - Might have to disable sampling during this |
thomasmorris | 38:8d86e0d8a816 | 524 | else if(input[0] == 'D' & input[1] == 'E' & input[2] == 'L' & input[3] == 'E' & input[4] == 'T' & input[5] == 'E' & input[6] == ' ') |
thomasmorris | 22:eb4cc12087b2 | 525 | { |
thomasmorris | 38:8d86e0d8a816 | 526 | int NumberOfChars = 0; int ArrayAddress = 0; string DeleteNumber; int NumberToDelete; |
thomasmorris | 38:8d86e0d8a816 | 527 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 528 | for(int x=7; x < NumberOfChars; x++){DeleteNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 529 | stringstream Number(DeleteNumber); |
thomasmorris | 38:8d86e0d8a816 | 530 | Number >> NumberToDelete; |
thomasmorris | 38:8d86e0d8a816 | 531 | |
thomasmorris | 38:8d86e0d8a816 | 532 | if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;} |
thomasmorris | 38:8d86e0d8a816 | 533 | |
chills | 40:d04aec00504f | 534 | Data_Buffer_Lock.lock(); |
chills | 40:d04aec00504f | 535 | int Start_Address = Write_Pointer; |
chills | 40:d04aec00504f | 536 | Data_Buffer_Lock.unlock(); |
chills | 40:d04aec00504f | 537 | |
chills | 40:d04aec00504f | 538 | for(int x_Delete = (Start_Address - NumberToDelete); x_Delete != Start_Address; x_Delete = x_Delete ) |
chills | 40:d04aec00504f | 539 | { |
chills | 40:d04aec00504f | 540 | if(x_Delete < 0){x_Delete = x_Delete + mailsize;} |
chills | 40:d04aec00504f | 541 | else {x_Delete = x_Delete;} |
chills | 40:d04aec00504f | 542 | |
chills | 40:d04aec00504f | 543 | Delete_Data(x_Delete); |
chills | 40:d04aec00504f | 544 | |
chills | 40:d04aec00504f | 545 | if(x_Delete == mailsize - 1){x_Delete = 0;} |
chills | 40:d04aec00504f | 546 | else {x_Delete = x_Delete + 1;} |
chills | 40:d04aec00504f | 547 | |
chills | 40:d04aec00504f | 548 | } |
chills | 40:d04aec00504f | 549 | //Serial_Comms_Data_Get(); |
chills | 40:d04aec00504f | 550 | if(Log_Value == 1){cout << "Deleted " << NumberToDelete << " samples" << endl;} |
chills | 40:d04aec00504f | 551 | |
chills | 34:c0b8705f183d | 552 | } |
thomasmorris | 38:8d86e0d8a816 | 553 | |
thomasmorris | 38:8d86e0d8a816 | 554 | //STATE |
thomasmorris | 38:8d86e0d8a816 | 555 | else if(input[0] == 'S' & input[1] == 'T' & input[2] == 'A' & input[3] == 'T' & input[4] == 'E' & input[5] == ' ') |
chills | 34:c0b8705f183d | 556 | { |
thomasmorris | 38:8d86e0d8a816 | 557 | int NumberOfChars = 0; int ArrayAddress = 0; string StateNumber; int NumberToState; |
thomasmorris | 38:8d86e0d8a816 | 558 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 559 | for(int x=6; x < NumberOfChars; x++){StateNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 560 | stringstream Number(StateNumber); |
thomasmorris | 38:8d86e0d8a816 | 561 | Number >> NumberToState; |
thomasmorris | 38:8d86e0d8a816 | 562 | |
chills | 40:d04aec00504f | 563 | if(NumberToState==0){Sampling_Timer.detach();} |
thomasmorris | 38:8d86e0d8a816 | 564 | if(NumberToState==1){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);} |
chills | 26:78f5e454e59f | 565 | } |
thomasmorris | 38:8d86e0d8a816 | 566 | |
thomasmorris | 38:8d86e0d8a816 | 567 | //SETDATE |
thomasmorris | 38:8d86e0d8a816 | 568 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'D' & input[4] == 'A' & input[5] == 'T' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 569 | { |
thomasmorris | 38:8d86e0d8a816 | 570 | int NumberOfChars = 0; int ArrayAddress = 0; |
thomasmorris | 38:8d86e0d8a816 | 571 | string DayNumber, MonthNumber, YearNumber; |
thomasmorris | 38:8d86e0d8a816 | 572 | int NumberToDay, NumberToMonth, NumberToYear; |
thomasmorris | 38:8d86e0d8a816 | 573 | |
thomasmorris | 38:8d86e0d8a816 | 574 | for(int x=8; x < 10; x++){DayNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 575 | stringstream Number_1(DayNumber); |
thomasmorris | 38:8d86e0d8a816 | 576 | Number_1 >> NumberToDay; |
thomasmorris | 38:8d86e0d8a816 | 577 | |
thomasmorris | 38:8d86e0d8a816 | 578 | for(int x=11; x < 13; x++){MonthNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 579 | stringstream Number_2(MonthNumber); |
thomasmorris | 38:8d86e0d8a816 | 580 | Number_2 >> NumberToMonth; |
thomasmorris | 38:8d86e0d8a816 | 581 | |
thomasmorris | 38:8d86e0d8a816 | 582 | for(int x=14; x < 18; x++){YearNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 583 | stringstream Number_3(YearNumber); |
thomasmorris | 38:8d86e0d8a816 | 584 | Number_3 >> NumberToYear; |
thomasmorris | 38:8d86e0d8a816 | 585 | |
thomasmorris | 38:8d86e0d8a816 | 586 | set_new_date(NumberToDay,NumberToMonth,NumberToYear); |
thomasmorris | 38:8d86e0d8a816 | 587 | } |
thomasmorris | 38:8d86e0d8a816 | 588 | |
thomasmorris | 38:8d86e0d8a816 | 589 | //SETTIME |
thomasmorris | 38:8d86e0d8a816 | 590 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == 'I' & input[5] == 'M' & input[6] == 'E' & input[7] == ' ' & input[10] == ' ' & input[13] == ' ') |
thomasmorris | 22:eb4cc12087b2 | 591 | { |
thomasmorris | 38:8d86e0d8a816 | 592 | int NumberOfChars = 0; int ArrayAddress = 0; |
thomasmorris | 38:8d86e0d8a816 | 593 | string HourNumber, MinuteNumber, SecondNumber; |
thomasmorris | 38:8d86e0d8a816 | 594 | int NumberToHour, NumberToMinute, NumberToSecond; |
thomasmorris | 38:8d86e0d8a816 | 595 | |
thomasmorris | 38:8d86e0d8a816 | 596 | for(int x=8; x < 10; x++){HourNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 597 | stringstream Number_1(HourNumber); |
thomasmorris | 38:8d86e0d8a816 | 598 | Number_1 >> NumberToHour; |
thomasmorris | 38:8d86e0d8a816 | 599 | |
thomasmorris | 38:8d86e0d8a816 | 600 | for(int x=11; x < 13; x++){MinuteNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 601 | stringstream Number_2(MinuteNumber); |
thomasmorris | 38:8d86e0d8a816 | 602 | Number_2 >> NumberToMinute; |
thomasmorris | 38:8d86e0d8a816 | 603 | |
thomasmorris | 38:8d86e0d8a816 | 604 | for(int x=14; x < 16; x++){SecondNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 605 | stringstream Number_3(SecondNumber); |
thomasmorris | 38:8d86e0d8a816 | 606 | Number_3 >> NumberToSecond; |
thomasmorris | 38:8d86e0d8a816 | 607 | |
thomasmorris | 38:8d86e0d8a816 | 608 | set_new_time(NumberToHour,NumberToMinute,NumberToSecond); |
thomasmorris | 38:8d86e0d8a816 | 609 | } |
thomasmorris | 38:8d86e0d8a816 | 610 | |
thomasmorris | 38:8d86e0d8a816 | 611 | //SETT |
thomasmorris | 38:8d86e0d8a816 | 612 | else if(input[0] == 'S' & input[1] == 'E' & input[2] == 'T' & input[3] == 'T' & input[4] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 613 | { |
thomasmorris | 38:8d86e0d8a816 | 614 | |
thomasmorris | 38:8d86e0d8a816 | 615 | int NumberOfChars = 0; int ArrayAddress = 0; string SettNumber; int NumberToSett; |
thomasmorris | 38:8d86e0d8a816 | 616 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 617 | for(int x=5; x < NumberOfChars; x++){SettNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 618 | stringstream Number(SettNumber); |
thomasmorris | 38:8d86e0d8a816 | 619 | Number >> NumberToSett; |
thomasmorris | 38:8d86e0d8a816 | 620 | |
chills | 40:d04aec00504f | 621 | if(NumberToSett >= 0.1){Sample_Rate = NumberToSett;} |
chills | 26:78f5e454e59f | 622 | |
chills | 26:78f5e454e59f | 623 | Sampling_Timer.detach(); |
chills | 26:78f5e454e59f | 624 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
thomasmorris | 38:8d86e0d8a816 | 625 | } |
thomasmorris | 38:8d86e0d8a816 | 626 | |
thomasmorris | 38:8d86e0d8a816 | 627 | //LOGGING |
thomasmorris | 38:8d86e0d8a816 | 628 | else if(input[0] == 'L' & input[1] == 'O' & input[2] == 'G' & input[3] == 'G' & input[4] == 'I' & input[5] == 'N' & input[6] == 'G' & input[7] == ' ') |
thomasmorris | 38:8d86e0d8a816 | 629 | { |
thomasmorris | 38:8d86e0d8a816 | 630 | int NumberOfChars = 0; int ArrayAddress = 0; string LoggingNumber; int NumberToLogging; |
thomasmorris | 38:8d86e0d8a816 | 631 | while(input[ArrayAddress] != '\0'){NumberOfChars++; ArrayAddress++;} |
thomasmorris | 38:8d86e0d8a816 | 632 | for(int x=8; x < NumberOfChars; x++){LoggingNumber += input[x];} |
thomasmorris | 38:8d86e0d8a816 | 633 | stringstream Number(LoggingNumber); |
thomasmorris | 38:8d86e0d8a816 | 634 | Number >> NumberToLogging; |
thomasmorris | 38:8d86e0d8a816 | 635 | |
thomasmorris | 38:8d86e0d8a816 | 636 | cout << "Successfully entered logging" << endl; |
thomasmorris | 38:8d86e0d8a816 | 637 | cout << NumberToLogging << endl; |
thomasmorris | 38:8d86e0d8a816 | 638 | Log_Value = NumberToLogging; |
thomasmorris | 25:36699ed589ab | 639 | } |
thomasmorris | 38:8d86e0d8a816 | 640 | |
thomasmorris | 38:8d86e0d8a816 | 641 | //HELP |
thomasmorris | 38:8d86e0d8a816 | 642 | else if(input[0] == 'H' & input[1] == 'E' & input[2] == 'L' & input[3] == 'P')// Use this to display all of the availble commands |
thomasmorris | 25:36699ed589ab | 643 | { |
thomasmorris | 25:36699ed589ab | 644 | HELP(); |
thomasmorris | 22:eb4cc12087b2 | 645 | } |
thomasmorris | 38:8d86e0d8a816 | 646 | |
thomasmorris | 25:36699ed589ab | 647 | else |
thomasmorris | 22:eb4cc12087b2 | 648 | { |
chills | 26:78f5e454e59f | 649 | cout << "Please enter an acceptable command" << endl; |
thomasmorris | 22:eb4cc12087b2 | 650 | } |
thomasmorris | 22:eb4cc12087b2 | 651 | } |
thomasmorris | 22:eb4cc12087b2 | 652 | } |
thomasmorris | 38:8d86e0d8a816 | 653 | void Serial_Comms_Data_Get() |
thomasmorris | 29:64b1f95a807c | 654 | { |
thomasmorris | 37:7c4d7f206039 | 655 | if(Log_Value == 1){cout<<"Getting Data"<<endl;} |
chills | 34:c0b8705f183d | 656 | time_t Time = Data_Active.get_time(); |
chills | 34:c0b8705f183d | 657 | tm* Time_Pointer = localtime(&Time); |
chills | 34:c0b8705f183d | 658 | strftime(scom_time_buffer, 32, "%I:%M %p\t", Time_Pointer); //Format time as a string |
chills | 34:c0b8705f183d | 659 | pc.printf("Date = %d %d %d\t", Time_Pointer->tm_mday, (Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900)); |
chills | 34:c0b8705f183d | 660 | pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time |
chills | 34:c0b8705f183d | 661 | pc.printf("Temperature = %f\t", Data_Active.get_temperature()); //Print Temperature |
chills | 34:c0b8705f183d | 662 | pc.printf("Pressure = %f\t", Data_Active.get_pressure()); //Print Pressure |
chills | 34:c0b8705f183d | 663 | pc.printf("Light = %f\n\r", Data_Active.get_light()); //Print Light |
thomasmorris | 29:64b1f95a807c | 664 | |
thomasmorris | 29:64b1f95a807c | 665 | Green_led.Toggle(); |
chills | 34:c0b8705f183d | 666 | |
thomasmorris | 29:64b1f95a807c | 667 | } |
thomasmorris | 5:2594b953f111 | 668 | |
chills | 26:78f5e454e59f | 669 | void Sampling_ISR() {t1.signal_set(SamplingTime);} |
chills | 26:78f5e454e59f | 670 | |
chills | 26:78f5e454e59f | 671 | |
thomasmorris | 5:2594b953f111 | 672 | void Sample()//Samples the hardware and prints the result to the LCD |
thomasmorris | 5:2594b953f111 | 673 | { |
thomasmorris | 30:4cde05cc7c4f | 674 | while(1) |
thomasmorris | 30:4cde05cc7c4f | 675 | { |
chills | 10:46946784326d | 676 | Thread::signal_wait(SamplingTime); //Set the time between samples |
thomasmorris | 37:7c4d7f206039 | 677 | if(Log_Value == 1){cout<<"Sample Time"<<endl;} |
chills | 34:c0b8705f183d | 678 | Data_Active.set_temperature(sensor.getTemperature()); //Read Temperature |
chills | 34:c0b8705f183d | 679 | Data_Active.set_pressure(sensor.getPressure()); //Read Pressure |
chills | 34:c0b8705f183d | 680 | Data_Active.set_light(adcIn.read()); //Read Light |
chills | 33:3b5096f0126a | 681 | |
chills | 33:3b5096f0126a | 682 | Time_Lock_Main.lock(); |
chills | 34:c0b8705f183d | 683 | time_t buffer_time = time(NULL); |
chills | 33:3b5096f0126a | 684 | Time_Lock_Main.unlock(); |
thomasmorris | 25:36699ed589ab | 685 | |
chills | 34:c0b8705f183d | 686 | Data_Active.set_time(buffer_time); |
thomasmorris | 25:36699ed589ab | 687 | |
thomasmorris | 5:2594b953f111 | 688 | Red_led.Toggle(); |
thomasmorris | 39:5c499989d2b9 | 689 | Write_Pointer = Write_Data(Data_Active,Write_Pointer); |
thomasmorris | 5:2594b953f111 | 690 | t1.signal_set(NotSamplingTime); |
thomasmorris | 37:7c4d7f206039 | 691 | if(Log_Value == 1){cout<<"New Sample avaliable"<<endl;} |
thomasmorris | 5:2594b953f111 | 692 | } |
thomasmorris | 25:36699ed589ab | 693 | } |
thomasmorris | 25:36699ed589ab | 694 | int main() |
thomasmorris | 25:36699ed589ab | 695 | { |
thomasmorris | 37:7c4d7f206039 | 696 | set_time(1515352584); //Set RTC time to December 10 2017 |
thomasmorris | 30:4cde05cc7c4f | 697 | |
chills | 10:46946784326d | 698 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 699 | |
chills | 20:cbb71f84cff9 | 700 | LCD.Initialise(); |
thomasmorris | 28:09b5c46c8afd | 701 | LCD.DDRAM_Address(0x00); |
thomasmorris | 29:64b1f95a807c | 702 | |
thomasmorris | 25:36699ed589ab | 703 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 704 | |
noutram | 3:a88838ff33e7 | 705 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 706 | if ( sd.init() != 0) { |
noutram | 1:e1cf7663f5ff | 707 | printf("Init failed \n"); |
thomasmorris | 28:09b5c46c8afd | 708 | LCD.Display_Clear(); |
thomasmorris | 28:09b5c46c8afd | 709 | LCD.Write_String("CANNOT INIT SD"); //Change me |
noutram | 1:e1cf7663f5ff | 710 | errorCode(FATAL); |
thomasmorris | 25:36699ed589ab | 711 | } |
noutram | 1:e1cf7663f5ff | 712 | //Create a filing system for SD Card |
thomasmorris | 25:36699ed589ab | 713 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 714 | |
noutram | 1:e1cf7663f5ff | 715 | //Open to WRITE |
noutram | 1:e1cf7663f5ff | 716 | FILE* fp = fopen("/sd/test.csv","a"); |
noutram | 1:e1cf7663f5ff | 717 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 718 | error("Could not open file for write\n"); |
thomasmorris | 28:09b5c46c8afd | 719 | LCD.Display_Clear(); |
thomasmorris | 37:7c4d7f206039 | 720 | LCD.Write_String("CANNOT OPEN FILE"); |
noutram | 1:e1cf7663f5ff | 721 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 722 | } |
thomasmorris | 37:7c4d7f206039 | 723 | int network_temp; |
thomasmorris | 37:7c4d7f206039 | 724 | network_temp = Network_Init(); |
thomasmorris | 37:7c4d7f206039 | 725 | if(network_temp == 1)//Sets up the network and checks if the network cable is not pluged in |
thomasmorris | 37:7c4d7f206039 | 726 | { |
thomasmorris | 37:7c4d7f206039 | 727 | error("Could not access network"); |
thomasmorris | 37:7c4d7f206039 | 728 | LCD.Display_Clear(); |
thomasmorris | 37:7c4d7f206039 | 729 | LCD.Write_String("Could not access network"); |
thomasmorris | 37:7c4d7f206039 | 730 | errorCode(FATAL); |
thomasmorris | 37:7c4d7f206039 | 731 | } |
noutram | 3:a88838ff33e7 | 732 | //Last message before sampling begins |
thomasmorris | 28:09b5c46c8afd | 733 | LCD.Display_Clear(); |
thomasmorris | 35:26b0a9b55d82 | 734 | LCD.Write_String("READY PLAYER"); |
thomasmorris | 31:4a88bf97b53e | 735 | LCD.DDRAM_Address(0x40); |
thomasmorris | 35:26b0a9b55d82 | 736 | LCD.Write_String(" One "); |
thomasmorris | 31:4a88bf97b53e | 737 | LCD.DDRAM_Address(0x00); |
thomasmorris | 25:36699ed589ab | 738 | |
thomasmorris | 25:36699ed589ab | 739 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 740 | //Run interrupt |
chills | 26:78f5e454e59f | 741 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 24:7d2da96e05ad | 742 | |
thomasmorris | 5:2594b953f111 | 743 | t1.start(Sample); |
thomasmorris | 30:4cde05cc7c4f | 744 | t3.start(LCD_Output); |
thomasmorris | 35:26b0a9b55d82 | 745 | t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 746 | t5.start(Serial_Commands); |
thomasmorris | 25:36699ed589ab | 747 | |
thomasmorris | 5:2594b953f111 | 748 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 749 | |
thomasmorris | 5:2594b953f111 | 750 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 751 | |
thomasmorris | 5:2594b953f111 | 752 | //Thread ID |
thomasmorris | 5:2594b953f111 | 753 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 754 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 755 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 756 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 757 | id5 = t5.gettid(); |
thomasmorris | 25:36699ed589ab | 758 | |
thomasmorris | 25:36699ed589ab | 759 | while (onBoardSwitch == 0) { |
thomasmorris | 25:36699ed589ab | 760 | |
noutram | 1:e1cf7663f5ff | 761 | } |
thomasmorris | 25:36699ed589ab | 762 | |
noutram | 1:e1cf7663f5ff | 763 | //Close File |
chills | 15:c1592fc1a501 | 764 | /* |
noutram | 1:e1cf7663f5ff | 765 | fclose(fp); |
thomasmorris | 25:36699ed589ab | 766 | |
noutram | 1:e1cf7663f5ff | 767 | //Close down |
noutram | 1:e1cf7663f5ff | 768 | sd.deinit(); |
noutram | 1:e1cf7663f5ff | 769 | printf("Unmounted...\n"); |
noutram | 1:e1cf7663f5ff | 770 | lcd.cls(); |
noutram | 1:e1cf7663f5ff | 771 | lcd.printf("Unmounted...\n\n"); |
chills | 15:c1592fc1a501 | 772 | */ |
thomasmorris | 25:36699ed589ab | 773 | |
noutram | 1:e1cf7663f5ff | 774 | while(true) { |
noutram | 1:e1cf7663f5ff | 775 | greenLED = 1; |
noutram | 1:e1cf7663f5ff | 776 | wait(0.5); |
noutram | 1:e1cf7663f5ff | 777 | greenLED = 0; |
thomasmorris | 25:36699ed589ab | 778 | wait(0.1); |
noutram | 0:36e89e3ed7c4 | 779 | } |
noutram | 0:36e89e3ed7c4 | 780 | } |