Thomas Morris
/
PROJ324_Final
Proj 324 Final
Fork of ELEC351_Group_T by
main.cpp@14:45630ba388e1, 2017-12-20 (annotated)
- Committer:
- chills
- Date:
- Wed Dec 20 21:32:57 2017 +0000
- Revision:
- 14:45630ba388e1
- Parent:
- 13:db857b3744c6
2017_12_20 21:30; Multiple mail boxes, first attempt;
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 |
noutram | 1:e1cf7663f5ff | 15 | #include "sample_hardware.hpp" |
noutram | 3:a88838ff33e7 | 16 | #include "Networkbits.hpp" |
thomasmorris | 5:2594b953f111 | 17 | #include "rtos.h" |
thomasmorris | 5:2594b953f111 | 18 | #include "LED.hpp" |
thomasmorris | 8:0e4481b64353 | 19 | #include "DATA.hpp" |
thomasmorris | 8:0e4481b64353 | 20 | #include "NETWORK.hpp" |
thomasmorris | 5:2594b953f111 | 21 | #define SamplingTime 1 |
thomasmorris | 5:2594b953f111 | 22 | #define NotSamplingTime 0 |
thomasmorris | 7:dfe19413fdc2 | 23 | #define Print_Time_to_LCD 1 |
thomasmorris | 7:dfe19413fdc2 | 24 | #define Dont_Print_Time_to_LCD 0 |
thomasmorris | 5:2594b953f111 | 25 | #define TimerInterval 15 //This is in seconds |
thomasmorris | 7:dfe19413fdc2 | 26 | #define EDGE_RISEN 1 |
thomasmorris | 7:dfe19413fdc2 | 27 | #define EDGE_FALLEN 0 |
thomasmorris | 8:0e4481b64353 | 28 | |
thomasmorris | 8:0e4481b64353 | 29 | |
thomasmorris | 5:2594b953f111 | 30 | Serial pc(USBTX, USBRX); |
thomasmorris | 7:dfe19413fdc2 | 31 | //SW1+SW2 are declared as interrupt ins in sample hardwarec.pp |
thomasmorris | 8:0e4481b64353 | 32 | |
thomasmorris | 8:0e4481b64353 | 33 | |
thomasmorris | 8:0e4481b64353 | 34 | //Thread IDs |
thomasmorris | 5:2594b953f111 | 35 | osThreadId idMain; |
thomasmorris | 5:2594b953f111 | 36 | osThreadId id1; |
thomasmorris | 5:2594b953f111 | 37 | osThreadId id2; |
thomasmorris | 5:2594b953f111 | 38 | osThreadId id3; |
thomasmorris | 5:2594b953f111 | 39 | osThreadId id4; |
noutram | 0:36e89e3ed7c4 | 40 | |
thomasmorris | 7:dfe19413fdc2 | 41 | Timeout sw1TimeOut;//Used to prevent switch bounce |
thomasmorris | 7:dfe19413fdc2 | 42 | |
thomasmorris | 5:2594b953f111 | 43 | LED Red_led(PE_15); |
thomasmorris | 5:2594b953f111 | 44 | LED Yellow_led(PB_10); |
thomasmorris | 5:2594b953f111 | 45 | LED Green_led(PB_11); |
thomasmorris | 5:2594b953f111 | 46 | |
thomasmorris | 8:0e4481b64353 | 47 | //Tickers |
thomasmorris | 8:0e4481b64353 | 48 | |
thomasmorris | 5:2594b953f111 | 49 | Ticker Sample_timer; |
thomasmorris | 8:0e4481b64353 | 50 | |
noutram | 3:a88838ff33e7 | 51 | //Threads |
thomasmorris | 5:2594b953f111 | 52 | Thread t1; |
thomasmorris | 5:2594b953f111 | 53 | Thread t2; |
thomasmorris | 7:dfe19413fdc2 | 54 | Thread t3; |
thomasmorris | 7:dfe19413fdc2 | 55 | Thread t4; |
thomasmorris | 7:dfe19413fdc2 | 56 | Thread t5; |
thomasmorris | 7:dfe19413fdc2 | 57 | Thread t6; |
thomasmorris | 7:dfe19413fdc2 | 58 | |
thomasmorris | 7:dfe19413fdc2 | 59 | double temp = 0; |
thomasmorris | 7:dfe19413fdc2 | 60 | double pressure = 0; |
thomasmorris | 7:dfe19413fdc2 | 61 | double lux = 0; |
chills | 10:46946784326d | 62 | string buffer_time = 0; |
thomasmorris | 7:dfe19413fdc2 | 63 | |
thomasmorris | 7:dfe19413fdc2 | 64 | char buffer[32]; |
thomasmorris | 7:dfe19413fdc2 | 65 | |
thomasmorris | 7:dfe19413fdc2 | 66 | |
thomasmorris | 7:dfe19413fdc2 | 67 | void SW1FallingEdge(); |
thomasmorris | 7:dfe19413fdc2 | 68 | void SW1TimeOutHandler(); |
thomasmorris | 7:dfe19413fdc2 | 69 | |
thomasmorris | 7:dfe19413fdc2 | 70 | int mode = 0; |
thomasmorris | 7:dfe19413fdc2 | 71 | |
chills | 14:45630ba388e1 | 72 | Mail<DATA, 120> mail_box_network; //Mail Queue, Type DATA, Capacity 120, name mail_box_network |
chills | 14:45630ba388e1 | 73 | Mail<DATA, 120> mail_box_sd; //Mail Queue, Type DATA, Capacity 120, name mail_box_sd |
chills | 14:45630ba388e1 | 74 | Mail<DATA, 120> mail_box_lcd; //Mail Queue, Type DATA, Capacity 120, name mail_box_lcd |
chills | 14:45630ba388e1 | 75 | Mail<DATA, 120> mail_box_serial; //Mail Queue, Type DATA, Capacity 120, name mail_box_serial |
thomasmorris | 8:0e4481b64353 | 76 | |
chills | 13:db857b3744c6 | 77 | void Network() //Interrupt service routine for handling the timeout |
thomasmorris | 8:0e4481b64353 | 78 | { |
chills | 14:45630ba388e1 | 79 | osEvent evt_network = mail_box_network.get(); //Get the latest entry from "mail_box" |
chills | 13:db857b3744c6 | 80 | |
chills | 13:db857b3744c6 | 81 | if (evt_network.status == osEventMail) |
chills | 13:db857b3744c6 | 82 | { |
chills | 13:db857b3744c6 | 83 | DATA *Rec_Data_Network = (DATA*)evt_network.value.p; |
chills | 13:db857b3744c6 | 84 | DATA msg_network; |
chills | 13:db857b3744c6 | 85 | |
chills | 13:db857b3744c6 | 86 | msg_network.set_time(Rec_Data_Network->get_time()); |
chills | 13:db857b3744c6 | 87 | msg_network.set_temperature(Rec_Data_Network->get_temperature()); |
chills | 13:db857b3744c6 | 88 | msg_network.set_pressure(Rec_Data_Network->get_pressure()); |
chills | 13:db857b3744c6 | 89 | msg_network.set_light(Rec_Data_Network->get_light()); |
chills | 13:db857b3744c6 | 90 | |
chills | 13:db857b3744c6 | 91 | //NETWORK_Print(); //Runs the network |
chills | 13:db857b3744c6 | 92 | } |
chills | 13:db857b3744c6 | 93 | } |
chills | 13:db857b3744c6 | 94 | |
thomasmorris | 8:0e4481b64353 | 95 | void SW1TimeOutHandler() |
thomasmorris | 8:0e4481b64353 | 96 | { |
thomasmorris | 7:dfe19413fdc2 | 97 | sw1TimeOut.detach(); //Stop the timeout counter firing |
thomasmorris | 7:dfe19413fdc2 | 98 | SW1.fall(&SW1FallingEdge); //Now wait for a falling edge |
thomasmorris | 7:dfe19413fdc2 | 99 | } |
thomasmorris | 12:536eca338ae8 | 100 | void SDWrite()//End of skype chat |
thomasmorris | 12:536eca338ae8 | 101 | { |
chills | 14:45630ba388e1 | 102 | osEvent evt_sd = mail_box_sd.get(); //Get the latest entry from "mail_box" |
chills | 13:db857b3744c6 | 103 | |
chills | 13:db857b3744c6 | 104 | if (evt_sd.status == osEventMail) |
chills | 13:db857b3744c6 | 105 | { |
chills | 13:db857b3744c6 | 106 | DATA *Rec_Data_SD = (DATA*)evt_sd.value.p; |
chills | 13:db857b3744c6 | 107 | DATA msg_sd; |
chills | 13:db857b3744c6 | 108 | |
chills | 13:db857b3744c6 | 109 | msg_sd.set_time(Rec_Data_SD->get_time()); |
chills | 13:db857b3744c6 | 110 | msg_sd.set_temperature(Rec_Data_SD->get_temperature()); |
chills | 13:db857b3744c6 | 111 | msg_sd.set_pressure(Rec_Data_SD->get_pressure()); |
chills | 13:db857b3744c6 | 112 | msg_sd.set_light(Rec_Data_SD->get_light()); |
chills | 13:db857b3744c6 | 113 | } |
thomasmorris | 12:536eca338ae8 | 114 | } |
thomasmorris | 7:dfe19413fdc2 | 115 | //Interrupt service routive for SW1 falling edge (release) |
thomasmorris | 7:dfe19413fdc2 | 116 | void SW1FallingEdge() { |
thomasmorris | 7:dfe19413fdc2 | 117 | SW1.fall(NULL); //Disable this interrupt |
thomasmorris | 7:dfe19413fdc2 | 118 | Yellow_led.Toggle(); //Toggle LED |
thomasmorris | 7:dfe19413fdc2 | 119 | |
thomasmorris | 7:dfe19413fdc2 | 120 | mode = mode +1;//Cycles through modes |
thomasmorris | 7:dfe19413fdc2 | 121 | if(mode >1) |
thomasmorris | 7:dfe19413fdc2 | 122 | { |
thomasmorris | 7:dfe19413fdc2 | 123 | mode = 0; |
thomasmorris | 7:dfe19413fdc2 | 124 | } |
thomasmorris | 7:dfe19413fdc2 | 125 | |
thomasmorris | 7:dfe19413fdc2 | 126 | sw1TimeOut.attach(&SW1TimeOutHandler, 0.2); //Start timeout counter |
thomasmorris | 7:dfe19413fdc2 | 127 | } |
thomasmorris | 7:dfe19413fdc2 | 128 | |
thomasmorris | 7:dfe19413fdc2 | 129 | void ModeSelection() |
thomasmorris | 7:dfe19413fdc2 | 130 | { |
thomasmorris | 7:dfe19413fdc2 | 131 | while(1){ |
chills | 13:db857b3744c6 | 132 | |
thomasmorris | 8:0e4481b64353 | 133 | Thread::wait(1000); |
chills | 13:db857b3744c6 | 134 | |
chills | 14:45630ba388e1 | 135 | osEvent evt_lcd = mail_box_lcd.get(); //Get the latest entry from "mail_box" |
chills | 13:db857b3744c6 | 136 | |
chills | 13:db857b3744c6 | 137 | if (evt_lcd.status == osEventMail) |
thomasmorris | 7:dfe19413fdc2 | 138 | { |
chills | 13:db857b3744c6 | 139 | DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p; |
chills | 13:db857b3744c6 | 140 | DATA msg_lcd; |
chills | 13:db857b3744c6 | 141 | |
chills | 13:db857b3744c6 | 142 | msg_lcd.set_time(Rec_Data_LCD->get_time()); |
chills | 13:db857b3744c6 | 143 | msg_lcd.set_temperature(Rec_Data_LCD->get_temperature()); |
chills | 13:db857b3744c6 | 144 | msg_lcd.set_pressure(Rec_Data_LCD->get_pressure()); |
chills | 13:db857b3744c6 | 145 | msg_lcd.set_light(Rec_Data_LCD->get_light()); |
chills | 13:db857b3744c6 | 146 | |
chills | 13:db857b3744c6 | 147 | |
chills | 13:db857b3744c6 | 148 | if(mode == 0)//Print values to the LCD |
chills | 13:db857b3744c6 | 149 | { |
chills | 13:db857b3744c6 | 150 | //Write new data to LCD (not fast!) |
chills | 13:db857b3744c6 | 151 | lcd.cls(); |
chills | 13:db857b3744c6 | 152 | lcd.printf("Temp Pres li\n"); |
chills | 13:db857b3744c6 | 153 | lcd.printf("%1.1f ", msg_lcd.get_temperature()); //Print Temperature to LCD |
chills | 13:db857b3744c6 | 154 | lcd.printf("%1.1f ", msg_lcd.get_pressure()); //Print Pressure to LCD |
chills | 13:db857b3744c6 | 155 | lcd.printf("%1.1f\n", msg_lcd.get_light()); //Print Light to LCD |
chills | 13:db857b3744c6 | 156 | } |
chills | 13:db857b3744c6 | 157 | else if(mode == 1)//Print the Time to the LCD |
chills | 13:db857b3744c6 | 158 | { |
chills | 13:db857b3744c6 | 159 | lcd.cls(); //Write new data to LCD (not fast!) |
chills | 13:db857b3744c6 | 160 | lcd.printf("Current Time:%s", buffer); |
chills | 13:db857b3744c6 | 161 | } |
chills | 13:db857b3744c6 | 162 | else |
chills | 13:db857b3744c6 | 163 | { |
chills | 13:db857b3744c6 | 164 | mode = 0; |
chills | 13:db857b3744c6 | 165 | } |
thomasmorris | 7:dfe19413fdc2 | 166 | } |
thomasmorris | 7:dfe19413fdc2 | 167 | } |
thomasmorris | 7:dfe19413fdc2 | 168 | } |
thomasmorris | 7:dfe19413fdc2 | 169 | |
thomasmorris | 7:dfe19413fdc2 | 170 | void PrintTime() |
thomasmorris | 7:dfe19413fdc2 | 171 | { |
thomasmorris | 7:dfe19413fdc2 | 172 | Thread::signal_wait(Print_Time_to_LCD); |
thomasmorris | 7:dfe19413fdc2 | 173 | while(1) |
thomasmorris | 7:dfe19413fdc2 | 174 | { |
thomasmorris | 7:dfe19413fdc2 | 175 | //lcd.printf("Current Time: \n %s", buffer); |
thomasmorris | 7:dfe19413fdc2 | 176 | Thread::wait(1000);//Waits the thread for 1 second |
thomasmorris | 7:dfe19413fdc2 | 177 | } |
thomasmorris | 7:dfe19413fdc2 | 178 | } |
thomasmorris | 7:dfe19413fdc2 | 179 | void Time() |
thomasmorris | 7:dfe19413fdc2 | 180 | { |
thomasmorris | 7:dfe19413fdc2 | 181 | while (true) |
thomasmorris | 7:dfe19413fdc2 | 182 | { |
thomasmorris | 7:dfe19413fdc2 | 183 | time_t seconds = time(NULL); |
thomasmorris | 7:dfe19413fdc2 | 184 | //pc.printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
thomasmorris | 7:dfe19413fdc2 | 185 | //pc.printf("Time as a basic string = %s", ctime(&seconds)); |
thomasmorris | 7:dfe19413fdc2 | 186 | strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
thomasmorris | 7:dfe19413fdc2 | 187 | pc.printf("Current Time:%s", buffer); |
thomasmorris | 7:dfe19413fdc2 | 188 | |
thomasmorris | 7:dfe19413fdc2 | 189 | Thread::wait(1000); |
thomasmorris | 7:dfe19413fdc2 | 190 | } |
thomasmorris | 7:dfe19413fdc2 | 191 | } |
thomasmorris | 7:dfe19413fdc2 | 192 | |
thomasmorris | 5:2594b953f111 | 193 | |
thomasmorris | 5:2594b953f111 | 194 | void Serial_Comms()//Thread for Serial Communications |
thomasmorris | 5:2594b953f111 | 195 | { |
thomasmorris | 5:2594b953f111 | 196 | pc.printf("Hello World \n"); |
thomasmorris | 5:2594b953f111 | 197 | while(1) |
thomasmorris | 5:2594b953f111 | 198 | { |
chills | 14:45630ba388e1 | 199 | osEvent evt_serial = mail_box_serial.get(); //Get the latest entry from "mail_box" |
chills | 10:46946784326d | 200 | |
chills | 13:db857b3744c6 | 201 | if (evt_serial.status == osEventMail) |
thomasmorris | 12:536eca338ae8 | 202 | { |
chills | 13:db857b3744c6 | 203 | DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; |
chills | 13:db857b3744c6 | 204 | DATA msg_serial; |
chills | 11:e7b5ed6cd3cf | 205 | |
chills | 13:db857b3744c6 | 206 | msg_serial.set_time(Rec_Data_Serial->get_time()); |
chills | 13:db857b3744c6 | 207 | msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); |
chills | 13:db857b3744c6 | 208 | msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); |
chills | 13:db857b3744c6 | 209 | msg_serial.set_light(Rec_Data_Serial->get_light()); |
chills | 11:e7b5ed6cd3cf | 210 | |
chills | 13:db857b3744c6 | 211 | pc.printf("Time = %d\t", msg_serial.get_time()); //Print Time |
chills | 13:db857b3744c6 | 212 | pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature |
chills | 13:db857b3744c6 | 213 | pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure |
chills | 13:db857b3744c6 | 214 | pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light |
chills | 10:46946784326d | 215 | } |
thomasmorris | 7:dfe19413fdc2 | 216 | Green_led.Toggle(); |
thomasmorris | 5:2594b953f111 | 217 | Thread::wait(1000); |
thomasmorris | 5:2594b953f111 | 218 | } |
thomasmorris | 5:2594b953f111 | 219 | } |
thomasmorris | 5:2594b953f111 | 220 | |
chills | 10:46946784326d | 221 | void Sample_signal_set() //Sets the Signal for when to sample the sensors |
thomasmorris | 5:2594b953f111 | 222 | { |
chills | 10:46946784326d | 223 | t1.signal_set(SamplingTime); //Set the sampling thread signal high |
thomasmorris | 5:2594b953f111 | 224 | } |
noutram | 3:a88838ff33e7 | 225 | |
chills | 10:46946784326d | 226 | |
thomasmorris | 5:2594b953f111 | 227 | void Sample()//Samples the hardware and prints the result to the LCD |
thomasmorris | 5:2594b953f111 | 228 | { |
thomasmorris | 5:2594b953f111 | 229 | while(1) |
thomasmorris | 5:2594b953f111 | 230 | { |
chills | 10:46946784326d | 231 | Thread::signal_wait(SamplingTime); //Set the time between samples |
chills | 10:46946784326d | 232 | |
chills | 10:46946784326d | 233 | temp = sensor.getTemperature(); //Read Temperature |
chills | 10:46946784326d | 234 | pressure = sensor.getPressure(); //Read Pressure |
chills | 10:46946784326d | 235 | lux = adcIn.read(); //Read Light |
chills | 10:46946784326d | 236 | buffer_time = buffer; //Read Time |
thomasmorris | 7:dfe19413fdc2 | 237 | |
chills | 14:45630ba388e1 | 238 | DATA *Send_Data_network = mail_box_network.alloc(); //Allocate a block from the memory pool, Type Data |
chills | 14:45630ba388e1 | 239 | DATA *Send_Data_sd = mail_box_sd.alloc(); //Allocate a block from the memory pool, Type Data |
chills | 14:45630ba388e1 | 240 | DATA *Send_Data_lcd = mail_box_lcd.alloc(); //Allocate a block from the memory pool, Type Data |
chills | 14:45630ba388e1 | 241 | DATA *Send_Data_serial = mail_box_serial.alloc(); //Allocate a block from the memory pool, Type Data |
chills | 14:45630ba388e1 | 242 | |
chills | 14:45630ba388e1 | 243 | if (Send_Data_network == NULL){return;} |
chills | 14:45630ba388e1 | 244 | if (Send_Data_sd == NULL){return;} |
chills | 14:45630ba388e1 | 245 | if (Send_Data_lcd == NULL){return;} |
chills | 14:45630ba388e1 | 246 | if (Send_Data_serial == NULL){return;} |
chills | 14:45630ba388e1 | 247 | |
chills | 14:45630ba388e1 | 248 | Send_Data_network->set_time(buffer_time); Send_Data_sd->set_time(buffer_time); Send_Data_lcd->set_time(buffer_time); Send_Data_serial->set_time(buffer_time); //Pass in Time |
chills | 14:45630ba388e1 | 249 | Send_Data_network->set_temperature(temp); Send_Data_sd->set_temperature(temp); Send_Data_lcd->set_temperature(temp); Send_Data_serial->set_temperature(temp); //Pass in Temp |
chills | 14:45630ba388e1 | 250 | Send_Data_network->set_pressure(pressure); Send_Data_sd->set_pressure(pressure); Send_Data_lcd->set_pressure(pressure); Send_Data_serial->set_pressure(pressure); //Pass in Pres |
chills | 14:45630ba388e1 | 251 | Send_Data_network->set_light(lux); Send_Data_sd->set_light(lux); Send_Data_lcd->set_light(lux); Send_Data_serial->set_light(lux); //Pass in Light //Pass in Light |
thomasmorris | 5:2594b953f111 | 252 | |
chills | 14:45630ba388e1 | 253 | osStatus stat_network = mail_box_network.put(Send_Data_network); //Puts "Send_Data" into the mailbox |
chills | 14:45630ba388e1 | 254 | if (stat_network == osErrorResource){ //If mailbox overfills |
chills | 14:45630ba388e1 | 255 | mail_box_network.free(Send_Data_network); //Free the mail box |
chills | 14:45630ba388e1 | 256 | return; |
chills | 14:45630ba388e1 | 257 | } |
chills | 14:45630ba388e1 | 258 | osStatus stat_sd = mail_box_sd.put(Send_Data_sd); //Puts "Send_Data" into the mailbox |
chills | 14:45630ba388e1 | 259 | if (stat_sd == osErrorResource){ //If mailbox overfills |
chills | 14:45630ba388e1 | 260 | mail_box_sd.free(Send_Data_sd); //Free the mail box |
chills | 14:45630ba388e1 | 261 | return; |
chills | 14:45630ba388e1 | 262 | } |
chills | 14:45630ba388e1 | 263 | osStatus stat_lcd = mail_box_lcd.put(Send_Data_lcd); //Puts "Send_Data" into the mailbox |
chills | 14:45630ba388e1 | 264 | if (stat_lcd == osErrorResource){ //If mailbox overfills |
chills | 14:45630ba388e1 | 265 | mail_box_lcd.free(Send_Data_lcd); //Free the mail box |
chills | 14:45630ba388e1 | 266 | return; |
chills | 14:45630ba388e1 | 267 | } |
chills | 14:45630ba388e1 | 268 | osStatus stat_serial = mail_box_serial.put(Send_Data_serial); //Puts "Send_Data" into the mailbox |
chills | 14:45630ba388e1 | 269 | if (stat_serial == osErrorResource){ //If mailbox overfills |
chills | 14:45630ba388e1 | 270 | mail_box_serial.free(Send_Data_serial); //Free the mail box |
chills | 10:46946784326d | 271 | return; |
chills | 10:46946784326d | 272 | } |
chills | 10:46946784326d | 273 | |
chills | 10:46946784326d | 274 | |
thomasmorris | 5:2594b953f111 | 275 | Red_led.Toggle(); |
thomasmorris | 5:2594b953f111 | 276 | t1.signal_set(NotSamplingTime); |
thomasmorris | 5:2594b953f111 | 277 | } |
thomasmorris | 5:2594b953f111 | 278 | } |
thomasmorris | 5:2594b953f111 | 279 | |
thomasmorris | 5:2594b953f111 | 280 | int main() |
thomasmorris | 5:2594b953f111 | 281 | { |
noutram | 1:e1cf7663f5ff | 282 | //Greeting |
noutram | 3:a88838ff33e7 | 283 | printf("Testing\n\n"); |
chills | 10:46946784326d | 284 | set_time(1512940530); //Set RTC time to December 10 2017 |
chills | 10:46946784326d | 285 | pc.baud(9600); //Sets the Serial Comms Baud Rate |
thomasmorris | 5:2594b953f111 | 286 | |
chills | 10:46946784326d | 287 | post(); //Power on Self Test |
noutram | 1:e1cf7663f5ff | 288 | |
noutram | 3:a88838ff33e7 | 289 | //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 290 | if ( sd.init() != 0) { |
noutram | 1:e1cf7663f5ff | 291 | printf("Init failed \n"); |
noutram | 3:a88838ff33e7 | 292 | lcd.cls(); |
noutram | 3:a88838ff33e7 | 293 | lcd.printf("CANNOT INIT SD"); |
noutram | 1:e1cf7663f5ff | 294 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 295 | } |
noutram | 1:e1cf7663f5ff | 296 | |
noutram | 1:e1cf7663f5ff | 297 | //Create a filing system for SD Card |
noutram | 1:e1cf7663f5ff | 298 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 299 | |
noutram | 1:e1cf7663f5ff | 300 | //Open to WRITE |
noutram | 1:e1cf7663f5ff | 301 | FILE* fp = fopen("/sd/test.csv","a"); |
noutram | 1:e1cf7663f5ff | 302 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 303 | error("Could not open file for write\n"); |
noutram | 3:a88838ff33e7 | 304 | lcd.cls(); |
noutram | 3:a88838ff33e7 | 305 | lcd.printf("CANNOT OPEN FILE\n\n"); |
noutram | 1:e1cf7663f5ff | 306 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 307 | } |
noutram | 3:a88838ff33e7 | 308 | |
noutram | 3:a88838ff33e7 | 309 | //Last message before sampling begins |
noutram | 3:a88838ff33e7 | 310 | lcd.cls(); |
noutram | 3:a88838ff33e7 | 311 | lcd.printf("READY\n\n"); |
thomasmorris | 5:2594b953f111 | 312 | |
thomasmorris | 5:2594b953f111 | 313 | //Run interrupt |
thomasmorris | 5:2594b953f111 | 314 | Sample_timer.attach(&Sample_signal_set,TimerInterval); |
thomasmorris | 7:dfe19413fdc2 | 315 | SW1.fall(&SW1FallingEdge); |
thomasmorris | 5:2594b953f111 | 316 | //Run Threads |
thomasmorris | 5:2594b953f111 | 317 | |
thomasmorris | 5:2594b953f111 | 318 | t1.start(Sample); |
thomasmorris | 5:2594b953f111 | 319 | t2.start(Serial_Comms); |
thomasmorris | 7:dfe19413fdc2 | 320 | t3.start(Time); |
thomasmorris | 7:dfe19413fdc2 | 321 | t4.start(PrintTime); |
thomasmorris | 7:dfe19413fdc2 | 322 | t5.start(ModeSelection); |
thomasmorris | 8:0e4481b64353 | 323 | t6.start(Network); |
thomasmorris | 5:2594b953f111 | 324 | //Main thread ID |
thomasmorris | 5:2594b953f111 | 325 | |
thomasmorris | 5:2594b953f111 | 326 | idMain = osThreadGetId(); //CMSIS RTOS call |
thomasmorris | 5:2594b953f111 | 327 | |
thomasmorris | 5:2594b953f111 | 328 | //Thread ID |
thomasmorris | 5:2594b953f111 | 329 | id1 = t1.gettid(); |
thomasmorris | 5:2594b953f111 | 330 | id2 = t2.gettid(); |
thomasmorris | 7:dfe19413fdc2 | 331 | id3 = t3.gettid(); |
thomasmorris | 8:0e4481b64353 | 332 | id4 = t4.gettid(); |
thomasmorris | 8:0e4481b64353 | 333 | //id5 = t5.gettid(); |
thomasmorris | 5:2594b953f111 | 334 | |
thomasmorris | 5:2594b953f111 | 335 | //Toggle Green LED after a button has been pressed |
noutram | 1:e1cf7663f5ff | 336 | //Press either switch to unmount |
thomasmorris | 7:dfe19413fdc2 | 337 | DigitalIn onBoardSwitch(USER_BUTTON); |
thomasmorris | 7:dfe19413fdc2 | 338 | while (onBoardSwitch == 0){ |
thomasmorris | 7:dfe19413fdc2 | 339 | |
noutram | 1:e1cf7663f5ff | 340 | } |
noutram | 1:e1cf7663f5ff | 341 | |
noutram | 1:e1cf7663f5ff | 342 | //Close File |
noutram | 1:e1cf7663f5ff | 343 | fclose(fp); |
noutram | 1:e1cf7663f5ff | 344 | |
noutram | 1:e1cf7663f5ff | 345 | //Close down |
noutram | 1:e1cf7663f5ff | 346 | sd.deinit(); |
noutram | 1:e1cf7663f5ff | 347 | printf("Unmounted...\n"); |
noutram | 1:e1cf7663f5ff | 348 | lcd.cls(); |
noutram | 1:e1cf7663f5ff | 349 | lcd.printf("Unmounted...\n\n"); |
noutram | 1:e1cf7663f5ff | 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; |
noutram | 1:e1cf7663f5ff | 355 | wait(0.1); |
noutram | 0:36e89e3ed7c4 | 356 | } |
noutram | 0:36e89e3ed7c4 | 357 | } |
noutram | 0:36e89e3ed7c4 | 358 | |
noutram | 1:e1cf7663f5ff | 359 | |
noutram | 1:e1cf7663f5ff | 360 |