![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proj 324 Final
Fork of ELEC351_Group_T by
Diff: main.cpp
- Revision:
- 33:3b5096f0126a
- Parent:
- 32:8f2795716e97
- Child:
- 34:c0b8705f183d
--- a/main.cpp Sat Jan 06 23:10:13 2018 +0000 +++ b/main.cpp Sun Jan 07 00:45:11 2018 +0000 @@ -12,9 +12,11 @@ #include "SETUP.hpp" -void Network()//Interrupt service routine for handling the timeout +Mutex Time_Lock_Main; + +void Network() //Interrupt service routine for handling the timeout { - osEvent evt_network = mail_box.get(); //Get the latest entry from "mail_box" + 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; //Create pointer to mailbox @@ -31,7 +33,11 @@ } void LCD_Write_Year() { - int Years = LCD_Time_Get("Years"); + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); + int Years = 1900 + Time_Pointer->tm_year; + Time_Lock_Main.unlock(); stringstream ss; ss << Years; string Year_String = ss.str(); @@ -43,7 +49,11 @@ void LCD_Write_Month() { - int Months = LCD_Time_Get("Months"); + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); + int Months = 1 + Time_Pointer->tm_mon; + Time_Lock_Main.unlock(); stringstream ss; ss << Months; string Month_String = ss.str(); @@ -54,7 +64,11 @@ } void LCD_Write_Day() { - int Days = LCD_Time_Get("Days"); + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); + int Days = Time_Pointer->tm_mday; + Time_Lock_Main.unlock(); stringstream ss; ss << Days; string Day_String = ss.str(); @@ -67,7 +81,11 @@ void LCD_Write_Hour() { - int Hours = LCD_Time_Get("Hours"); + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); + int Hours = Time_Pointer->tm_hour; + Time_Lock_Main.unlock(); stringstream ss; ss << Hours; string Hour_String = ss.str(); @@ -78,7 +96,11 @@ } void LCD_Write_Minute() { - int Minutes = LCD_Time_Get("Minutes"); + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); + int Minutes = Time_Pointer->tm_min; + Time_Lock_Main.unlock(); stringstream ss; ss << Minutes; string Minute_String = ss.str(); @@ -89,7 +111,11 @@ } void LCD_Write_Seconds() { - int Seconds = LCD_Time_Get("Seconds"); + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); + int Seconds = Time_Pointer->tm_sec; + Time_Lock_Main.unlock(); stringstream ss; ss << Seconds; string Second_String = ss.str(); @@ -118,21 +144,26 @@ } if(mode == 0)//Default mode { - cout << "In mode 0" << endl; + cout << "In mode 0 " << endl; + 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 + + 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); 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 + + Time_Lock_Main.lock(); + time_t Time = time(NULL); + tm* Time_Pointer = localtime(&Time); LCD.Display_Clear(); - sprintf (LCD_buffer, "%d:%d %d,%d",LCD_Time_Get("Hours"),LCD_Time_Get("Minutes"),LCD_Time_Get("Months"),LCD_Time_Get("Years"));//Used for converting to a sting + sprintf (LCD_buffer, "%d:%d %d,%d",Time_Pointer->tm_hour,Time_Pointer->tm_min,(Time_Pointer->tm_mon+1),(Time_Pointer->tm_year+1900));//Used for converting to a sting + Time_Lock_Main.unlock(); + LCD.DDRAM_Address(0x00); LCD.Write_String("Current Time:"); LCD.DDRAM_Address(0x40); @@ -174,7 +205,11 @@ { LCD_Write_Year(); Thread::wait(1000); - + if(SW1.read() & SW2.read() == 1) + { + mode = 3; + break; + } if(SW1.read() == 1 & SW2.read() == 0) { Add_Year(); @@ -184,12 +219,6 @@ Subtract_Year(); } LCD_Write_Year(); - - if(SW1.read() & SW2.read() == 1) - { - mode = 3; - break; - } } } else if(mode == 3)//Set the Month @@ -200,7 +229,11 @@ { LCD_Write_Month(); Thread::wait(1000); - + if(SW1.read() & SW2.read() == 1) + { + mode = 4; + break; + } if(SW1.read() == 1 & SW2.read() == 0) { Add_Month(); @@ -209,11 +242,7 @@ { Subtract_Month(); } - if(SW1.read() & SW2.read() == 1) - { - mode = 4; - break; - } + } } else if(mode == 4)//Set the Day @@ -224,7 +253,11 @@ { LCD_Write_Day(); Thread::wait(1000); - + if(SW1.read() & SW2.read() == 1) + { + mode = 0; + break; + } if(SW1.read() == 1 & SW2.read() == 0) { Add_Day(); @@ -233,11 +266,6 @@ { Subtract_Day(); } - if(SW1.read() & SW2.read() == 1) - { - mode = 0; - break; - } } } else if(mode == 5)//Set the Hour @@ -248,7 +276,11 @@ { LCD_Write_Hour(); Thread::wait(1000); - + if(SW1.read() & SW2.read() == 1) + { + mode = 6; + break; + } if(SW1.read() == 1 & SW2.read() == 0) { Add_Hour(); @@ -258,11 +290,7 @@ Subtract_Hour(); } - if(SW1.read() & SW2.read() == 1) - { - mode = 6; - break; - } + } } else if(mode == 6)//Set the Minute @@ -273,7 +301,11 @@ { LCD_Write_Minute(); Thread::wait(1000); - + if(SW1.read() & SW2.read() == 1) + { + mode = 7; + break; + } if(SW1.read() == 1 & SW2.read() == 0) { Add_Minute(); @@ -282,11 +314,6 @@ { Subtract_Minute(); } - if(SW1.read() & SW2.read() == 1) - { - mode = 7; - break; - } } } else if(mode == 7)//Set the Seconds @@ -297,7 +324,11 @@ { LCD_Write_Seconds(); Thread::wait(1000); - + if(SW1.read() & SW2.read() == 1) + { + mode = 0; + break; + } if(SW1.read() == 1 & SW2.read() == 0) { Add_Second(); @@ -306,11 +337,6 @@ { Subtract_Second(); } - if(SW1.read() & SW2.read() == 1) - { - mode = 0; - break; - } } } else @@ -459,14 +485,15 @@ temp = sensor.getTemperature(); //Read Temperature pressure = sensor.getPressure(); //Read Pressure lux = adcIn.read(); //Read Light + + Time_Lock_Main.lock(); time_t buffer_time = time(NULL); //Read Time + Time_Lock_Main.unlock(); DATA *Send_Data = mail_box.alloc(); //Allocate a block from the memory pool, Type Data - if (Send_Data == NULL) { //If Data is empty - //pc.printf("Out of memory\n\r"); //Print out of memory warning - return; - } + if (Send_Data == NULL) {return;} + Send_Data->set_time(buffer_time); //Pass in Time Send_Data->set_temperature(temp); //Pass in Temp Send_Data->set_pressure(pressure); //Pass in Pres @@ -516,9 +543,9 @@ } //Last message before sampling begins LCD.Display_Clear(); - LCD.Write_String("READY Player"); + LCD.Write_String("Ready Player"); LCD.DDRAM_Address(0x40); - LCD.Write_String("ONE"); + LCD.Write_String("One"); LCD.DDRAM_Address(0x00);