![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 26:78f5e454e59f
- Parent:
- 25:36699ed589ab
- Child:
- 27:807dd5660c4b
--- a/main.cpp Mon Jan 01 20:14:19 2018 +0000 +++ b/main.cpp Wed Jan 03 15:38:40 2018 +0000 @@ -130,63 +130,78 @@ } else if(Serial_Input == "READALL") { - cout << "Read All Confirmed" << endl; - t2.start(Serial_Comms); + cout << "Read All Confirmed " << Sample_Rate << endl; + Console_Output_Timer.attach(&Console_Output_ISR,Sample_Rate); } - else if(Serial_Input == "DELETE.ALL") - { - + else if(Serial_Input == "DELETEALL") + { + Sampling_Timer.detach(); + Console_Output_Timer.detach(); + for (int x = 0; x < mailsize; x++){ + DATA *Delete_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data + mail_box.free(Delete_Data); //Puts "Send_Data" into the mailbox + } + Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); + cout << "Sampling Restarted" << endl; } else if(Serial_Input == "READ.<n>") { } - else if(Serial_Input == "DELETE.<n>") + else if(Serial_Input == "DELETE") { - + Sampling_Timer.detach(); + Console_Output_Timer.detach(); + cout << "Number of samples to delete:" << endl; + int Loops; cin >> Loops; + for (int x = 0; x < Loops; x++){ + DATA *Delete_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data + mail_box.free(Delete_Data); //Puts "Send_Data" into the mailbox + } + Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); + cout << "Sampling Restarted" << endl; } else if(Serial_Input == "SETDATE") - { + { set_time(SETDATE()); - } + } else if(Serial_Input == "SETT") { - - if(SETT() >= 1) - { - Sample_Rate = SETT(); - } - else - { - Sample_Rate = TimerInterval; - } - Sample_timer.detach(); - Sample_timer.attach(&Sample_signal_set,Sample_Rate); + float Temp_Sample_Rate = SETT(); + + if(Temp_Sample_Rate >= 1){Sample_Rate = Temp_Sample_Rate;} + + Sampling_Timer.detach(); + Console_Output_Timer.detach(); + Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); } else if(Serial_Input == "STATE.<x>") { } else if(Serial_Input == "LOGGING.<x>") - { + { } else if(Serial_Input == "HELP")// Use this to display all of the availble commands { HELP(); } + else if(Serial_Input == "STOP") + { + Console_Output_Timer.detach(); + } else { - cout << "Please enter a acceptable command" << endl; + cout << "Please enter an acceptable command" << endl; } } } void Serial_Comms()//Thread for Serial Communications { - cout << "In Serial Comms" << endl; while(1) { Thread::signal_wait(1); - osEvent evt_serial = 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_serial.status == osEventMail) { DATA *Rec_Data_Serial = (DATA*)evt_serial.value.p; //Create pointer to mailbox @@ -207,15 +222,13 @@ pc.printf("Light = %f\n\r", msg_serial.get_light()); //Print Light } Green_led.Toggle(); - //Thread::wait(1000); } } -void Sample_signal_set() //Sets the Signal for when to sample the sensors -{ - t1.signal_set(SamplingTime); //Set the sampling thread signal high - t2.signal_set(1); -} +void Console_Output_ISR() {t2.signal_set(1);} +void Sampling_ISR() {t1.signal_set(SamplingTime);} + + void Sample()//Samples the hardware and prints the result to the LCD { while(1) { @@ -251,9 +264,6 @@ } int main() { - - - //Greeting pc.printf("Test Start"); pc.printf("\n\r"); @@ -264,7 +274,7 @@ LCD.Initialise(); LCD.DDRAM_Address(0x40); - + /* post(); //Power on Self Test //Initialise the SD card (this needs to move) @@ -286,6 +296,7 @@ lcd.printf("CANNOT OPEN FILE\n\n");//Change me errorCode(FATAL); } + */ //Last message before sampling begins lcd.cls();//change me @@ -294,10 +305,11 @@ Sample_Rate = TimerInterval; //Run interrupt - Sample_timer.attach(&Sample_signal_set,Sample_Rate); SW1.fall(&SW1FallingEdge); + Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); t1.start(Sample); + t2.start(Serial_Comms); t3.start(ModeSelection); //t4.start(Network); t5.start(Serial_Commands); @@ -314,9 +326,6 @@ id4 = t4.gettid(); id5 = t5.gettid(); - - //Toggle Green LED after a button has been pressed - //Press either switch to unmount DigitalIn onBoardSwitch(USER_BUTTON); while (onBoardSwitch == 0) {