Repo. for the ELEC351 Coursework - Oliver Thompson

Dependencies:   BMP280 ELEC350-Practicals-FZ429- TextLCD watchdog_RTOS BME280 ntp-client

Revision:
20:2ce28a5032d5
Parent:
18:a036c2e5ff89
--- a/Sampler.hpp	Thu Dec 13 16:09:54 2018 +0000
+++ b/Sampler.hpp	Wed Jan 02 12:12:30 2019 +0000
@@ -1,48 +1,59 @@
 #ifndef _SAMPLER_
 #define _SAMPLER_
+
 #include "mbed.h"
 #include "LCD.hpp"
 #include "SerialComms.hpp"
+#include "SDcard.hpp"
 #include "sample_hardware.hpp"
 #include <vector>
-
-
 #define Activate_Flag 1
 
-LCD_Data m_oDisplay;
-Serialcomms m_oSerial(m_oDisplay);
+Serialcomms m_oSerial;
 
 class Sampler
 {
 private:
-
+    int SampleEN;
+    sample_message message;
+   
 public: 
     EventQueue SAMP_Queue;                  //Initialise the EventQueue
-    sample_message message;
-    int SampleEN = 1;
+
     Sampler()   //Constructor 
     {
         SampleEN = 0;
     }
     ~Sampler() //Destructor - should the instance go out of scope, this is called
     {
+            
     }
-    
-    void publishSample()
-    {
-        if (SampleEN)
+ 
+        void getSerial2Sampler()    // Queue Consumer
         {
-             sample_message message = getData();
-             m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_sensor_info, message);
-             m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::setsampledata, message);
-            //SD_Queue.call(this, &SD_Queue::update_sensor_info, sample_data, sample_data);
+            if (!Serial2Sampler.empty())
+            {
+                osEvent evt = Serial2Sampler.get();     //With timeout
+        switch (evt.status) 
+                {
+            case osEventMessage:
+                //Normal status
+                                if ((evt.value.v == 0) || (evt.value.v == 1))   // Update the enable pin if the value co-responds to allowed cases
+                                {
+                                    SampleEN = evt.value.v;             
+                                }
+                greenLED = !greenLED;
+            case osEventTimeout:
+                //Timeout
+                //printf("Serial2Sampler->get() returned %02x status (timeout)\n\r", evt.status);
+            default:
+                //All other errors (see cmsis_os.h for meaning of error code)
+                //printf("Serial2Sampler->get() returned %02x status\n\r", evt.status);
+                }               
+            }
         }
-    }
-    
-    void updateSampleEN(int EN)
-    {
-        SampleEN = EN;
-    }
+
+
     void getData()
     {
         float temp = sensor.getTemperature();
@@ -55,12 +66,27 @@
         msg.temp = temp;
         msg.pressure = pressure;
         msg.ldr = LDR;
-        redLED != redLED;
         message = msg;  // Write to the private 'global' variable
+    }
+        
+    void publishSample()
+    {
+       if (SampleEN == 1)
+       {
+          getData();
+          m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_sensor_info, message);
+                  m_oNet.Network_Queue.call(&m_oNet, &Network::update_sensor_info, message);
+          m_oSerial.SERIAL_Queue.call(&m_oSerial, &Serialcomms::setsampledata, message);
+                  //m_oSD.SDcard_Queue.call(&m_oSD, &SDcard::update_sensor_info, message);
         }
-    
+    }
+   
+
     void updateTimeData();
+};
+
+#endif
 
 
-};
-#endif
\ No newline at end of file
+Sampler m_oSample;
+