V4

Dependencies:   BMP280

Fork of Thread_Communication_V3 by BDG

Revision:
1:bca9993a0df3
Parent:
0:cb3a5c15b01e
Child:
2:28d12a3db239
--- a/main.cpp	Tue Dec 12 17:05:59 2017 +0000
+++ b/main.cpp	Wed Dec 13 17:20:18 2017 +0000
@@ -9,54 +9,92 @@
 BMP280 Sensor(D14, D15);
 void PrintLCD ();
 
+/* Mail */
+typedef struct {
+    float LDR_Value;
+    float temp_Value;
+    float press_Value;
+} mail_t;
+
+//Class type
+/*class mail_t {
+public:    
+    float LDR_Value;
+    float temp_Value;
+    float press_Value;
+    
+    //Constructor
+    mail_t( float LDR_Value, float temp_Value, int s2) {
+        adcValue = f;
+        sw1State = s1;
+        sw2State = s2;    
+    }
+};*/
+
+Mail<mail_t, 16> mail_box;
 
 
-float LDR_Value;
-float temp_Value;
-float press_Value;
 Thread t1;
 Thread t2;
 
-Mutex door;
+//Mutex door;
 
 void PrintLCD () {
     
     int i = 0;
     while(1){
-        char DataString[16];
+        char lightString[16];
+        char tempString[16];
+        char pressString[16];
+        
+
         lcd.Clear();
         lcd.RowSelect(0);
-        
+         
         switch (i){
-        case 0:
+        case 0: 
+            osEvent evt = mail_box.get();
+        
+            if (evt.status == osEventMail) {
+                mail_t *mail = (mail_t*)evt.value.p;
             
+                sprintf(lightString,"%.4f", mail->LDR_Value);
+                sprintf(tempString,"%2.2f", mail->temp_Value);
+                sprintf(pressString,"%4.2f", mail->press_Value);    
+                
+                mail_box.free(mail);
+            }
+               
+            lcd.Write("Light Level:");
+            lcd.RowSelect(1);
+            lcd.Write(lightString);
+            i++;
             
-            sprintf(DataString,"%.4f", LDR_Value);
-            lcd.Write("Light Level:");
-            i++;
             break;
         case 1:
-        
-            
-            sprintf(DataString,"%2.2f", temp_Value);
+
             lcd.Write("Temperature:");
+            lcd.RowSelect(1);
+            lcd.Write(tempString);
             i++;
 
             break;
         
         case 2:
-         
-            sprintf(DataString,"%4.2f", press_Value);
+
             lcd.Write("Pressure:");
+            lcd.RowSelect(1);
+            lcd.Write(pressString);
             i =0;
             break;
         default:
             i = 0;
             break;
         }
+        Red_int = !Red_int;
         
-        lcd.RowSelect(1);
-        lcd.Write(DataString);
+        
+
         Thread::wait (5000);
         }
 }
@@ -65,20 +103,25 @@
 int main() {
 
     t1.start(PrintLCD);
-    
+
         while(1) {
-        Green_int = 1;
+            Green_int = !Green_int;
+
+            mail_t *mail = mail_box.alloc();
+            mail->LDR_Value = LDR_In.read(); 
+            mail->temp_Value = Sensor.getTemperature();
+            mail->press_Value = Sensor.getPressure();
+            mail_box.put(mail);
         
-        
-        door.lock();
+        /*door.lock();
        
         LDR_Value = LDR_In.read();
         temp_Value = Sensor.getTemperature();
         press_Value = Sensor.getPressure();
-        door.unlock();
+        door.unlock();*/
         
         
-        Thread::wait (15000);
+            Thread::wait (15000);
         }
 
 }