Plymouth ELEC351 Group T
/
ELEC351_Group_T
FINAL PROJECT isn't it
Fork of ELEC351 by
Diff: main.cpp
- Revision:
- 13:db857b3744c6
- Parent:
- 12:536eca338ae8
- Child:
- 14:45630ba388e1
- Child:
- 15:c1592fc1a501
--- a/main.cpp Wed Dec 20 15:18:00 2017 +0000 +++ b/main.cpp Wed Dec 20 15:37:12 2017 +0000 @@ -71,11 +71,24 @@ Mail<DATA, 120> mail_box; //Mail Queue, Type DATA, Capacity 120, name mail_box -void Network() +void Network() //Interrupt service routine for handling the timeout { - NETWORK_Print();//Runs the network - //Send DATA to the network -}//Interrupt service routine for handling the timeout + osEvent evt_network = mail_box.get(); //Get the latest entry from "mail_box" + + if (evt_network.status == osEventMail) + { + DATA *Rec_Data_Network = (DATA*)evt_network.value.p; + DATA msg_network; + + msg_network.set_time(Rec_Data_Network->get_time()); + msg_network.set_temperature(Rec_Data_Network->get_temperature()); + msg_network.set_pressure(Rec_Data_Network->get_pressure()); + msg_network.set_light(Rec_Data_Network->get_light()); + + //NETWORK_Print(); //Runs the network + } +} + void SW1TimeOutHandler() { sw1TimeOut.detach(); //Stop the timeout counter firing @@ -83,7 +96,18 @@ } void SDWrite()//End of skype chat { - + osEvent evt_sd = mail_box.get(); //Get the latest entry from "mail_box" + + if (evt_sd.status == osEventMail) + { + DATA *Rec_Data_SD = (DATA*)evt_sd.value.p; + DATA msg_sd; + + msg_sd.set_time(Rec_Data_SD->get_time()); + msg_sd.set_temperature(Rec_Data_SD->get_temperature()); + msg_sd.set_pressure(Rec_Data_SD->get_pressure()); + msg_sd.set_light(Rec_Data_SD->get_light()); + } } //Interrupt service routive for SW1 falling edge (release) void SW1FallingEdge() { @@ -102,30 +126,40 @@ void ModeSelection() { while(1){ + Thread::wait(1000); - //Detech the not required interrupt then rettach it when finshed - if(mode == 0)//Print values to the LCD + + osEvent evt_lcd = mail_box.get(); //Get the latest entry from "mail_box" + + if (evt_lcd.status == osEventMail) { - //Write new data to LCD (not fast!) - lcd.cls(); - lcd.printf("Temp Pres li\n"); - lcd.printf("%1.1f ",temp); - lcd.printf("%1.1f ",pressure); - lcd.printf("%1.1f\n",lux); - } - else if(mode == 1)//Print the Time to the LCD - { - //Write new data to LCD (not fast!) - lcd.cls(); - - lcd.printf("Current Time:%s", buffer); - - //Write to SD (potentially slow) - //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure); - } - else - { - mode = 0; + DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p; + DATA msg_lcd; + + msg_lcd.set_time(Rec_Data_LCD->get_time()); + msg_lcd.set_temperature(Rec_Data_LCD->get_temperature()); + msg_lcd.set_pressure(Rec_Data_LCD->get_pressure()); + msg_lcd.set_light(Rec_Data_LCD->get_light()); + + + if(mode == 0)//Print values to the LCD + { + //Write new data to LCD (not fast!) + lcd.cls(); + lcd.printf("Temp Pres li\n"); + lcd.printf("%1.1f ", msg_lcd.get_temperature()); //Print Temperature to LCD + lcd.printf("%1.1f ", msg_lcd.get_pressure()); //Print Pressure to LCD + lcd.printf("%1.1f\n", msg_lcd.get_light()); //Print Light to LCD + } + else if(mode == 1)//Print the Time to the LCD + { + lcd.cls(); //Write new data to LCD (not fast!) + lcd.printf("Current Time:%s", buffer); + } + else + { + mode = 0; + } } } } @@ -159,25 +193,23 @@ pc.printf("Hello World \n"); while(1) { - osEvent evt = mail_box.get(); //Get the latest entry from "mail_box" + osEvent evt_serial = mail_box.get(); //Get the latest entry from "mail_box" - if (evt.status == osEventMail) + if (evt_serial.status == osEventMail) { - DATA *Rec_Data = (DATA*)evt.value.p; - DATA msg; + DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; + DATA msg_serial; - msg.set_time(Rec_Data->get_time()); - msg.set_temperature(Rec_Data->get_temperature()); - msg.set_pressure(Rec_Data->get_pressure()); - msg.set_light(Rec_Data->get_light()); + msg_serial.set_time(Rec_Data_Serial->get_time()); + msg_serial.set_temperature(Rec_Data_Serial->get_temperature()); + msg_serial.set_pressure(Rec_Data_Serial->get_pressure()); + msg_serial.set_light(Rec_Data_Serial->get_light()); - pc.printf("Time = %d\t", msg.get_time()); //Print Time - pc.printf("Temperature = %f", msg.get_temperature()); //Print Temperature - pc.printf("Pressure = %f", msg.get_pressure()); //Print Pressure - pc.printf("Light = %f", msg.get_light()); //Print Light + pc.printf("Time = %d\t", msg_serial.get_time()); //Print Time + pc.printf("Temperature = %f\t", msg_serial.get_temperature()); //Print Temperature + pc.printf("Pressure = %f\t", msg_serial.get_pressure()); //Print Pressure + pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light } - - pc.printf("Test\n");//Use this Line to output a string to Putty Green_led.Toggle(); Thread::wait(1000); }