fuck this
Dependencies: BMP280
Diff: Sampling.cpp
- Revision:
- 8:dbb57b4d5ba4
- Parent:
- 7:bf9f92ff02e8
- Child:
- 9:ac5673cca703
diff -r bf9f92ff02e8 -r dbb57b4d5ba4 Sampling.cpp --- a/Sampling.cpp Thu Jan 04 17:34:57 2018 +0000 +++ b/Sampling.cpp Thu Jan 04 19:32:30 2018 +0000 @@ -1,17 +1,6 @@ #include "Sampling.h" #include "mbed.h" - -//Thread Sync Tools -Mutex tempReadingsLock; -Mutex presReadingsLock; -Mutex LDRReadingsLock; -Mutex timeReadingsLock; - -//Buffers -float tempReadings[BUFFERSIZE]; -float presReadings[BUFFERSIZE]; -float LDRReadings[BUFFERSIZE]; -float timeReadings[BUFFERSIZE]; +#include "rtos.h" //Index unsigned short newestIndex = BUFFERSIZE-1; @@ -20,18 +9,17 @@ bool firstSample = true; //Hardware -#ifdef BME -BME280 sensor(D14, D15); -#else BMP280 sensor(D14, D15); -#endif -AnalogIn LDRSensor(PA_1); //Check this is the correct pin +AnalogIn LDRSensor(PA_0); +DigitalOut SamplingLED(LED1); void SampleTimerISR(void) { //Flag Threads t1.signal_set(1); t2.signal_set(1); + SamplingLED = 1; + SampleLEDTimeout.attach(&FlipSamplingLED,1); //To turn LED off } void ConfigThreadsAndIR(void) @@ -39,10 +27,10 @@ NewEnvSample = false; //Reset NewLDRSample = false; //Reset - t1.start(ThreadSampleEnvSensor); - t2.start(ThreadSampleLDR); + t1.start(&ThreadSampleEnvSensor); + t2.start(&ThreadSampleLDR); - sampleRate.attach(SampleTimerISR, 15); //15 second interval + sampleRate.attach(&SampleTimerISR, 15); //15 second interval } void AddTempSample(float temp) @@ -56,7 +44,7 @@ { presReadingsLock.lock(); //Take the key presReadings[newestIndex+1] = pres; //Add to register - presReadingsLock.unclock(); //Release the key + presReadingsLock.unlock(); //Release the key } void ThreadSampleEnvSensor(void) @@ -75,7 +63,7 @@ void AddLDRSample(float LDRval) { LDRReadingsLock.lock(); //Take the key - LDRReadings[newestIndex+1] = LDR; //Add the sample after the most recent + LDRReadings[newestIndex+1] = LDRval; //Add the sample after the most recent LDRReadingsLock.unlock(); // Release the key } @@ -84,7 +72,7 @@ while (true) { Thread::signal_wait(1); //Wait for signal 1 //get readings - float LDRval = LDRSensor.value(); //Read the analogue pin value + float LDRval = LDRSensor; //Read the analogue pin value //get time function AddLDRSample(LDRval); //add time sample @@ -106,3 +94,8 @@ } } } + +void FlipSamplingLED(void) +{ + SamplingLED = 0; +}