![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
main.cpp@25:36699ed589ab, 2018-01-01 (annotated)
- Committer:
- thomasmorris
- Date:
- Mon Jan 01 20:14:19 2018 +0000
- Revision:
- 25:36699ed589ab
- Parent:
- 24:7d2da96e05ad
- Child:
- 26:78f5e454e59f
More Serial Comms stuff
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 | 24:7d2da96e05ad | 133 | cout << "Read All Confirmed" << endl; |
chills | 24:7d2da96e05ad | 134 | t2.start(Serial_Comms); |
thomasmorris | 25:36699ed589ab | 135 | } |
thomasmorris | 25:36699ed589ab | 136 | else if(Serial_Input == "DELETE.ALL") |
thomasmorris | 25:36699ed589ab | 137 | { |
thomasmorris | 25:36699ed589ab | 138 | |
thomasmorris | 25:36699ed589ab | 139 | } |
thomasmorris | 25:36699ed589ab | 140 | else if(Serial_Input == "READ.<n>") |
thomasmorris | 22:eb4cc12087b2 | 141 | { |
thomasmorris | 25:36699ed589ab | 142 | |
thomasmorris | 25:36699ed589ab | 143 | } |
thomasmorris | 25:36699ed589ab | 144 | else if(Serial_Input == "DELETE.<n>") |
thomasmorris | 22:eb4cc12087b2 | 145 | { |
thomasmorris | 25:36699ed589ab | 146 | |
thomasmorris | 25:36699ed589ab | 147 | } |
thomasmorris | 25:36699ed589ab | 148 | else if(Serial_Input == "SETDATE") |
thomasmorris | 25:36699ed589ab | 149 | { |
thomasmorris | 25:36699ed589ab | 150 | set_time(SETDATE()); |
thomasmorris | 25:36699ed589ab | 151 | } |
thomasmorris | 25:36699ed589ab | 152 | else if(Serial_Input == "SETT") |
thomasmorris | 22:eb4cc12087b2 | 153 | { |
thomasmorris | 25:36699ed589ab | 154 | |
thomasmorris | 25:36699ed589ab | 155 | if(SETT() >= 1) |
thomasmorris | 25:36699ed589ab | 156 | { |
thomasmorris | 25:36699ed589ab | 157 | Sample_Rate = SETT(); |
thomasmorris | 25:36699ed589ab | 158 | } |
thomasmorris | 25:36699ed589ab | 159 | else |
thomasmorris | 25:36699ed589ab | 160 | { |
thomasmorris | 25:36699ed589ab | 161 | Sample_Rate = TimerInterval; |
thomasmorris | 25:36699ed589ab | 162 | } |
thomasmorris | 25:36699ed589ab | 163 | Sample_timer.detach(); |
thomasmorris | 25:36699ed589ab | 164 | Sample_timer.attach(&Sample_signal_set,Sample_Rate); |
thomasmorris | 25:36699ed589ab | 165 | } |
thomasmorris | 25:36699ed589ab | 166 | else if(Serial_Input == "STATE.<x>") |
thomasmorris | 22:eb4cc12087b2 | 167 | { |
thomasmorris | 25:36699ed589ab | 168 | |
thomasmorris | 25:36699ed589ab | 169 | } |
thomasmorris | 25:36699ed589ab | 170 | else if(Serial_Input == "LOGGING.<x>") |
thomasmorris | 25:36699ed589ab | 171 | { |
thomasmorris | 25:36699ed589ab | 172 | |
thomasmorris | 25:36699ed589ab | 173 | } |
thomasmorris | 25:36699ed589ab | 174 | else if(Serial_Input == "HELP")// Use this to display all of the availble commands |
thomasmorris | 25:36699ed589ab | 175 | { |
thomasmorris | 25:36699ed589ab | 176 | HELP(); |
thomasmorris | 22:eb4cc12087b2 | 177 | } |
thomasmorris | 25:36699ed589ab | 178 | else |
thomasmorris | 22:eb4cc12087b2 | 179 | { |
thomasmorris | 25:36699ed589ab | 180 | cout << "Please enter a acceptable command" << endl; |
thomasmorris | 22:eb4cc12087b2 | 181 | } |
thomasmorris | 22:eb4cc12087b2 | 182 | } |
thomasmorris | 22:eb4cc12087b2 | 183 | } |
chills | 24:7d2da96e05ad | 184 | void Serial_Comms()//Thread for Serial Communications |
thomasmorris | 5:2594b953f111 | 185 | { |
chills | 24:7d2da96e05ad | 186 | cout << "In Serial Comms" << endl; |
thomasmorris | 25:36699ed589ab | 187 | while(1) { |
chills | 24:7d2da96e05ad | 188 | Thread::signal_wait(1); |
chills | 13:db857b3744c6 | 189 | osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box" |
thomasmorris | 25:36699ed589ab | 190 | |
thomasmorris | 25:36699ed589ab | 191 | if (evt_serial.status == osEventMail) { |
chills | 17:37d883f40c3d | 192 | DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox |
chills | 17:37d883f40c3d | 193 | DATA msg_serial; //Create temporary instance of DATA class |
thomasmorris | 25:36699ed589ab | 194 | |
chills | 17:37d883f40c3d | 195 | msg_serial.set_time(Rec_Data_Serial->get_time()); //Copy time from mailbox to temporary instance |
chills | 17:37d883f40c3d | 196 | msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); //Copy teperature from mailbox to temporary instance |
chills | 17:37d883f40c3d | 197 | msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); //Copy pressure from mailbox to temporary instance |
chills | 17:37d883f40c3d | 198 | msg_serial.set_light(Rec_Data_Serial->get_light()); //Copy light from mailbox to temporary instance |
chills | 17:37d883f40c3d | 199 | mail_box.free(Rec_Data_Serial); //Free space in the mailbox (delete earliest sample taken) |
thomasmorris | 25:36699ed589ab | 200 | |
chills | 17:37d883f40c3d | 201 | time_t scom_time = msg_serial.get_time(); //Declare local variable for time |
chills | 17:37d883f40c3d | 202 | strftime(scom_time_buffer, 32, "%I:%M %p\t", localtime(&scom_time)); //Format time as a string |
chills | 17:37d883f40c3d | 203 | pc.printf("Time = %s", scom_time_buffer); //Print the string formatted time |
thomasmorris | 25:36699ed589ab | 204 | |
chills | 13:db857b3744c6 | 205 | pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature |
chills | 13:db857b3744c6 | 206 | pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure |
chills | 13:db857b3744c6 | 207 | pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light |
chills | 10:46946784326d | 208 | } |
thomasmorris | 7:dfe19413fdc2 | 209 | Green_led.Toggle(); |
thomasmorris | 25:36699ed589ab | 210 | //Thread::wait(1000); |
thomasmorris | 5:2594b953f111 | 211 | } |
thomasmorris | 5:2594b953f111 | 212 | } |
thomasmorris | 5:2594b953f111 | 213 | |
chills | 10:46946784326d | 214 | void Sample_signal_set() //Sets the Signal for when to sample the sensors |
thomasmorris | 5:2594b953f111 | 215 | { |
chills | 10:46946784326d | 216 | t1.signal_set(SamplingTime); //Set the sampling thread signal high |
chills | 24:7d2da96e05ad | 217 | t2.signal_set(1); |
thomasmorris | 5:2594b953f111 | 218 | } |
thomasmorris | 5:2594b953f111 | 219 | void Sample()//Samples the hardware and prints the result to the LCD |
thomasmorris | 5:2594b953f111 | 220 | { |
thomasmorris | 25:36699ed589ab | 221 | while(1) { |
chills | 10:46946784326d | 222 | Thread::signal_wait(SamplingTime); //Set the time between samples |
thomasmorris | 25:36699ed589ab | 223 | |
chills | 10:46946784326d | 224 | temp = sensor.getTemperature(); //Read Temperature |
chills | 10:46946784326d | 225 | pressure = sensor.getPressure(); //Read Pressure |
chills | 10:46946784326d | 226 | lux = adcIn.read(); //Read Light |
chills | 16:067916791a25 | 227 | time_t buffer_time = time(NULL); //Read Time |
thomasmorris | 25:36699ed589ab | 228 | |
chills | 16:067916791a25 | 229 | DATA *Send_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data |
thomasmorris | 25:36699ed589ab | 230 | |
thomasmorris | 25:36699ed589ab | 231 | if (Send_Data == NULL) { //If Data is empty |
chills | 16:067916791a25 | 232 | //pc.printf("Out of memory\n\r"); //Print out of memory warning |
chills | 10:46946784326d | 233 | return; |
chills | 10:46946784326d | 234 | } |
thomasmorris | 25:36699ed589ab | 235 | |
chills | 10:46946784326d | 236 | Send_Data->set_time(buffer_time); //Pass in Time |
chills | 10:46946784326d | 237 | Send_Data->set_temperature(temp); //Pass in Temp |
chills | 10:46946784326d | 238 | Send_Data->set_pressure(pressure); //Pass in Pres |
chills | 10:46946784326d | 239 | Send_Data->set_light(lux); //Pass in Light |
thomasmorris | 25:36699ed589ab | 240 | |
chills | 10:46946784326d | 241 | osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox |
thomasmorris | 25:36699ed589ab | 242 | |
thomasmorris | 25:36699ed589ab | 243 | if (stat == osErrorResource) { //If mailbox overfills |
chills | 10:46946784326d | 244 | //pc.printf("queue->put() Error code: %4Xh, Resource not available\r\n", stat); //Print error message |
chills | 10:46946784326d | 245 | mail_box.free(Send_Data); //Free the mail box |
chills | 10:46946784326d | 246 | return; |
chills | 10:46946784326d | 247 | } |
thomasmorris | 5:2594b953f111 | 248 | Red_led.Toggle(); |
thomasmorris | 5:2594b953f111 | 249 | t1.signal_set(NotSamplingTime); |
thomasmorris | 5:2594b953f111 | 250 | } |
thomasmorris | 25:36699ed589ab | 251 | } |
thomasmorris | 25:36699ed589ab | 252 | int main() |
thomasmorris | 25:36699ed589ab | 253 | { |
chills | 24:7d2da96e05ad | 254 | |
thomasmorris | 25:36699ed589ab | 255 | |
thomasmorris | 25:36699ed589ab | 256 | |
noutram | 1:e1cf7663f5ff | 257 | //Greeting |
chills | 16:067916791a25 | 258 | pc.printf("Test Start"); |
chills | 16:067916791a25 | 259 | pc.printf("\n\r"); |
thomasmorris | 25:36699ed589ab | 260 | |
chills | 10:46946784326d | 261 | set_time(1512940530); //Set RTC time to December 10 2017 |
chills | 10:46946784326d | 262 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 25:36699ed589ab | 263 | |
chills | 20:cbb71f84cff9 | 264 | LCD.Initialise(); |
chills | 24:7d2da96e05ad | 265 | LCD.DDRAM_Address(0x40); |
thomasmorris | 25:36699ed589ab | 266 | |
thomasmorris | 25:36699ed589ab | 267 | |
thomasmorris | 25:36699ed589ab | 268 | post(); //Power on Self Test |
thomasmorris | 25:36699ed589ab | 269 | |
noutram | 3:a88838ff33e7 | 270 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 271 | if ( sd.init() != 0) { |
noutram | 1:e1cf7663f5ff | 272 | printf("Init failed \n"); |
chills | 24:7d2da96e05ad | 273 | lcd.cls(); |
chills | 24:7d2da96e05ad | 274 | lcd.printf("CANNOT INIT SD"); //Change me |
noutram | 1:e1cf7663f5ff | 275 | errorCode(FATAL); |
thomasmorris | 25:36699ed589ab | 276 | } |
thomasmorris | 25:36699ed589ab | 277 | |
noutram | 1:e1cf7663f5ff | 278 | //Create a filing system for SD Card |
thomasmorris | 25:36699ed589ab | 279 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 280 | |
noutram | 1:e1cf7663f5ff | 281 | //Open to WRITE |
noutram | 1:e1cf7663f5ff | 282 | FILE* fp = fopen("/sd/test.csv","a"); |
noutram | 1:e1cf7663f5ff | 283 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 284 | error("Could not open file for write\n"); |
chills | 24:7d2da96e05ad | 285 | lcd.cls(); |
chills | 24:7d2da96e05ad | 286 | lcd.printf("CANNOT OPEN FILE\n\n");//Change me |
noutram | 1:e1cf7663f5ff | 287 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 288 | } |
thomasmorris | 25:36699ed589ab | 289 | |
noutram | 3:a88838ff33e7 | 290 | //Last message before sampling begins |
chills | 24:7d2da96e05ad | 291 | lcd.cls();//change me |
chills | 24:7d2da96e05ad | 292 | lcd.printf("READY\n\n");//change me |
thomasmorris | 25:36699ed589ab | 293 | |
thomasmorris | 25:36699ed589ab | 294 | |
thomasmorris | 25:36699ed589ab | 295 | Sample_Rate = TimerInterval; |
chills | 24:7d2da96e05ad | 296 | //Run interrupt |
thomasmorris | 25:36699ed589ab | 297 | Sample_timer.attach(&Sample_signal_set,Sample_Rate); |
thomasmorris | 23:3c85d7f657a2 | 298 | SW1.fall(&SW1FallingEdge); |
chills | 24:7d2da96e05ad | 299 | |
thomasmorris | 5:2594b953f111 | 300 | t1.start(Sample); |
thomasmorris | 21:3c078c799caa | 301 | t3.start(ModeSelection); |
chills | 24:7d2da96e05ad | 302 | //t4.start(Network); |
thomasmorris | 23:3c85d7f657a2 | 303 | t5.start(Serial_Commands); |
thomasmorris | 25:36699ed589ab | 304 | |
thomasmorris | 25:36699ed589ab | 305 | |
thomasmorris | 5:2594b953f111 | 306 | //Main thread ID |
thomasmorris | 25:36699ed589ab | 307 | |
thomasmorris | 5:2594b953f111 | 308 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 25:36699ed589ab | 309 | |
thomasmorris | 5:2594b953f111 | 310 | //Thread ID |
thomasmorris | 5:2594b953f111 | 311 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 312 | id2 = t2.gettid(); |
thomasmorris | 21:3c078c799caa | 313 | id3 = t3.gettid(); |
thomasmorris | 21:3c078c799caa | 314 | id4 = t4.gettid(); |
chills | 24:7d2da96e05ad | 315 | id5 = t5.gettid(); |
thomasmorris | 25:36699ed589ab | 316 | |
thomasmorris | 25:36699ed589ab | 317 | |
thomasmorris | 5:2594b953f111 | 318 | //Toggle Green LED after a button has been pressed |
noutram | 1:e1cf7663f5ff | 319 | //Press either switch to unmount |
thomasmorris | 7:dfe19413fdc2 | 320 | DigitalIn onBoardSwitch(USER_BUTTON); |
thomasmorris | 25:36699ed589ab | 321 | |
thomasmorris | 25:36699ed589ab | 322 | while (onBoardSwitch == 0) { |
thomasmorris | 25:36699ed589ab | 323 | |
noutram | 1:e1cf7663f5ff | 324 | } |
thomasmorris | 25:36699ed589ab | 325 | |
noutram | 1:e1cf7663f5ff | 326 | //Close File |
chills | 15:c1592fc1a501 | 327 | /* |
noutram | 1:e1cf7663f5ff | 328 | fclose(fp); |
thomasmorris | 25:36699ed589ab | 329 | |
noutram | 1:e1cf7663f5ff | 330 | //Close down |
noutram | 1:e1cf7663f5ff | 331 | sd.deinit(); |
noutram | 1:e1cf7663f5ff | 332 | printf("Unmounted...\n"); |
noutram | 1:e1cf7663f5ff | 333 | lcd.cls(); |
noutram | 1:e1cf7663f5ff | 334 | lcd.printf("Unmounted...\n\n"); |
chills | 15:c1592fc1a501 | 335 | */ |
thomasmorris | 25:36699ed589ab | 336 | |
noutram | 1:e1cf7663f5ff | 337 | while(true) { |
noutram | 1:e1cf7663f5ff | 338 | greenLED = 1; |
noutram | 1:e1cf7663f5ff | 339 | wait(0.5); |
noutram | 1:e1cf7663f5ff | 340 | greenLED = 0; |
thomasmorris | 25:36699ed589ab | 341 | wait(0.1); |
noutram | 0:36e89e3ed7c4 | 342 | } |
noutram | 0:36e89e3ed7c4 | 343 | } |
noutram | 0:36e89e3ed7c4 | 344 | |
noutram | 1:e1cf7663f5ff | 345 | |
thomasmorris | 25:36699ed589ab | 346 |