Alix & Sam's combined versions
Dependencies: BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client
main.cpp@10:eea19f8e6122, 2018-12-13 (annotated)
- Committer:
- Alix955
- Date:
- Thu Dec 13 15:24:22 2018 +0000
- Revision:
- 10:eea19f8e6122
- Parent:
- 9:f5eae5211225
Alix & Sams versions combined;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
O_Thom | 5:f87129ac8bf3 | 1 | #include "mbed.h" |
Alix955 | 9:f5eae5211225 | 2 | #include "ntp-client/NTPClient.h" |
O_Thom | 0:f9a18207d99c | 3 | #include "sample_hardware.hpp" |
O_Thom | 0:f9a18207d99c | 4 | #include "Sampler.hpp" |
Alix955 | 9:f5eae5211225 | 5 | #include "SwitchManager.hpp" |
O_Thom | 6:b7f6e0c0f646 | 6 | |
O_Thom | 6:b7f6e0c0f646 | 7 | void LCD_Thread(void); |
O_Thom | 6:b7f6e0c0f646 | 8 | void SAMP_Thread(void); |
O_Thom | 6:b7f6e0c0f646 | 9 | void SERIAL_Thread(void); |
Alix955 | 10:eea19f8e6122 | 10 | void Network_Thread(void); |
O_Thom | 6:b7f6e0c0f646 | 11 | |
Alix955 | 10:eea19f8e6122 | 12 | Thread tLCD, tSAMP, tSERIAL, tSD, tNET; |
O_Thom | 5:f87129ac8bf3 | 13 | |
O_Thom | 6:b7f6e0c0f646 | 14 | // Define member object |
O_Thom | 7:8664a45f5ce1 | 15 | Sampler m_oSample; |
O_Thom | 5:f87129ac8bf3 | 16 | |
O_Thom | 6:b7f6e0c0f646 | 17 | int main() |
O_Thom | 6:b7f6e0c0f646 | 18 | { |
O_Thom | 6:b7f6e0c0f646 | 19 | tLCD.start(LCD_Thread); |
O_Thom | 6:b7f6e0c0f646 | 20 | tSAMP.start(SAMP_Thread); |
O_Thom | 6:b7f6e0c0f646 | 21 | tSERIAL.start(SERIAL_Thread); |
Alix955 | 10:eea19f8e6122 | 22 | tNET.start(Network_Thread); |
O_Thom | 6:b7f6e0c0f646 | 23 | Thread::wait(osWaitForever); |
O_Thom | 6:b7f6e0c0f646 | 24 | } |
O_Thom | 0:f9a18207d99c | 25 | |
O_Thom | 0:f9a18207d99c | 26 | |
O_Thom | 6:b7f6e0c0f646 | 27 | void LCD_Thread() |
O_Thom | 6:b7f6e0c0f646 | 28 | { |
O_Thom | 6:b7f6e0c0f646 | 29 | while(1) |
O_Thom | 6:b7f6e0c0f646 | 30 | { |
Alix955 | 10:eea19f8e6122 | 31 | //m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_time_date); |
Alix955 | 10:eea19f8e6122 | 32 | 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 |
O_Thom | 6:b7f6e0c0f646 | 33 | m_oDisplay.LCD_Queue.dispatch(); //dispatches the above tasks to the queue, then blocks main forever unless ' break_dispatch () ' is used |
O_Thom | 6:b7f6e0c0f646 | 34 | while(true) |
O_Thom | 6:b7f6e0c0f646 | 35 | { |
O_Thom | 6:b7f6e0c0f646 | 36 | redLED = 1; |
O_Thom | 6:b7f6e0c0f646 | 37 | wait(0.5); |
O_Thom | 6:b7f6e0c0f646 | 38 | redLED = 0; |
O_Thom | 6:b7f6e0c0f646 | 39 | wait(0.1); |
O_Thom | 6:b7f6e0c0f646 | 40 | } |
O_Thom | 6:b7f6e0c0f646 | 41 | } |
O_Thom | 6:b7f6e0c0f646 | 42 | } |
O_Thom | 0:f9a18207d99c | 43 | |
O_Thom | 6:b7f6e0c0f646 | 44 | void SAMP_Thread() |
O_Thom | 6:b7f6e0c0f646 | 45 | { |
O_Thom | 6:b7f6e0c0f646 | 46 | while(1) |
O_Thom | 6:b7f6e0c0f646 | 47 | { |
O_Thom | 7:8664a45f5ce1 | 48 | m_oSample.SAMP_Queue.call_every(500, &m_oSample, &Sampler::publishSample); // Publish sample |
O_Thom | 7:8664a45f5ce1 | 49 | m_oSample.SAMP_Queue.dispatch(); |
O_Thom | 6:b7f6e0c0f646 | 50 | while(true) |
O_Thom | 6:b7f6e0c0f646 | 51 | { // Flash if the event queue is exited. |
O_Thom | 6:b7f6e0c0f646 | 52 | yellowLED = 1; |
O_Thom | 6:b7f6e0c0f646 | 53 | wait(0.5); |
O_Thom | 6:b7f6e0c0f646 | 54 | yellowLED = 0; |
O_Thom | 6:b7f6e0c0f646 | 55 | wait(0.1); |
O_Thom | 6:b7f6e0c0f646 | 56 | } |
O_Thom | 6:b7f6e0c0f646 | 57 | } |
O_Thom | 6:b7f6e0c0f646 | 58 | } |
O_Thom | 6:b7f6e0c0f646 | 59 | |
O_Thom | 6:b7f6e0c0f646 | 60 | void SERIAL_Thread() |
O_Thom | 0:f9a18207d99c | 61 | { |
O_Thom | 6:b7f6e0c0f646 | 62 | while(1) |
O_Thom | 6:b7f6e0c0f646 | 63 | { |
O_Thom | 7:8664a45f5ce1 | 64 | m_oSerial.SERIAL_Queue.call_every(1000, &m_oSerial, &Serialcomms::updateTerminal); // Publish sample |
O_Thom | 7:8664a45f5ce1 | 65 | m_oSerial.SERIAL_Queue.dispatch(); |
O_Thom | 6:b7f6e0c0f646 | 66 | while(true) |
O_Thom | 6:b7f6e0c0f646 | 67 | { // Flash if the event queue is exited. |
O_Thom | 6:b7f6e0c0f646 | 68 | yellowLED = 1; |
O_Thom | 6:b7f6e0c0f646 | 69 | wait(0.5); |
O_Thom | 6:b7f6e0c0f646 | 70 | yellowLED = 0; |
O_Thom | 6:b7f6e0c0f646 | 71 | wait(0.1); |
O_Thom | 6:b7f6e0c0f646 | 72 | } |
O_Thom | 6:b7f6e0c0f646 | 73 | } |
O_Thom | 0:f9a18207d99c | 74 | } |
O_Thom | 6:b7f6e0c0f646 | 75 | |
Alix955 | 10:eea19f8e6122 | 76 | |
Alix955 | 10:eea19f8e6122 | 77 | |
Alix955 | 10:eea19f8e6122 | 78 | void Network_Thread() |
Alix955 | 10:eea19f8e6122 | 79 | { |
Alix955 | 10:eea19f8e6122 | 80 | while(1) |
Alix955 | 10:eea19f8e6122 | 81 | { |
Alix955 | 10:eea19f8e6122 | 82 | m_oNet.Network_Queue.call_every(10, &m_oNet, &Network::NetPush); |
Alix955 | 10:eea19f8e6122 | 83 | m_oNet.Network_Queue.dispatch(); |
Alix955 | 10:eea19f8e6122 | 84 | |
Alix955 | 10:eea19f8e6122 | 85 | while(true) |
Alix955 | 10:eea19f8e6122 | 86 | { // Flash if the event queue is exited. |
Alix955 | 10:eea19f8e6122 | 87 | greenLED = 1; |
Alix955 | 10:eea19f8e6122 | 88 | wait(0.5); |
Alix955 | 10:eea19f8e6122 | 89 | greenLED = 0; |
Alix955 | 10:eea19f8e6122 | 90 | wait(0.1); |
Alix955 | 10:eea19f8e6122 | 91 | |
Alix955 | 10:eea19f8e6122 | 92 | } |
Alix955 | 10:eea19f8e6122 | 93 | } |
Alix955 | 10:eea19f8e6122 | 94 | } |
Alix955 | 10:eea19f8e6122 | 95 | |
Alix955 | 10:eea19f8e6122 | 96 |