Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Revision:
21:3c078c799caa
Parent:
20:cbb71f84cff9
Child:
22:eb4cc12087b2
diff -r cbb71f84cff9 -r 3c078c799caa main.cpp
--- a/main.cpp	Wed Dec 27 21:46:31 2017 +0000
+++ b/main.cpp	Fri Dec 29 21:21:46 2017 +0000
@@ -17,7 +17,6 @@
 #include "rtos.h"
 #include "LED.hpp"
 #include "DATA.hpp"
-#include "NETWORK.hpp"
 #include "LCD.hpp"
 #define SamplingTime 1
 #define NotSamplingTime 0
@@ -30,7 +29,7 @@
 
 
 Serial pc(USBTX, USBRX);
-//SW1+SW2 are declared as interrupt ins in sample hardwarec.pp
+//SW1+SW2 are declared as interrupt ins in sample hardware.cpp
 
 
 //Thread IDs
@@ -40,6 +39,7 @@
 osThreadId id3;
 osThreadId id4;
 
+
 Timeout sw1TimeOut;//Used to prevent switch bounce
 
 LED Red_led(PE_15);
@@ -47,6 +47,8 @@
 LED Green_led(PB_11);
 
 LCD LCD(D8,D9,D4,A0,A1,A2,A3,D7,D6,D3,D1); 
+char LCD_buffer [50];
+int LCD_sprintf;
 
 //Tickers
 
@@ -55,8 +57,9 @@
 //Threads
 Thread t1;
 Thread t2;
-Thread t5;
-Thread t6;
+Thread t3;
+Thread t4;
+Thread t180;//cos yolo
 
 double temp = 0;
 double pressure = 0;
@@ -90,7 +93,6 @@
         mail_box.free(Rec_Data_Network);                                        //Free space in the mailbox (delete earliest sample taken)
     
         networktest();
-        //NETWORK_Print();     //Runs the network
     }                                                
 }
 
@@ -151,18 +153,32 @@
             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
+                                      
+                /*LCD_sprintf = */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.Display_Clear();
+                LCD.DDRAM_Address(0x00);
+                LCD.Write_String("Temp Pres  li");
+                LCD.DDRAM_Address(0x40);
+                
+                LCD.Write_String(LCD_buffer);
+                //LCD.Write_String("Temp Pres  li\n");
+                //LCD.Write_String("%1.1f ",    msg_lcd.get_temperature());//Print Temperature to LCD
+                //LCD.Write_String("%1.1f ",    msg_lcd.get_pressure());//Print Pressure to LCD
+                //LCD.Write_String("%1.1f\n",   msg_lcd.get_light()); //Print Light to LCD
+                
             }
             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.cls();                                                              //Write new data to LCD (not fast!)
-                lcd.printf("Current Time:%s", scom_time_buffer);
+                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
             {
@@ -242,6 +258,8 @@
 } 
 int main() 
 {  
+
+    
     //Greeting
     pc.printf("Test Start");
     pc.printf("\n\r");
@@ -251,17 +269,15 @@
     
     LCD.Initialise();
     LCD.DDRAM_Address(0x40);
-    LCD.Write_String("Hi Tom 21:41");
-    
-    
-    /*
+  
+        
     post();     //Power on Self Test
     
     //Initialise the SD card (this needs to move)
     if ( sd.init() != 0) {
         printf("Init failed \n");
         lcd.cls();
-        lcd.printf("CANNOT INIT SD");        
+        lcd.printf("CANNOT INIT SD");        //Change me
         errorCode(FATAL);
     } 
     
@@ -273,24 +289,27 @@
     if (fp == NULL) {
         error("Could not open file for write\n");
         lcd.cls();
-        lcd.printf("CANNOT OPEN FILE\n\n");
+        lcd.printf("CANNOT OPEN FILE\n\n");//Change me
         errorCode(FATAL);
     }
     
     //Last message before sampling begins
-    lcd.cls();
-    lcd.printf("READY\n\n");
-    */
+    lcd.cls();//change me
+    lcd.printf("READY\n\n");//change me
+    
     
     //Run interrupt
     Sample_timer.attach(&Sample_signal_set,TimerInterval);
     SW1.fall(&SW1FallingEdge);
     //Run Threads
     
+    Thread t4(osPriorityAboveNormal);//Sets the Priority bigly
     t1.start(Sample);
     t2.start(Serial_Comms);
-    //t5.start(ModeSelection);
-    t6.start(Network);
+    t3.start(ModeSelection);
+    t4.start(Network);
+    
+    
     //Main thread ID
     
     idMain = osThreadGetId();   //CMSIS RTOS call
@@ -298,11 +317,14 @@
     //Thread ID
     id1 = t1.gettid();
     id2 = t2.gettid();
-    //id5 = t5.gettid();
+    id3 = t3.gettid();
+    id4 = t4.gettid();
+    
     
     //Toggle Green LED after a button has been pressed
     //Press either switch to unmount
     DigitalIn  onBoardSwitch(USER_BUTTON);
+    
     while (onBoardSwitch == 0){
         
     }