![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
FINAL PROJECT isn't it
Fork of ELEC351 by
Diff: main.cpp
- Revision:
- 30:4cde05cc7c4f
- Parent:
- 29:64b1f95a807c
- Child:
- 31:4a88bf97b53e
--- a/main.cpp Wed Jan 03 22:00:07 2018 +0000 +++ b/main.cpp Sat Jan 06 17:43:17 2018 +0000 @@ -1,7 +1,7 @@ /* ELEC 351 Group T Team Members : Christopher Hills, Thomas Morris -Current Verision 12 +Current Verision 13 Overiew: Working Tasks 1,2,4,5,6,7,8,10,11,12,13 Last Revision: Added Mail Box to serial @@ -29,11 +29,15 @@ networktest(); } } - +void SW2TimeOutHandler() +{ + sw2TimeOut.detach();//Stop the timeout counter firing + SW2.rise(&SW2RisingEdge);//Now wait for a rising edge +} void SW1TimeOutHandler() { sw1TimeOut.detach(); //Stop the timeout counter firing - SW1.fall(&SW1FallingEdge); //Now wait for a falling edge + SW1.rise(&SW1RisingEdge); //Now wait for a rising edge } void SDWrite() { @@ -50,58 +54,126 @@ mail_box.free(Rec_Data_SD); //Free space in the mailbox (delete earliest sample taken) } } -//Interrupt service routive for SW1 falling edge (release) -void SW1FallingEdge() +//Interrupt service routive for SW1 rising edge (release) +void SW1RisingEdge() { - SW1.fall(NULL); //Disable this interrupt - Yellow_led.Toggle(); //Toggle LED - - mode = mode +1;//Cycles through modes - if(mode >1) { - mode = 0; + sw1TimeOut.attach(&SW1TimeOutHandler, 0.35); //Start timeout counter + wait(0.1); + if(SW2 == 1 & SW1 == 1) + { + wait(0.2); //Wait 200ms + if(SW1 == 0 & SW2 == 0) + { + if(mode < 7) + { + mode = mode + 1; + } + else if (mode == 7) + { + mode = 0; + } + } } +} - sw1TimeOut.attach(&SW1TimeOutHandler, 0.2); //Start timeout counter +void SW2RisingEdge() +{ + + while (SW1 == 0) { } + + //Insert a small delay to reduce switch bounce effects + wait(0.05); + + // Wait for SW1 to be released + while (SW1 == 1) { } + + mode = mode + 1; } -void ModeSelection() -{ - while(1) + +void LCD_Output() +{ + while(1) { + Thread::wait(10);//Dont Delete osEvent evt_lcd = mail_box.get(); //Get the latest entry from "mail_box" - - if (evt_lcd.status == osEventMail) { + DATA msg_lcd; + if (evt_lcd.status == osEventMail) + { DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p; //Create pointer to mailbox - DATA msg_lcd; //Create temporary instance of DATA class + //Create temporary instance of DATA class msg_lcd.set_time(Rec_Data_LCD->get_time()); //Copy time from mailbox to temporary instance msg_lcd.set_temperature(Rec_Data_LCD->get_temperature()); //Copy temperature from mailbox to temporary instance msg_lcd.set_pressure(Rec_Data_LCD->get_pressure()); //Copy pressure from mailbox to temporary instance msg_lcd.set_light(Rec_Data_LCD->get_light()); //Copy light from mailbox to temporary instance mail_box.free(Rec_Data_LCD); //Free space in the mailbox (delete earliest sample taken) - - if(mode == 0) { //Print values to the LCD - //Write new data to LCD (not fast!) - - 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 - - LCD.DDRAM_Address(0x00); - LCD.Write_String("Temp Pres li"); - LCD.DDRAM_Address(0x40); - LCD.Write_String(LCD_buffer); + } + if(mode == 0)//Default mode + { + cout << "In mode 0" << endl; + SW1.rise(&SW1RisingEdge);//Now wait for a rising edg + //SW2.rise(&SW2RisingEdge);//Now wait for a rising edg + Thread::wait(3000); + + 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 + LCD.DDRAM_Address(0x00); + LCD.Write_String("Temp Pres li"); + LCD.DDRAM_Address(0x40); + LCD.Write_String(LCD_buffer); - } - else if(mode == 1) //Print the Time to the LCD - { - time_t msel_time = msg_lcd.get_time(); //Declare local variable for time - strftime(scom_time_buffer, 32, "%I:%M %p", localtime(&msel_time)); //Format time as a string - LCD.Display_Clear(); - LCD_sprintf = sprintf (LCD_buffer, "%s",scom_time_buffer); - LCD.DDRAM_Address(0x00); - LCD.Write_String("Current Time:"); - LCD.DDRAM_Address(0x40); - LCD.Write_String(LCD_buffer); + Thread::wait(3000); + + time_t msel_time = msg_lcd.get_time(); //Declare local variable for time + strftime(scom_time_buffer, 32, "%I:%M %p", localtime(&msel_time)); //Format time as a string + LCD.Display_Clear(); + LCD_sprintf = sprintf (LCD_buffer, "%s",scom_time_buffer); + LCD.DDRAM_Address(0x00); + LCD.Write_String("Current Time:"); + LCD.DDRAM_Address(0x40); + LCD.Write_String(LCD_buffer); + } + else if(mode == 1)//Choose either date setting or time setting + { + SW1.rise(NULL); + SW2.rise(NULL); + Thread::wait(10); + cout << "In Mode 1" << endl; + LCD.Display_Clear(); + LCD.DDRAM_Address(0x00); + LCD.Write_String("Date Time"); + LCD.DDRAM_Address(0x40); + LCD.Write_String("< >"); + + - }else{mode = 0;}//Set a default mode + } + else if(mode == 2)//Set the Year + { + cout << "In Mode 2" << endl; + } + else if(mode == 3)//Set the Month + { + cout << "In Mode 3" << endl; + } + else if(mode == 4)//Set the Day + { + cout << "In Mode 4" << endl; + } + else if(mode == 5)//Set the Hour + { + cout << "In Mode 5" << endl; + } + else if(mode == 6)//Set the Minute + { + cout << "In Mode 6" << endl; + } + else if(mode == 7)//Set the Seconds + { + cout << "In Mode 7" << endl; + } + else + { + mode == 0; } } } @@ -117,6 +189,7 @@ if (Serial_Input == "Test") { cout << "Test Confirmed" << endl; + cout << "This is the time " << get_current_time() << endl; } else if(Serial_Input == "READALL") { @@ -192,6 +265,10 @@ { Console_Output_Timer.detach(); //Stops Sampling } + else if(Serial_Input == "Blank Blank") + { + cout << "Blank Blank complete" << endl; + } else { cout << "Please enter an acceptable command" << endl; @@ -233,7 +310,8 @@ void Sample()//Samples the hardware and prints the result to the LCD { - while(1) { + while(1) + { Thread::signal_wait(SamplingTime); //Set the time between samples temp = sensor.getTemperature(); //Read Temperature @@ -253,11 +331,6 @@ Send_Data->set_light(lux); //Pass in Light osStatus stat = mail_box.put(Send_Data); //Puts "Send_Data" into the mailbox - - //if(stat == osErrorNoMemory) - // { - // mail_box.free(Send_Data); - // } if (stat == osErrorResource) { //If mailbox overfills mail_box.free(Send_Data); //Free the mail box @@ -273,6 +346,7 @@ pc.printf("\n\r"); set_time(1512940530); //Set RTC time to December 10 2017 + pc.baud(9600); //Sets the Serial Comms Baud Rate LCD.Initialise(); @@ -300,17 +374,16 @@ } //Last message before sampling begins LCD.Display_Clear(); - LCD.Write_String("READY\n\n"); + LCD.Write_String("READY"); Sample_Rate = TimerInterval; //Run interrupt - SW1.fall(&SW1FallingEdge); Sampling_Timer.attach(&Sampling_ISR,Sample_Rate); t1.start(Sample); t2.start(Serial_Comms); - t3.start(ModeSelection); + t3.start(LCD_Output); //t4.start(Network); t5.start(Serial_Commands);