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