Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Wed Jan 03 22:00:07 2018 +0000
Revision:
29:64b1f95a807c
Parent:
28:09b5c46c8afd
Child:
30:4cde05cc7c4f
Need to look into Serial Comms, Mail box, Network, SD Card.

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 29:64b1f95a807c 4 Current Verision 12
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 }
chills 13:db857b3744c6 32
thomasmorris 25:36699ed589ab 33 void SW1TimeOutHandler()
thomasmorris 8:0e4481b64353 34 {
thomasmorris 7:dfe19413fdc2 35 sw1TimeOut.detach(); //Stop the timeout counter firing
thomasmorris 7:dfe19413fdc2 36 SW1.fall(&SW1FallingEdge); //Now wait for a falling edge
thomasmorris 7:dfe19413fdc2 37 }
thomasmorris 29:64b1f95a807c 38 void SDWrite()
thomasmorris 12:536eca338ae8 39 {
thomasmorris 29:64b1f95a807c 40 osEvent evt_sd = mail_box.get(); //Get the latest entry from "mail_box"
thomasmorris 25:36699ed589ab 41
thomasmorris 25:36699ed589ab 42 if (evt_sd.status == osEventMail) {
chills 17:37d883f40c3d 43 DATA *Rec_Data_SD = (DATA*)evt_sd.value.p; //Create pointer to mailbox
chills 17:37d883f40c3d 44 DATA msg_sd; //Create temporary instance of DATA class
thomasmorris 25:36699ed589ab 45
chills 17:37d883f40c3d 46 msg_sd.set_time(Rec_Data_SD->get_time()); //Copy time from mailbox to temporary instance
chills 17:37d883f40c3d 47 msg_sd.set_temperature(Rec_Data_SD->get_temperature()); //Copy temperature from mailbox to temporary instance
chills 17:37d883f40c3d 48 msg_sd.set_pressure(Rec_Data_SD->get_pressure()); //Copy pressure from mailbox to temporary instance
chills 17:37d883f40c3d 49 msg_sd.set_light(Rec_Data_SD->get_light()); //Copy light from mailbox to temporary instance
chills 17:37d883f40c3d 50 mail_box.free(Rec_Data_SD); //Free space in the mailbox (delete earliest sample taken)
thomasmorris 25:36699ed589ab 51 }
thomasmorris 12:536eca338ae8 52 }
thomasmorris 7:dfe19413fdc2 53 //Interrupt service routive for SW1 falling edge (release)
thomasmorris 19:54bc302a82ea 54 void SW1FallingEdge()
thomasmorris 19:54bc302a82ea 55 {
thomasmorris 7:dfe19413fdc2 56 SW1.fall(NULL); //Disable this interrupt
thomasmorris 25:36699ed589ab 57 Yellow_led.Toggle(); //Toggle LED
thomasmorris 25:36699ed589ab 58
thomasmorris 7:dfe19413fdc2 59 mode = mode +1;//Cycles through modes
thomasmorris 25:36699ed589ab 60 if(mode >1) {
thomasmorris 25:36699ed589ab 61 mode = 0;
thomasmorris 7:dfe19413fdc2 62 }
thomasmorris 25:36699ed589ab 63
thomasmorris 25:36699ed589ab 64 sw1TimeOut.attach(&SW1TimeOutHandler, 0.2); //Start timeout counter
thomasmorris 7:dfe19413fdc2 65 }
thomasmorris 7:dfe19413fdc2 66 void ModeSelection()
thomasmorris 7:dfe19413fdc2 67 {
thomasmorris 29:64b1f95a807c 68 while(1)
thomasmorris 29:64b1f95a807c 69 {
chills 13:db857b3744c6 70 osEvent evt_lcd = mail_box.get(); //Get the latest entry from "mail_box"
thomasmorris 25:36699ed589ab 71
thomasmorris 25:36699ed589ab 72 if (evt_lcd.status == osEventMail) {
chills 17:37d883f40c3d 73 DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p; //Create pointer to mailbox
chills 17:37d883f40c3d 74 DATA msg_lcd; //Create temporary instance of DATA class
thomasmorris 25:36699ed589ab 75
chills 17:37d883f40c3d 76 msg_lcd.set_time(Rec_Data_LCD->get_time()); //Copy time from mailbox to temporary instance
chills 17:37d883f40c3d 77 msg_lcd.set_temperature(Rec_Data_LCD->get_temperature()); //Copy temperature from mailbox to temporary instance
chills 17:37d883f40c3d 78 msg_lcd.set_pressure(Rec_Data_LCD->get_pressure()); //Copy pressure from mailbox to temporary instance
chills 17:37d883f40c3d 79 msg_lcd.set_light(Rec_Data_LCD->get_light()); //Copy light from mailbox to temporary instance
chills 17:37d883f40c3d 80 mail_box.free(Rec_Data_LCD); //Free space in the mailbox (delete earliest sample taken)
thomasmorris 25:36699ed589ab 81
thomasmorris 25:36699ed589ab 82 if(mode == 0) { //Print values to the LCD
chills 13:db857b3744c6 83 //Write new data to LCD (not fast!)
thomasmorris 25:36699ed589ab 84
thomasmorris 29:64b1f95a807c 85 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 29:64b1f95a807c 86
thomasmorris 21:3c078c799caa 87 LCD.DDRAM_Address(0x00);
thomasmorris 21:3c078c799caa 88 LCD.Write_String("Temp Pres li");
thomasmorris 21:3c078c799caa 89 LCD.DDRAM_Address(0x40);
thomasmorris 29:64b1f95a807c 90 LCD.Write_String(LCD_buffer);
thomasmorris 25:36699ed589ab 91
thomasmorris 29:64b1f95a807c 92 }
thomasmorris 29:64b1f95a807c 93 else if(mode == 1) //Print the Time to the LCD
thomasmorris 29:64b1f95a807c 94 {
chills 17:37d883f40c3d 95 time_t msel_time = msg_lcd.get_time(); //Declare local variable for time
thomasmorris 18:194a606ccd47 96 strftime(scom_time_buffer, 32, "%I:%M %p", localtime(&msel_time)); //Format time as a string
thomasmorris 21:3c078c799caa 97 LCD.Display_Clear();
chills 24:7d2da96e05ad 98 LCD_sprintf = sprintf (LCD_buffer, "%s",scom_time_buffer);
thomasmorris 21:3c078c799caa 99 LCD.DDRAM_Address(0x00);
thomasmorris 21:3c078c799caa 100 LCD.Write_String("Current Time:");
thomasmorris 21:3c078c799caa 101 LCD.DDRAM_Address(0x40);
thomasmorris 21:3c078c799caa 102 LCD.Write_String(LCD_buffer);
thomasmorris 21:3c078c799caa 103
thomasmorris 29:64b1f95a807c 104 }else{mode = 0;}//Set a default mode
thomasmorris 7:dfe19413fdc2 105 }
thomasmorris 7:dfe19413fdc2 106 }
thomasmorris 7:dfe19413fdc2 107 }
thomasmorris 29:64b1f95a807c 108 void Serial_Commands()//Used for getting input from the user to determine the opperations to perform
thomasmorris 22:eb4cc12087b2 109 {
chills 24:7d2da96e05ad 110 string Serial_Input;
thomasmorris 25:36699ed589ab 111 while(1) {
thomasmorris 25:36699ed589ab 112 Serial_Input = "Blank";
chills 24:7d2da96e05ad 113 cout << "Please type in a command" << endl;
thomasmorris 25:36699ed589ab 114
thomasmorris 22:eb4cc12087b2 115 cin >> Serial_Input;
thomasmorris 25:36699ed589ab 116
thomasmorris 22:eb4cc12087b2 117 if (Serial_Input == "Test")
thomasmorris 22:eb4cc12087b2 118 {
chills 24:7d2da96e05ad 119 cout << "Test Confirmed" << endl;
thomasmorris 25:36699ed589ab 120 }
thomasmorris 25:36699ed589ab 121 else if(Serial_Input == "READALL")
thomasmorris 22:eb4cc12087b2 122 {
chills 26:78f5e454e59f 123 cout << "Read All Confirmed " << Sample_Rate << endl;
chills 26:78f5e454e59f 124 Console_Output_Timer.attach(&Console_Output_ISR,Sample_Rate);
thomasmorris 25:36699ed589ab 125 }
chills 26:78f5e454e59f 126 else if(Serial_Input == "DELETEALL")
chills 26:78f5e454e59f 127 {
chills 27:807dd5660c4b 128 Sampling_Timer.detach();
chills 27:807dd5660c4b 129 Console_Output_Timer.detach();
thomasmorris 29:64b1f95a807c 130 for (int x = 0; x < mailsize; x++)
thomasmorris 29:64b1f95a807c 131 {
chills 27:807dd5660c4b 132 DATA *Delete_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data
chills 27:807dd5660c4b 133 mail_box.free(Delete_Data); //Puts "Send_Data" into the mailbox
chills 27:807dd5660c4b 134 }
chills 27:807dd5660c4b 135 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 27:807dd5660c4b 136 cout << "Sampling Restarted" << endl;
thomasmorris 25:36699ed589ab 137 }
chills 27:807dd5660c4b 138 else if(Serial_Input == "READ")
thomasmorris 22:eb4cc12087b2 139 {
thomasmorris 29:64b1f95a807c 140 cout << "Please enter in the number of samples to read" <<endl;
thomasmorris 29:64b1f95a807c 141 int Loops; cin >> Loops;
thomasmorris 29:64b1f95a807c 142 for (int x = 0; x < Loops; x++)
thomasmorris 29:64b1f95a807c 143 {
thomasmorris 29:64b1f95a807c 144 Serial_Comms_Stealth_Mode();
thomasmorris 29:64b1f95a807c 145 }
thomasmorris 25:36699ed589ab 146 }
chills 26:78f5e454e59f 147 else if(Serial_Input == "DELETE")
thomasmorris 22:eb4cc12087b2 148 {
chills 26:78f5e454e59f 149 Sampling_Timer.detach();
chills 26:78f5e454e59f 150 Console_Output_Timer.detach();
chills 26:78f5e454e59f 151 cout << "Number of samples to delete:" << endl;
chills 26:78f5e454e59f 152 int Loops; cin >> Loops;
chills 26:78f5e454e59f 153 for (int x = 0; x < Loops; x++){
chills 26:78f5e454e59f 154 DATA *Delete_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data
chills 26:78f5e454e59f 155 mail_box.free(Delete_Data); //Puts "Send_Data" into the mailbox
chills 26:78f5e454e59f 156 }
chills 26:78f5e454e59f 157 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 26:78f5e454e59f 158 cout << "Sampling Restarted" << endl;
thomasmorris 25:36699ed589ab 159 }
thomasmorris 25:36699ed589ab 160 else if(Serial_Input == "SETDATE")
chills 26:78f5e454e59f 161 {
thomasmorris 25:36699ed589ab 162 set_time(SETDATE());
chills 26:78f5e454e59f 163 }
thomasmorris 25:36699ed589ab 164 else if(Serial_Input == "SETT")
thomasmorris 22:eb4cc12087b2 165 {
chills 26:78f5e454e59f 166 float Temp_Sample_Rate = SETT();
chills 26:78f5e454e59f 167
chills 26:78f5e454e59f 168 if(Temp_Sample_Rate >= 1){Sample_Rate = Temp_Sample_Rate;}
chills 26:78f5e454e59f 169
chills 26:78f5e454e59f 170 Sampling_Timer.detach();
chills 26:78f5e454e59f 171 Console_Output_Timer.detach();
chills 26:78f5e454e59f 172 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
thomasmorris 25:36699ed589ab 173 }
chills 27:807dd5660c4b 174 else if(Serial_Input == "STATE")
chills 27:807dd5660c4b 175 {
chills 27:807dd5660c4b 176 Sampling_Timer.detach(); Console_Output_Timer.detach();
chills 27:807dd5660c4b 177 cout << "Turn Sampling On or Off:" << endl;
chills 27:807dd5660c4b 178 string State; cin >> State;
chills 27:807dd5660c4b 179
chills 27:807dd5660c4b 180 if(State == "On"){Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);}
chills 27:807dd5660c4b 181 if(State == "Off"){Sampling_Timer.detach();}
thomasmorris 25:36699ed589ab 182 }
thomasmorris 25:36699ed589ab 183 else if(Serial_Input == "LOGGING.<x>")
chills 26:78f5e454e59f 184 {
thomasmorris 25:36699ed589ab 185
thomasmorris 25:36699ed589ab 186 }
thomasmorris 25:36699ed589ab 187 else if(Serial_Input == "HELP")// Use this to display all of the availble commands
thomasmorris 25:36699ed589ab 188 {
thomasmorris 25:36699ed589ab 189 HELP();
thomasmorris 22:eb4cc12087b2 190 }
chills 26:78f5e454e59f 191 else if(Serial_Input == "STOP")
chills 26:78f5e454e59f 192 {
thomasmorris 28:09b5c46c8afd 193 Console_Output_Timer.detach(); //Stops Sampling
chills 26:78f5e454e59f 194 }
thomasmorris 25:36699ed589ab 195 else
thomasmorris 22:eb4cc12087b2 196 {
chills 26:78f5e454e59f 197 cout << "Please enter an acceptable command" << endl;
thomasmorris 22:eb4cc12087b2 198 }
thomasmorris 22:eb4cc12087b2 199 }
thomasmorris 22:eb4cc12087b2 200 }
thomasmorris 29:64b1f95a807c 201 void Serial_Comms_Stealth_Mode()//Change this name
thomasmorris 29:64b1f95a807c 202 {
thomasmorris 29:64b1f95a807c 203 osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box"
thomasmorris 29:64b1f95a807c 204
thomasmorris 29:64b1f95a807c 205 DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox
thomasmorris 29:64b1f95a807c 206 DATA msg_serial; //Create temporary instance of DATA class
thomasmorris 29:64b1f95a807c 207
thomasmorris 29:64b1f95a807c 208 msg_serial.set_time(Rec_Data_Serial->get_time()); //Copy time from mailbox to temporary instance
thomasmorris 29:64b1f95a807c 209 msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); //Copy teperature from mailbox to temporary instance
thomasmorris 29:64b1f95a807c 210 msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); //Copy pressure from mailbox to temporary instance
thomasmorris 29:64b1f95a807c 211 msg_serial.set_light(Rec_Data_Serial->get_light()); //Copy light from mailbox to temporary instance
thomasmorris 29:64b1f95a807c 212 mail_box.free(Rec_Data_Serial); //Free space in the mailbox (delete earliest sample taken)
thomasmorris 29:64b1f95a807c 213 time_t scom_time = msg_serial.get_time(); //Declare local variable for time
thomasmorris 29:64b1f95a807c 214 strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time)); //Format time as a string
thomasmorris 29:64b1f95a807c 215 pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time
thomasmorris 29:64b1f95a807c 216 pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature
thomasmorris 29:64b1f95a807c 217 pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure
thomasmorris 29:64b1f95a807c 218 pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light
thomasmorris 29:64b1f95a807c 219
thomasmorris 29:64b1f95a807c 220 Green_led.Toggle();
thomasmorris 29:64b1f95a807c 221 }
chills 24:7d2da96e05ad 222 void Serial_Comms()//Thread for Serial Communications
thomasmorris 5:2594b953f111 223 {
thomasmorris 25:36699ed589ab 224 while(1) {
thomasmorris 28:09b5c46c8afd 225 Thread::signal_wait(SerialCommsTime);//Stupid 0 Bug
thomasmorris 29:64b1f95a807c 226 Serial_Comms_Stealth_Mode();
thomasmorris 5:2594b953f111 227 }
thomasmorris 5:2594b953f111 228 }
thomasmorris 5:2594b953f111 229
thomasmorris 28:09b5c46c8afd 230 void Console_Output_ISR() {t2.signal_set(SerialCommsTime);}
chills 26:78f5e454e59f 231 void Sampling_ISR() {t1.signal_set(SamplingTime);}
chills 26:78f5e454e59f 232
chills 26:78f5e454e59f 233
thomasmorris 5:2594b953f111 234 void Sample()//Samples the hardware and prints the result to the LCD
thomasmorris 5:2594b953f111 235 {
thomasmorris 25:36699ed589ab 236 while(1) {
chills 10:46946784326d 237 Thread::signal_wait(SamplingTime); //Set the time between samples
thomasmorris 25:36699ed589ab 238
chills 10:46946784326d 239 temp = sensor.getTemperature(); //Read Temperature
chills 10:46946784326d 240 pressure = sensor.getPressure(); //Read Pressure
chills 10:46946784326d 241 lux = adcIn.read(); //Read Light
chills 16:067916791a25 242 time_t buffer_time = time(NULL); //Read Time
thomasmorris 25:36699ed589ab 243
chills 16:067916791a25 244 DATA *Send_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data
thomasmorris 25:36699ed589ab 245
thomasmorris 25:36699ed589ab 246 if (Send_Data == NULL) { //If Data is empty
chills 16:067916791a25 247 //pc.printf("Out of memory\n\r"); //Print out of memory warning
chills 10:46946784326d 248 return;
chills 10:46946784326d 249 }
chills 10:46946784326d 250 Send_Data->set_time(buffer_time); //Pass in Time
chills 10:46946784326d 251 Send_Data->set_temperature(temp); //Pass in Temp
chills 10:46946784326d 252 Send_Data->set_pressure(pressure); //Pass in Pres
chills 10:46946784326d 253 Send_Data->set_light(lux); //Pass in Light
thomasmorris 25:36699ed589ab 254
chills 10:46946784326d 255 osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox
thomasmorris 29:64b1f95a807c 256
thomasmorris 29:64b1f95a807c 257 //if(stat == osErrorNoMemory)
thomasmorris 29:64b1f95a807c 258 // {
thomasmorris 29:64b1f95a807c 259 // mail_box.free(Send_Data);
thomasmorris 29:64b1f95a807c 260 // }
thomasmorris 25:36699ed589ab 261
thomasmorris 25:36699ed589ab 262 if (stat == osErrorResource) { //If mailbox overfills
chills 10:46946784326d 263 mail_box.free(Send_Data); //Free the mail box
chills 10:46946784326d 264 }
thomasmorris 5:2594b953f111 265 Red_led.Toggle();
thomasmorris 5:2594b953f111 266 t1.signal_set(NotSamplingTime);
thomasmorris 5:2594b953f111 267 }
thomasmorris 25:36699ed589ab 268 }
thomasmorris 25:36699ed589ab 269 int main()
thomasmorris 25:36699ed589ab 270 {
noutram 1:e1cf7663f5ff 271 //Greeting
chills 16:067916791a25 272 pc.printf("Test Start");
chills 16:067916791a25 273 pc.printf("\n\r");
thomasmorris 25:36699ed589ab 274
chills 10:46946784326d 275 set_time(1512940530); //Set RTC time to December 10 2017
chills 10:46946784326d 276 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 25:36699ed589ab 277
chills 20:cbb71f84cff9 278 LCD.Initialise();
thomasmorris 28:09b5c46c8afd 279 LCD.DDRAM_Address(0x00);
thomasmorris 29:64b1f95a807c 280
thomasmorris 25:36699ed589ab 281 post(); //Power on Self Test
thomasmorris 25:36699ed589ab 282
noutram 3:a88838ff33e7 283 //Initialise the SD card (this needs to move)
noutram 1:e1cf7663f5ff 284 if ( sd.init() != 0) {
noutram 1:e1cf7663f5ff 285 printf("Init failed \n");
thomasmorris 28:09b5c46c8afd 286 LCD.Display_Clear();
thomasmorris 28:09b5c46c8afd 287 LCD.Write_String("CANNOT INIT SD"); //Change me
noutram 1:e1cf7663f5ff 288 errorCode(FATAL);
thomasmorris 25:36699ed589ab 289 }
noutram 1:e1cf7663f5ff 290 //Create a filing system for SD Card
thomasmorris 25:36699ed589ab 291 FATFileSystem fs("sd", &sd);
noutram 0:36e89e3ed7c4 292
noutram 1:e1cf7663f5ff 293 //Open to WRITE
noutram 1:e1cf7663f5ff 294 FILE* fp = fopen("/sd/test.csv","a");
noutram 1:e1cf7663f5ff 295 if (fp == NULL) {
noutram 1:e1cf7663f5ff 296 error("Could not open file for write\n");
thomasmorris 28:09b5c46c8afd 297 LCD.Display_Clear();
thomasmorris 28:09b5c46c8afd 298 LCD.Write_String("CANNOT OPEN FILE\n\n");//Change me
noutram 1:e1cf7663f5ff 299 errorCode(FATAL);
noutram 1:e1cf7663f5ff 300 }
noutram 3:a88838ff33e7 301 //Last message before sampling begins
thomasmorris 28:09b5c46c8afd 302 LCD.Display_Clear();
thomasmorris 29:64b1f95a807c 303 LCD.Write_String("READY\n\n");
thomasmorris 25:36699ed589ab 304
thomasmorris 25:36699ed589ab 305
thomasmorris 25:36699ed589ab 306 Sample_Rate = TimerInterval;
chills 24:7d2da96e05ad 307 //Run interrupt
thomasmorris 23:3c85d7f657a2 308 SW1.fall(&SW1FallingEdge);
chills 26:78f5e454e59f 309 Sampling_Timer.attach(&Sampling_ISR,Sample_Rate);
chills 24:7d2da96e05ad 310
thomasmorris 5:2594b953f111 311 t1.start(Sample);
chills 26:78f5e454e59f 312 t2.start(Serial_Comms);
thomasmorris 21:3c078c799caa 313 t3.start(ModeSelection);
chills 24:7d2da96e05ad 314 //t4.start(Network);
thomasmorris 23:3c85d7f657a2 315 t5.start(Serial_Commands);
thomasmorris 25:36699ed589ab 316
thomasmorris 5:2594b953f111 317 //Main thread ID
thomasmorris 25:36699ed589ab 318
thomasmorris 5:2594b953f111 319 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 25:36699ed589ab 320
thomasmorris 5:2594b953f111 321 //Thread ID
thomasmorris 5:2594b953f111 322 id1 = t1.gettid();
thomasmorris 5:2594b953f111 323 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 324 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 325 id4 = t4.gettid();
chills 24:7d2da96e05ad 326 id5 = t5.gettid();
thomasmorris 25:36699ed589ab 327
thomasmorris 25:36699ed589ab 328 while (onBoardSwitch == 0) {
thomasmorris 25:36699ed589ab 329
noutram 1:e1cf7663f5ff 330 }
thomasmorris 25:36699ed589ab 331
noutram 1:e1cf7663f5ff 332 //Close File
chills 15:c1592fc1a501 333 /*
noutram 1:e1cf7663f5ff 334 fclose(fp);
thomasmorris 25:36699ed589ab 335
noutram 1:e1cf7663f5ff 336 //Close down
noutram 1:e1cf7663f5ff 337 sd.deinit();
noutram 1:e1cf7663f5ff 338 printf("Unmounted...\n");
noutram 1:e1cf7663f5ff 339 lcd.cls();
noutram 1:e1cf7663f5ff 340 lcd.printf("Unmounted...\n\n");
chills 15:c1592fc1a501 341 */
thomasmorris 25:36699ed589ab 342
noutram 1:e1cf7663f5ff 343 while(true) {
noutram 1:e1cf7663f5ff 344 greenLED = 1;
noutram 1:e1cf7663f5ff 345 wait(0.5);
noutram 1:e1cf7663f5ff 346 greenLED = 0;
thomasmorris 25:36699ed589ab 347 wait(0.1);
noutram 0:36e89e3ed7c4 348 }
noutram 0:36e89e3ed7c4 349 }