Alix Germany / Mbed OS Coursework_Version_8

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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ntp-client/NTPClient.h"
00003 #include "sample_hardware.hpp"
00004 #include "Sampler.hpp"
00005 #include "SwitchManager.hpp"
00006 #include "SDcard.hpp"
00007 
00008 void LCD_Thread(void);
00009 void SAMP_Thread(void);
00010 void SERIAL_Thread(void);
00011 void Network_Thread(void);
00012 void SD_Thread(void);
00013 
00014 
00015 Thread tLCD, tSAMP, tSERIAL, tSD, tNET;
00016 
00017 // Define member object
00018 Sampler m_oSample;
00019 
00020 int main()
00021 {  
00022     tLCD.start(LCD_Thread); //start the LCD thread
00023     tSAMP.start(SAMP_Thread); //start the sampling thread
00024     tSERIAL.start(SERIAL_Thread); //start the serial communications thread
00025     tNET.start(Network_Thread); //start the networking thread
00026     tSD.start(SD_Thread); //start the SD card thread
00027     Thread::wait(osWaitForever);
00028 }
00029 
00030 
00031 void LCD_Thread()
00032 {   
00033     while(1)
00034     {
00035         //m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_time_date);
00036         m_oDisplay.LCD_Queue.call_every(1000, &m_oDisplay, &LCD_Data::display_LCD); //displays the current sensor information onto the LCD screen every x miliseconds 
00037         m_oDisplay.LCD_Queue.dispatch();  //dispatches the above tasks to the queue, then blocks main forever unless ' break_dispatch () ' is used 
00038         while(true) 
00039         {
00040             redLED = 1;
00041             wait(0.5);
00042             redLED = 0;
00043             wait(0.1);    
00044         }
00045     }
00046 }
00047 
00048 void SAMP_Thread()
00049  {
00050      while(1)
00051      {
00052         m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample);     // Publish sample 
00053         m_oSample.SAMP_Queue.dispatch();
00054         while(true) 
00055         {   // Flash if the event queue is exited.
00056             yellowLED = 1;
00057             wait(0.5);
00058             yellowLED = 0;
00059             wait(0.1);    
00060         }
00061      }
00062 }
00063 
00064 void SERIAL_Thread()
00065 {
00066       while(1)
00067      {
00068         m_oSerial.SERIAL_Queue.call_every(1000, &m_oSerial, &Serialcomms::updateTerminal);     // Publish sample 
00069         m_oSerial.SERIAL_Queue.dispatch();
00070         while(true) 
00071         {   // Flash if the event queue is exited.
00072             yellowLED = 1;
00073             wait(0.5);
00074             yellowLED = 0;
00075             wait(0.1);    
00076         }
00077      }   
00078 }
00079 
00080 
00081 void SD_Thread() 
00082 { 
00083     while(1) 
00084     { 
00085          m_oSD.SDcard_Queue.call_every(5000, &m_oSD, &SDcard::Save_Data); 
00086          m_oSD.SDcard_Queue.dispatch(); 
00087           while(true)  
00088        {   // Flash if the event queue is exited. 
00089             greenLED = 1; 
00090             wait(0.5); 
00091             greenLED = 0; 
00092             wait(0.1);     
00093         } 
00094     } 
00095 }    
00096 
00097      
00098 
00099 
00100     void Network_Thread() 
00101 { 
00102     while(1) 
00103     { 
00104          m_oNet.Network_Queue.call_every(5000, &m_oNet, &Network::NetPush); 
00105          m_oNet.Network_Queue.dispatch(); 
00106 
00107           while(true)  
00108         {   // Flash if the event queue is exited. 
00109             greenLED = 1; 
00110             wait(0.5); 
00111             greenLED = 0; 
00112             wait(0.1);     
00113 
00114         } 
00115     }    
00116 } 
00117 
00118