Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Wed Jan 03 21:12:25 2018 +0000
Revision:
28:09b5c46c8afd
Parent:
27:807dd5660c4b
Child:
29:64b1f95a807c
Debugged Revision

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