Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Revision:
31:4a88bf97b53e
Parent:
30:4cde05cc7c4f
Child:
32:8f2795716e97
--- a/main.cpp	Sat Jan 06 17:43:17 2018 +0000
+++ b/main.cpp	Sat Jan 06 23:04:05 2018 +0000
@@ -1,7 +1,7 @@
 /*
 ELEC 351 Group T
 Team Members : Christopher Hills, Thomas Morris
-Current Verision 13
+Current Verision 14
 Overiew: Working Tasks 1,2,4,5,6,7,8,10,11,12,13
 
 Last Revision: Added Mail Box to serial
@@ -29,65 +29,74 @@
         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.rise(&SW1RisingEdge);  //Now wait for a rising edge
-}
-void SDWrite()
+void LCD_Write_Year()
 {
-    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;                      //Create pointer to mailbox
-        DATA msg_sd;                                                    //Create temporary instance of DATA class
-
-        msg_sd.set_time(Rec_Data_SD->get_time());                       //Copy time from mailbox to temporary instance
-        msg_sd.set_temperature(Rec_Data_SD->get_temperature());         //Copy temperature from mailbox to temporary instance
-        msg_sd.set_pressure(Rec_Data_SD->get_pressure());               //Copy pressure from mailbox to temporary instance
-        msg_sd.set_light(Rec_Data_SD->get_light());                     //Copy light from mailbox to temporary instance
-        mail_box.free(Rec_Data_SD);                                     //Free space in the mailbox (delete earliest sample taken)
-    }
-}
-//Interrupt service routive for SW1 rising edge (release)
-void SW1RisingEdge()
-{
-    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;    
-            }   
-        }
-    }
+        int Years = LCD_Time_Get("Years");
+        stringstream ss;
+        ss << Years;
+        string Year_String = ss.str();
+        LCD.DDRAM_Address(0x00);
+        LCD.Write_String("Set Year");
+        LCD.DDRAM_Address(0x40);
+        LCD.Write_String(Year_String);   
 }
 
-void SW2RisingEdge()
+void LCD_Write_Month()
+{
+        int Months = LCD_Time_Get("Months");
+        stringstream ss;
+        ss << Months;
+        string Month_String = ss.str();
+        LCD.DDRAM_Address(0x00);
+        LCD.Write_String("Set Month");
+        LCD.DDRAM_Address(0x40);
+        LCD.Write_String(Month_String);   
+}
+void LCD_Write_Day()
+{
+        int Days = LCD_Time_Get("Days");
+        stringstream ss;
+        ss << Days;
+        string Day_String = ss.str();
+        LCD.DDRAM_Address(0x00);
+        LCD.Write_String("Set Day");
+        LCD.DDRAM_Address(0x40);
+        LCD.Write_String(Day_String);   
+}
+
+
+void LCD_Write_Hour()
 {
-    
-    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;
+        int Hours = LCD_Time_Get("Hours");
+        stringstream ss;
+        ss << Hours;
+        string Hour_String = ss.str();
+        LCD.DDRAM_Address(0x00);
+        LCD.Write_String("Set Hour");
+        LCD.DDRAM_Address(0x40);
+        LCD.Write_String(Hour_String);   
+}
+void LCD_Write_Minute()
+{
+        int Minutes = LCD_Time_Get("Minutes");
+        stringstream ss;
+        ss << Minutes;
+        string Minute_String = ss.str();
+        LCD.DDRAM_Address(0x00);
+        LCD.Write_String("Set Minute");
+        LCD.DDRAM_Address(0x40);
+        LCD.Write_String(Minute_String);   
+}
+void LCD_Write_Seconds()
+{
+        int Seconds = LCD_Time_Get("Seconds");
+        stringstream ss;
+        ss << Seconds;
+        string Second_String = ss.str();
+        LCD.DDRAM_Address(0x00);
+        LCD.Write_String("Set Second");
+        LCD.DDRAM_Address(0x40);
+        LCD.Write_String(Second_String);   
 }
 
 void LCD_Output()
@@ -96,11 +105,10 @@
     {
         Thread::wait(10);//Dont Delete
         osEvent evt_lcd = mail_box.get();                        //Get the latest entry from "mail_box"
-        DATA msg_lcd;  
+        DATA msg_lcd;  //Create temporary instance of DATA class
         if (evt_lcd.status == osEventMail)
         {
             DATA *Rec_Data_LCD = (DATA*)evt_lcd.value.p;                    //Create pointer to mailbox
-                                                             //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
@@ -111,8 +119,6 @@
         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   
@@ -126,50 +132,191 @@
             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);
+            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   
             LCD.DDRAM_Address(0x00);
             LCD.Write_String("Current Time:");
             LCD.DDRAM_Address(0x40);
             LCD.Write_String(LCD_buffer);
+            
+            if(SW1.read() & SW2.read() == 1)
+            {
+                mode = 1;   
+            }
         }
         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("<              >");
-            
-            
-
+            while(1)
+            {
+                LCD.DDRAM_Address(0x00);
+                LCD.Write_String("Date        Time");
+                LCD.DDRAM_Address(0x40);
+                LCD.Write_String("<              >");
+                Thread::wait(1000);
+                if(SW1.read() == 1)
+                {
+                    mode = 2;
+                    break;   
+                }
+                if(SW2.read() == 1)
+                {
+                    mode = 5;
+                    break;
+                }
+            }
         } 
         else if(mode == 2)//Set the Year
         {
             cout << "In Mode 2" << endl;
+            LCD.Display_Clear();
+            while(1)
+            {          
+                Thread::wait(1000);
+                LCD_Write_Year();
+                
+                if(SW1.read() == 1 & SW2.read() == 0)
+                {
+                    Add_Year();
+                }
+                else if(SW2.read() == 1 & SW1.read() == 0)
+                {
+                    Subtract_Year();   
+                }
+                LCD_Write_Year();
+                
+                if(SW1.read() & SW2.read() == 1)
+                {
+                    mode = 3;
+                    break;   
+                }
+            }
         } 
         else if(mode == 3)//Set the Month
         {
             cout << "In Mode 3" << endl;
+            LCD.Display_Clear();
+            while(1)
+                {
+                    
+                Thread::wait(1000);
+                
+                if(SW1.read() == 1 & SW2.read() == 0)
+                {
+                    Add_Month();
+                }
+                else if(SW2.read() == 1 & SW1.read() == 0)
+                {
+                    Subtract_Month();   
+                }
+                LCD_Write_Month();
+                
+                if(SW1.read() & SW2.read() == 1)
+                {
+                    mode = 4;
+                    break;   
+                }
+            }
         }
         else if(mode == 4)//Set the Day
         {
             cout << "In Mode 4" << endl;
+            LCD.Display_Clear();
+            while(1)
+            {
+                Thread::wait(1000);
+                
+                if(SW1.read() == 1 & SW2.read() == 0)
+                {
+                    Add_Day();
+                }
+                else if(SW2.read() == 1 & SW1.read() == 0)
+                {
+                    Subtract_Day();   
+                }
+                LCD_Write_Day();
+                
+                if(SW1.read() & SW2.read() == 1)
+                {
+                    mode = 0;   
+                    break;
+                }
+            }
         } 
         else if(mode == 5)//Set the Hour
         {
             cout << "In Mode 5" << endl;
+            LCD.Display_Clear();
+            while(1)
+            {
+                 Thread::wait(1000);
+                
+                if(SW1.read() == 1 & SW2.read() == 0)
+                {
+                    Add_Hour();
+                }
+                else if(SW2.read() == 1 & SW1.read() == 0)
+                {
+                    Subtract_Hour();   
+                }
+                LCD_Write_Hour();
+                
+                if(SW1.read() & SW2.read() == 1)
+                {
+                    mode = 6;  
+                    break; 
+                }
+            }
         } 
         else if(mode == 6)//Set the Minute
         {
             cout << "In Mode 6" << endl;
+            LCD.Display_Clear();
+            while(1)
+            {
+                 Thread::wait(1000);
+                
+                if(SW1.read() == 1 & SW2.read() == 0)
+                {
+                    Add_Minute();
+                }
+                else if(SW2.read() == 1 & SW1.read() == 0)
+                {
+                    Subtract_Minute();   
+                }
+                LCD_Write_Minute();
+                
+                if(SW1.read() & SW2.read() == 1)
+                {
+                    mode = 7;  
+                    break; 
+                }
+            }
         }  
         else if(mode == 7)//Set the Seconds
         {
             cout << "In Mode 7" << endl;
+            LCD.Display_Clear();
+            while(1)
+            {
+                 Thread::wait(1000);
+                
+                if(SW1.read() == 1 & SW2.read() == 0)
+                {
+                    Add_Second();
+                }
+                else if(SW2.read() == 1 & SW1.read() == 0)
+                {
+                    Subtract_Second();   
+                }
+                LCD_Write_Seconds();
+                
+                if(SW1.read() & SW2.read() == 1)
+                {
+                    mode = 0;  
+                    break; 
+                }
+            }
         }
         else
         {
@@ -374,7 +521,10 @@
     }
     //Last message before sampling begins
     LCD.Display_Clear();
-    LCD.Write_String("READY");
+    LCD.Write_String("READY Player");
+    LCD.DDRAM_Address(0x40);
+    LCD.Write_String("ONE");
+    LCD.DDRAM_Address(0x00);
 
 
     Sample_Rate = TimerInterval;