Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BMP280 ELEC350-Practicals-FZ429 TextLCD BME280 ntp-client
Revision 5:f87129ac8bf3, committed 2018-11-29
- Comitter:
- O_Thom
- Date:
- Thu Nov 29 16:08:28 2018 +0000
- Parent:
- 4:740cba3f2716
- Child:
- 6:b7f6e0c0f646
- Commit message:
- Commit before change from sample message class to typedef struct
Changed in this revision
--- a/ELEC350-Practicals-FZ429.lib Tue Nov 27 12:51:34 2018 +0000 +++ b/ELEC350-Practicals-FZ429.lib Thu Nov 29 16:08:28 2018 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/O_Thom/code/ELEC350-Practicals-FZ429/#8a08e08e4d25 +https://os.mbed.com/teams/University-of-Plymouth-Stage-2-and-3/code/ELEC350-Practicals-FZ429/#df979097cc71
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.cpp Thu Nov 29 16:08:28 2018 +0000
@@ -0,0 +1,22 @@
+#include "mbed.h"
+#include "sample_hardware.hpp"
+#include "LCD.hpp"
+
+//EventQueue LCD_Queue; //create an event queue for main
+Ticker read_Data; //used to read the sensor data information every 5 seconds from mail queue
+
+void LCD_Thread()
+{
+ while(1)
+ {
+ 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
+ m_oDisplay.LCD_Queue.call_every(5000, &m_oDisplay, &LCD_Data::update_sensor_info); //reads sensor information every X miliseconds
+ m_oDisplay.LCD_Queue.dispatch(); //dispatches the above tasks to the queue, then blocks main forever unless ' break_dispatch () ' is used
+ while(true) {
+ redLED = 1;
+ wait(0.5);
+ redLED = 0;
+ wait(0.1);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD.hpp Thu Nov 29 16:08:28 2018 +0000
@@ -0,0 +1,52 @@
+ #ifndef _LCD_
+ #define _LCD_
+ #include "mbed.h"
+ #include "message.hpp"
+
+ class LCD_Data
+ {
+ private: //private variables can only be changed via functions in this function
+ float temp; //current temperature of sensor, updated every 15 seconds
+ float pressure; //current pressure of sensor, updated every 15 seconds
+ float fLDR; //current light level from LDR, updated every 15 seconds
+ int flip;
+ void update_temp(double temp) //use this function to update the current temperature value
+ {
+ temp = sensor.getTemperature();
+ }
+ void update_pressure(double pressure) //use this function to update the current pressure value
+ {
+ pressure = sensor.getPressure();
+ }
+ public:
+ EventQueue LCD_Queue; //create an event queue for main
+
+ LCD_Data(){ //constructor, initializes the FLIP variable for use in toggling the bottom line of the LCD
+ flip = 1;
+ temp = sensor.getTemperature();
+ pressure = sensor.getPressure();
+ }
+ void update_sensor_info() //updates all current sensor information, this is called by a ticker every 5 seconds to read from the mailbox
+ {
+ update_temp(0); // Include message class passing of data
+ update_pressure(0);
+ }
+ void display_LCD() //updates the current LCD display with the new sensor information
+ {
+ lcd.cls(); //clear current LCD display
+ lcd.printf("%4.2fC", temp); //print temperature to the top line of LCD, 2dp celcius
+ switch(flip){
+ case 1:
+ lcd.printf("\n%4.2f mbar", pressure); //print pressure to bottom line of LCD, 2dp mbar
+ break;
+
+ default:
+ printf("Error in LCD flip function");
+ break;
+ }
+ }
+ }; //end of class LCD_Data
+// Define Objects for the LCD_Data Class
+LCD_Data m_oDisplay;
+
+ #endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Sampler.cpp Thu Nov 29 16:08:28 2018 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+#include "sample_hardware.hpp"
+#include "Sampler.hpp"
+
+Sampler m_os; // Initialise the s object
+
+void SAMP_Thread()
+ {
+ while(1)
+ {
+ SAMP_Queue.call_every(1000, &m_os, &Sampler::publishSample); // Publish sample
+ SAMP_Queue.dispatch();
+ while(true) { // Flash if the event queue is exited.
+ yellowLED = 1;
+ wait(0.5);
+ yellowLED = 0;
+ wait(0.1);
+ }
+ }
+}
\ No newline at end of file
--- a/Sampler.hpp Tue Nov 27 12:51:34 2018 +0000
+++ b/Sampler.hpp Thu Nov 29 16:08:28 2018 +0000
@@ -1,88 +1,43 @@
+#ifndef _SAMPLER_
+#define _SAMPLER_
+#include "message.hpp"
#include "mbed.h"
+#include "LCD.hpp"
#define Activate_Flag 1
-// Class for Sampled Data
-class sample_message
-{
-public:
- float temp;
- float pressure;
- int sw1State;
- int sw2State;
- sample_message(float f1, float f2, int s1, int s2)
- {
- temp = f1;
- pressure = f2;
- sw1State = s1;
- sw2State = s2;
- }
-};
-
-class MailQueue
-// Potentially place all of the mail queue code into a class. Include pushing and popping functions
-// Circular buffer management also - Rewrite the oldest sample -> Include in the mail queue or in each respective thread??
-{
- private:
-
- public:
-
-};
+EventQueue SAMP_Queue; //create an event queue for main
class Sampler
{
private:
- Thread t1; // Sample Thread
- MemoryPool<sample_message, 20> mpool; //Memory Pool has 20 data blocks
- Queue<sample_message, 20> queue; //Message queue
- EventQueue sampEQueue; //Initialise the EventQueue
+ EventQueue sampEQueue; //Initialise the EventQueue
public:
void publishSample()
{
-
+ getData();
+ m_oDisplay.LCD_Queue.call(&m_oDisplay, &LCD_Data::update_sensor_info, sample);
+ //SD_Queue.call(&m_oSD_data, &SD_Queue::update_sensor_info, sample_data, sample_data);
+ //SERIAL_Queue.call(&m_oSERIAL_data, &SERIAL_Queue::update_sensor_info, sample_data, sample_data);
}
-
- void activate()
- {
- t1.signal_set(Activate_Flag); // Signal the sampling thread to move from WAITING to READY
- }
-
- void samplingThread()
+ void getData()
{
- while(1)
- {
- Thread::signal_wait(Activate_Flag);
- printf("\033[2J"); // Clear screen
- printf("\033[H"); // Home Position
- printf("**********Sample**********\n");
- int sw1State = SW1.read();
- int sw2state = SW2.read();
- printf("SW1: %d\tSW2: %d\n\r", sw1State, sw2state);
- printf("LDR: %3.5f\n\r", adcIn.read()*4095);
- float temp = sensor.getTemperature();
- float pressure = sensor.getPressure();
- #ifdef BME
- float humidity = sensor.getHumidity();
- #endif
- printf("Temperature: %5.1f\n", temp);
- printf("Pressure: %5.1f\n", pressure);
- #ifdef BME
- printf("Pressure: %5.1f\n", humidity);
- #endif
- mailqueuePush(temp, pressure, sw1State, sw2state); // Place onto the mailqueue
- }
+ int sw1State = SW1.read();
+ int sw2State = SW2.read();
+ float temp = sensor.getTemperature();
+ float pressure = sensor.getPressure();
+ #ifdef BME
+ float humidity = sensor.getHumidity();
+ #endif
+ sample.temp = temp;
+ sample.pressure = pressure;
+ sample.sw1State = sw1State;
+ sample.swState = sw1State;
}
- Sampler()
- { //Constructor
- osThreadId idMain;
- osThreadId idSample;
- idMain = osThreadGetId(); // CMSIS RTOS Call
- idSample = t1.gettid(); // Assign the id to the thread handle (Check this)
- t1.start(this, &Sampler::samplingThread); // Start the sampling thread
- // NVIC_SetPriority(TIMER0_IRQn,osPriorityHigh); // Uncomment for priority setting in the NVIC
+ Sampler() //Constructor
+ {
}
- //Destructor - should the instance go out of scope, this is called
- ~Sampler()
+ ~Sampler() //Destructor - should the instance go out of scope, this is called
{
- // Code
}
-};
\ No newline at end of file
+};
+#endif
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Thu Nov 29 16:08:28 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/TextLCD/#308d188a2d3a
--- a/main.cpp Tue Nov 27 12:51:34 2018 +0000
+++ b/main.cpp Thu Nov 29 16:08:28 2018 +0000
@@ -1,23 +1,21 @@
-/* Sampling Code */
- #include "mbed.h"
+#include "mbed.h"
#include "sample_hardware.hpp"
#include "Sampler.hpp"
+#include "LCD.hpp"
+#include "message.hpp"
+
+sample_message message;
+
+Thread tLCD;
+Thread tSAMP;
-Sampler s; // Initialise the s object
-Ticker t; // Time Initialisation
-
-void doISR()
-{
- s.activate(); // Signal the sampling thread to move from WAITING to READY
-}
-
int main()
{
- s.sampEQueue.call_every(1000, &Sampler::publishSample); // Publish sample
-
- s.sampEQueue.dispatch();
+ tLCD.start(LCD_Thread);
+ tSAMP.start(SAMP_Thread);
+ Thread::wait(osWaitForever);
}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/message.hpp Thu Nov 29 16:08:28 2018 +0000
@@ -0,0 +1,28 @@
+// Class for Sampled Data
+#ifdef _SAMPLE_MESSAGE_
+#define _SAMPLE_MESSAGE_
+class sample_message
+{
+private:
+ float temp = 0;
+ float pressure = 0;
+ int sw1State = 0;
+ int sw2State = 0;
+public:
+ sample_message(float f1, float f2, int s1, int s2) // Constructor
+ {
+ temp = f1;
+ pressure = f2;
+ sw1State = s1;
+ sw2State = s2;
+ }
+ ~sample_message() // Desconstructor
+ {
+ temp = 0;
+ pressure = 0;
+ sw1State = 0;
+ sw2State = 0;
+ }
+};
+
+#endif
\ No newline at end of file