FINAL PROJECT isn't it

Fork of ELEC351 by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Sat Jan 06 23:10:13 2018 +0000
Revision:
32:8f2795716e97
Parent:
31:4a88bf97b53e
Child:
33:3b5096f0126a
Working LCD time code;

Who changed what in which revision?

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