PROJ515 / Mbed OS ELEC-351-GROUP-E-CW

Dependencies:   BMP280

Files at this revision

API Documentation at this revision

Comitter:
Swaggie
Date:
Wed Jan 03 16:37:33 2018 +0000
Parent:
5:bea93c8e50b7
Child:
7:bf9f92ff02e8
Commit message:
Worked on Sampling files

Changed in this revision

Sampling.cpp Show annotated file Show diff for this revision Revisions of this file
Sampling.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Sampling.cpp	Tue Jan 02 13:29:00 2018 +0000
+++ b/Sampling.cpp	Wed Jan 03 16:37:33 2018 +0000
@@ -1,13 +1,42 @@
 #include "Sampling.h"
 #include "mbed.h"
 
+//Thread Sync Tools
+Mutex tempReadingsLock;
+Mutex presReadingsLock;
+Mutex LDRReadingsLock;
+
+//Buffers
+float tempReadings[BUFFERSIZE];
+float presReadings[BUFFERSIZE];
+float LDRReadings[BUFFERSIZE];
+
+unsigned short newestTempIndex = BUFFERSIZE-1;
+unsigned short oldestTempIndex = BUFFERSIZE-1;
+
+bool NewEnvSample = false;  //Is there new data from the envirom sensor to output?
+bool NewLDRSample = false;  //Is there new data from the LDR to output?
+
 void SampleTimerISR(void)
 {
     //Flag Threads
 }
     
-
 void ConfigThreadsAndIR(void)
 {
-   
-}
\ No newline at end of file
+   sampleRate.attach(SampleTimerISR, 15); //15 second interval
+}
+
+void AddPresSample(float* Pres)
+{
+   tempReadingsLock.lock(); //Take the key
+   tempReadings[newestTempIndex+1] = Pres; //Add the sample after the most recet
+   tempReadingsLock.unlock(); // Release the key
+}
+
+void threadSampleEnvSensor(void)
+{
+    //Get readings
+    //float temp =
+    //float pres = 
+    AddPresSample(pres);
\ No newline at end of file
--- a/Sampling.h	Tue Jan 02 13:29:00 2018 +0000
+++ b/Sampling.h	Wed Jan 03 16:37:33 2018 +0000
@@ -1,25 +1,71 @@
 #ifndef __Sampling__
 #define __Sampling__
 
+#include "mbed.h"
+
 #ifdef BME
 #include "BME280.h"
 #else
 #include "BMP280.h"
 #endif
 
+#define BUFFERSIZE 120
+
 #ifdef BME
 extern BME280 sensor;
 #else
 extern BMP280 sensor;
 #endif
 
+//Thread Sync Tools
+Mutex tempReadingsLock;
+Mutex presReadingsLock;
+Mutex LDRReadingsLock;
+
+//Buffers
+float tempReadings[BUFFERSIZE];
+float presReadings[BUFFERSIZE];
+float LDRReadings[BUFFERSIZE];
+
+unsigned short newestTempIndex;
+//Position in the buffer of the newest sample
+unsigned short oldestTempIndex;
+//Position in the buffer of the oldest sample
+
+Thread t1; //Sample Enviromental Sensor
+Thread t2; //Sample LDR Sensor
+
+Ticker sampleRate;
+AnalogIn LDR(A13);  //LDR Pin
+
+/*These can be deleted I think
+extern float fLatestTemp;
+extern float fLatestLDR;
+extern float fLatestPres;
+*/
+
+extern bool NewEnvSample;  //Is there new data from the envirom sensor to output?
+extern bool NewLDRSample;  //Is there new data from the LDR to output?
+
 void SampleTimerISR(void);
 //Called by ticker. Calls the sample funcs of each device by flagging the threads
 
 void ConfigThreadsAndIR(void);
 //Setup Interrupts and Threads
 
-void InitiateHW(void);
-//
+void threadSampleEnvSensor(void);
+//when flagged by interrupt will capture a sample then calls the addtobufferfuncs
+
+void AddTempSample(float* Temp);
+//Producer function
+
+void AddPresSample(float* Pres);
+//Producer Function
+
+void ThreadSampleLDR(void);
+//When flagged by interrupt will read LDR value.
+
+void AddLDRSample(float* LDR);
+//Poducer Function
 
 #endif
\ No newline at end of file
--- a/main.cpp	Tue Jan 02 13:29:00 2018 +0000
+++ b/main.cpp	Wed Jan 03 16:37:33 2018 +0000
@@ -6,6 +6,8 @@
 #include "SDBlockDevice.h"
 #include "FATFileSystem.h"
 
+
+
 //SD Card Object
 SDBlockDevice sd(D11, D12, D13, D10); // mosi, miso, sclk, cs
 //File pointer for the SD card
@@ -20,4 +22,18 @@
     //Hardware Self Test
     
     //Initilaiase interrupts and times
+    ConfigThreadsAndIR();
+    
+    //Run
+    while (1)
+    {
+        if (NewEnvSample && NewLDRSample)
+        {
+            //If new samples have been captured, update history and LCD
+            //LCD Update Function
+            //Write values to history
+            NewEnvSample = false;
+            NewLDRSample = false;
+        }
+    }   
 }