Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
main.cpp@26:78f5e454e59f, 2018-01-03 (annotated)
- Committer:
- chills
- Date:
- Wed Jan 03 15:38:40 2018 +0000
- Revision:
- 26:78f5e454e59f
- Parent:
- 25:36699ed589ab
- Child:
- 27:807dd5660c4b
2018_01_03 15:35; Read All, Stop, Delete and Delete All working.;
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 | 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 | 26:78f5e454e59f | 138 | Sampling_Timer.detach(); |
chills | 26:78f5e454e59f | 139 | Console_Output_Timer.detach(); |
chills | 26:78f5e454e59f | 140 | for (int x = 0; x < mailsize; x++){ |
chills | 26:78f5e454e59f | 141 | DATA *Delete_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data |
chills | 26:78f5e454e59f | 142 | mail_box.free(Delete_Data); //Puts "Send_Data" into the mailbox |
chills | 26:78f5e454e59f | 143 | } |
chills | 26:78f5e454e59f | 144 | Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); |
chills | 26:78f5e454e59f | 145 | cout << "Sampling Restarted" << endl; |
thomasmorris | 25:36699ed589ab | 146 | } |
thomasmorris | 25:36699ed589ab | 147 | else if(Serial_Input == "READ.<n>") |
thomasmorris | 22:eb4cc12087b2 | 148 | { |
thomasmorris | 25:36699ed589ab | 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 | } |
thomasmorris | 25:36699ed589ab | 178 | else if(Serial_Input == "STATE.<x>") |
thomasmorris | 22:eb4cc12087b2 | 179 | { |
thomasmorris | 25:36699ed589ab | 180 | |
thomasmorris | 25:36699ed589ab | 181 | } |
thomasmorris | 25:36699ed589ab | 182 | else if(Serial_Input == "LOGGING.<x>") |
chills | 26:78f5e454e59f | 183 | { |
thomasmorris | 25:36699ed589ab | 184 | |
thomasmorris | 25:36699ed589ab | 185 | } |
thomasmorris | 25:36699ed589ab | 186 | else if(Serial_Input == "HELP")// Use this to display all of the availble commands |
thomasmorris | 25:36699ed589ab | 187 | { |
thomasmorris | 25:36699ed589ab | 188 | HELP(); |
thomasmorris | 22:eb4cc12087b2 | 189 | } |
chills | 26:78f5e454e59f | 190 | else if(Serial_Input == "STOP") |
chills | 26:78f5e454e59f | 191 | { |
chills | 26:78f5e454e59f | 192 | Console_Output_Timer.detach(); |
chills | 26:78f5e454e59f | 193 | } |
thomasmorris | 25:36699ed589ab | 194 | else |
thomasmorris | 22:eb4cc12087b2 | 195 | { |
chills | 26:78f5e454e59f | 196 | cout << "Please enter an acceptable command" << endl; |
thomasmorris | 22:eb4cc12087b2 | 197 | } |
thomasmorris | 22:eb4cc12087b2 | 198 | } |
thomasmorris | 22:eb4cc12087b2 | 199 | } |
chills | 24:7d2da96e05ad | 200 | void Serial_Comms()//Thread for Serial Communications |
thomasmorris | 5:2594b953f111 | 201 | { |
thomasmorris | 25:36699ed589ab | 202 | while(1) { |
chills | 24:7d2da96e05ad | 203 | Thread::signal_wait(1); |
chills | 26:78f5e454e59f | 204 | osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box" |
thomasmorris | 25:36699ed589ab | 205 | |
thomasmorris | 25:36699ed589ab | 206 | if (evt_serial.status == osEventMail) { |
chills | 17:37d883f40c3d | 207 | DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox |
chills | 17:37d883f40c3d | 208 | DATA msg_serial; //Create temporary instance of DATA class |
thomasmorris | 25:36699ed589ab | 209 | |
chills | 17:37d883f40c3d | 210 | msg_serial.set_time(Rec_Data_Serial->get_time()); //Copy time from mailbox to temporary instance |
chills | 17:37d883f40c3d | 211 | msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); //Copy teperature from mailbox to temporary instance |
chills | 17:37d883f40c3d | 212 | msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); //Copy pressure from mailbox to temporary instance |
chills | 17:37d883f40c3d | 213 | msg_serial.set_light(Rec_Data_Serial->get_light()); //Copy light from mailbox to temporary instance |
chills | 17:37d883f40c3d | 214 | mail_box.free(Rec_Data_Serial); //Free space in the mailbox (delete earliest sample taken) |
thomasmorris | 25:36699ed589ab | 215 | |
chills | 17:37d883f40c3d | 216 | time_t scom_time = msg_serial.get_time(); //Declare local variable for time |
chills | 17:37d883f40c3d | 217 | strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time)); //Format time as a string |
chills | 17:37d883f40c3d | 218 | pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time |
thomasmorris | 25:36699ed589ab | 219 | |
chills | 13:db857b3744c6 | 220 | pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature |
chills | 13:db857b3744c6 | 221 | pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure |
chills | 13:db857b3744c6 | 222 | pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light |
chills | 10:46946784326d | 223 | } |
thomasmorris | 7:dfe19413fdc2 | 224 | Green_led.Toggle(); |
thomasmorris | 5:2594b953f111 | 225 | } |
thomasmorris | 5:2594b953f111 | 226 | } |
thomasmorris | 5:2594b953f111 | 227 | |
chills | 26:78f5e454e59f | 228 | void Console_Output_ISR() {t2.signal_set(1);} |
chills | 26:78f5e454e59f | 229 | void Sampling_ISR() {t1.signal_set(SamplingTime);} |
chills | 26:78f5e454e59f | 230 | |
chills | 26:78f5e454e59f | 231 | |
thomasmorris | 5:2594b953f111 | 232 | void Sample()//Samples the hardware and prints the result to the LCD |
thomasmorris | 5:2594b953f111 | 233 | { |
thomasmorris | 25:36699ed589ab | 234 | while(1) { |
chills | 10:46946784326d | 235 | Thread::signal_wait(SamplingTime); //Set the time between samples |
thomasmorris | 25:36699ed589ab | 236 | |
chills | 10:46946784326d | 237 | temp = sensor.getTemperature(); //Read Temperature |
chills | 10:46946784326d | 238 | pressure = sensor.getPressure(); //Read Pressure |
chills | 10:46946784326d | 239 | lux = adcIn.read(); //Read Light |
chills | 16:067916791a25 | 240 | time_t buffer_time = time(NULL); //Read Time |
thomasmorris | 25:36699ed589ab | 241 | |
chills | 16:067916791a25 | 242 | DATA *Send_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data |
thomasmorris | 25:36699ed589ab | 243 | |
thomasmorris | 25:36699ed589ab | 244 | if (Send_Data == NULL) { //If Data is empty |
chills | 16:067916791a25 | 245 | //pc.printf("Out of memory\n\r"); //Print out of memory warning |
chills | 10:46946784326d | 246 | return; |
chills | 10:46946784326d | 247 | } |
thomasmorris | 25:36699ed589ab | 248 | |
chills | 10:46946784326d | 249 | Send_Data->set_time(buffer_time); //Pass in Time |
chills | 10:46946784326d | 250 | Send_Data->set_temperature(temp); //Pass in Temp |
chills | 10:46946784326d | 251 | Send_Data->set_pressure(pressure); //Pass in Pres |
chills | 10:46946784326d | 252 | Send_Data->set_light(lux); //Pass in Light |
thomasmorris | 25:36699ed589ab | 253 | |
chills | 10:46946784326d | 254 | osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox |
thomasmorris | 25:36699ed589ab | 255 | |
thomasmorris | 25:36699ed589ab | 256 | if (stat == osErrorResource) { //If mailbox overfills |
chills | 10:46946784326d | 257 | //pc.printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat); //Print error message |
chills | 10:46946784326d | 258 | mail_box.free(Send_Data); //Free the mail box |
chills | 10:46946784326d | 259 | return; |
chills | 10:46946784326d | 260 | } |
thomasmorris | 5:2594b953f111 | 261 | Red_led.Toggle(); |
thomasmorris | 5:2594b953f111 | 262 | t1.signal_set(NotSamplingTime); |
thomasmorris | 5:2594b953f111 | 263 | } |
thomasmorris | 25:36699ed589ab | 264 | } |
thomasmorris | 25:36699ed589ab | 265 | int main() |
thomasmorris | 25:36699ed589ab | 266 | { |
noutram | 1:e1cf7663f5ff | 267 | //Greeting |
chills | 16:067916791a25 | 268 | pc.printf("Test Start"); |
chills | 16:067916791a25 | 269 | pc.printf("\n\r"); |
thomasmorris | 25:36699ed589ab | 270 | |
chills | 10:46946784326d | 271 | set_time(1512940530); //Set RTC time to December 10 2017 |
chills | 10:46946784326d | 272 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 273 | |
chills | 20:cbb71f84cff9 | 274 | LCD.Initialise(); |
chills | 24:7d2da96e05ad | 275 | LCD.DDRAM_Address(0x40); |
thomasmorris | 25:36699ed589ab | 276 | |
chills | 26:78f5e454e59f | 277 | /* |
thomasmorris | 25:36699ed589ab | 278 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 279 | |
noutram | 3:a88838ff33e7 | 280 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 281 | if ( sd.init() != 0) { |
noutram | 1:e1cf7663f5ff | 282 | printf("Init failed \n"); |
chills | 24:7d2da96e05ad | 283 | lcd.cls(); |
chills | 24:7d2da96e05ad | 284 | lcd.printf("CANNOT INIT SD"); //Change me |
noutram | 1:e1cf7663f5ff | 285 | errorCode(FATAL); |
thomasmorris | 25:36699ed589ab | 286 | } |
thomasmorris | 25:36699ed589ab | 287 | |
noutram | 1:e1cf7663f5ff | 288 | //Create a filing system for SD Card |
thomasmorris | 25:36699ed589ab | 289 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 290 | |
noutram | 1:e1cf7663f5ff | 291 | //Open to WRITE |
noutram | 1:e1cf7663f5ff | 292 | FILE* fp = fopen("/sd/test.csv","a"); |
noutram | 1:e1cf7663f5ff | 293 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 294 | error("Could not open file for write\n"); |
chills | 24:7d2da96e05ad | 295 | lcd.cls(); |
chills | 24:7d2da96e05ad | 296 | lcd.printf("CANNOT OPEN FILE\n\n");//Change me |
noutram | 1:e1cf7663f5ff | 297 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 298 | } |
chills | 26:78f5e454e59f | 299 | */ |
thomasmorris | 25:36699ed589ab | 300 | |
noutram | 3:a88838ff33e7 | 301 | //Last message before sampling begins |
chills | 24:7d2da96e05ad | 302 | lcd.cls();//change me |
chills | 24:7d2da96e05ad | 303 | lcd.printf("READY\n\n");//change me |
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 | 25:36699ed589ab | 317 | |
thomasmorris | 5:2594b953f111 | 318 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 319 | |
thomasmorris | 5:2594b953f111 | 320 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 321 | |
thomasmorris | 5:2594b953f111 | 322 | //Thread ID |
thomasmorris | 5:2594b953f111 | 323 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 324 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 325 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 326 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 327 | id5 = t5.gettid(); |
thomasmorris | 25:36699ed589ab | 328 | |
thomasmorris | 7:dfe19413fdc2 | 329 | DigitalIn onBoardSwitch(USER_BUTTON); |
thomasmorris | 25:36699ed589ab | 330 | |
thomasmorris | 25:36699ed589ab | 331 | while (onBoardSwitch == 0) { |
thomasmorris | 25:36699ed589ab | 332 | |
noutram | 1:e1cf7663f5ff | 333 | } |
thomasmorris | 25:36699ed589ab | 334 | |
noutram | 1:e1cf7663f5ff | 335 | //Close File |
chills | 15:c1592fc1a501 | 336 | /* |
noutram | 1:e1cf7663f5ff | 337 | fclose(fp); |
thomasmorris | 25:36699ed589ab | 338 | |
noutram | 1:e1cf7663f5ff | 339 | //Close down |
noutram | 1:e1cf7663f5ff | 340 | sd.deinit(); |
noutram | 1:e1cf7663f5ff | 341 | printf("Unmounted...\n"); |
noutram | 1:e1cf7663f5ff | 342 | lcd.cls(); |
noutram | 1:e1cf7663f5ff | 343 | lcd.printf("Unmounted...\n\n"); |
chills | 15:c1592fc1a501 | 344 | */ |
thomasmorris | 25:36699ed589ab | 345 | |
noutram | 1:e1cf7663f5ff | 346 | while(true) { |
noutram | 1:e1cf7663f5ff | 347 | greenLED = 1; |
noutram | 1:e1cf7663f5ff | 348 | wait(0.5); |
noutram | 1:e1cf7663f5ff | 349 | greenLED = 0; |
thomasmorris | 25:36699ed589ab | 350 | wait(0.1); |
noutram | 0:36e89e3ed7c4 | 351 | } |
noutram | 0:36e89e3ed7c4 | 352 | } |
noutram | 0:36e89e3ed7c4 | 353 | |
noutram | 1:e1cf7663f5ff | 354 | |
thomasmorris | 25:36699ed589ab | 355 |