fuck this

Dependencies:   BMP280

Sampling.h

Committer:
Swaggie
Date:
2018-01-04
Revision:
7:bf9f92ff02e8
Parent:
6:8e1795a5886b
Child:
8:dbb57b4d5ba4

File content as of revision 7:bf9f92ff02e8:

#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

AnalogIn LDRSensor; //Input pin for LDR

//Thread Sync Tools
Mutex tempReadingsLock;
Mutex presReadingsLock;
Mutex LDRReadingsLock;
Mutex timeReadingsLock;

//Buffers
float tempReadings[BUFFERSIZE];
float presReadings[BUFFERSIZE];
float LDRReadings[BUFFERSIZE];
float timeReadings[BUFFERSIZE];

unsigned short newestIndex;
//Position in the buffer of the newest sample
unsigned short oldestIndex;
//Position in the buffer of the oldest sample

bool firstSample;
//Used to indicate this is the first sample to be taken. used in IncrementIndex func

Thread t1; //Sample Enviromental Sensor
Thread t2; //Sample LDR Sensor

Ticker sampleRate;
AnalogIn LDR(A13);  //LDR Pin
DigitalOut SamplingLED(LED1); //Onboard LED showing when a sample happens

/*These can be deleted I think
extern float fLatestTemp;
extern float fLatestLDR;
extern float fLatestPres;
*/

bool NewEnvSample;  //Is there new data from the envirom sensor to output?
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 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 time and LDR value.

void AddLDRSample(float LDR);
//Poducer Function

void AddTimeSample(/*Whatever time*/);
//Producer Function

void IncrementIndex(void);
//Called after samples are added. Increments the index and moves the oldest
//along if necessary

#endif