fuck this
Dependencies: BMP280
Sampling.h@9:ac5673cca703, 2018-01-06 (annotated)
- Committer:
- mwthewsey
- Date:
- Sat Jan 06 16:13:37 2018 +0000
- Revision:
- 9:ac5673cca703
- Parent:
- 8:dbb57b4d5ba4
- Child:
- 10:261f2b69c4c7
- Child:
- 15:e61297f9bae9
Circular buffer working
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Swaggie | 4:2e6d9492b76d | 1 | #ifndef __Sampling__ |
Swaggie | 4:2e6d9492b76d | 2 | #define __Sampling__ |
Swaggie | 4:2e6d9492b76d | 3 | |
Swaggie | 6:8e1795a5886b | 4 | #include "mbed.h" |
Swaggie | 5:bea93c8e50b7 | 5 | #include "BMP280.h" |
Swaggie | 8:dbb57b4d5ba4 | 6 | #include "rtos.h" |
Swaggie | 5:bea93c8e50b7 | 7 | |
mwthewsey | 9:ac5673cca703 | 8 | #define BUFFERSIZE 8 |
Swaggie | 6:8e1795a5886b | 9 | |
Swaggie | 7:bf9f92ff02e8 | 10 | |
Swaggie | 6:8e1795a5886b | 11 | //Thread Sync Tools |
mwthewsey | 9:ac5673cca703 | 12 | extern Mutex tempReadingsLock; |
mwthewsey | 9:ac5673cca703 | 13 | extern Mutex presReadingsLock; |
mwthewsey | 9:ac5673cca703 | 14 | extern Mutex LDRReadingsLock; |
mwthewsey | 9:ac5673cca703 | 15 | extern Mutex timeReadingsLock; |
Swaggie | 6:8e1795a5886b | 16 | |
Swaggie | 6:8e1795a5886b | 17 | //Buffers |
mwthewsey | 9:ac5673cca703 | 18 | extern float tempReadings[BUFFERSIZE]; |
mwthewsey | 9:ac5673cca703 | 19 | extern float presReadings[BUFFERSIZE]; |
mwthewsey | 9:ac5673cca703 | 20 | extern float LDRReadings[BUFFERSIZE]; |
mwthewsey | 9:ac5673cca703 | 21 | extern float timeReadings[BUFFERSIZE]; |
Swaggie | 6:8e1795a5886b | 22 | |
mwthewsey | 9:ac5673cca703 | 23 | extern unsigned short currentIndex; |
Swaggie | 6:8e1795a5886b | 24 | //Position in the buffer of the newest sample |
mwthewsey | 9:ac5673cca703 | 25 | extern unsigned short nextIndex; |
mwthewsey | 9:ac5673cca703 | 26 | //Position in the buffer where the next sample needs to be writen to |
Swaggie | 8:dbb57b4d5ba4 | 27 | extern unsigned short oldestIndex; |
Swaggie | 6:8e1795a5886b | 28 | //Position in the buffer of the oldest sample |
Swaggie | 6:8e1795a5886b | 29 | |
Swaggie | 8:dbb57b4d5ba4 | 30 | extern bool firstSample; |
Swaggie | 7:bf9f92ff02e8 | 31 | //Used to indicate this is the first sample to be taken. used in IncrementIndex func |
Swaggie | 7:bf9f92ff02e8 | 32 | |
mwthewsey | 9:ac5673cca703 | 33 | extern Thread t1; //Sample Enviromental Sensor |
mwthewsey | 9:ac5673cca703 | 34 | extern Thread t2; //Sample LDR Sensor |
Swaggie | 6:8e1795a5886b | 35 | |
mwthewsey | 9:ac5673cca703 | 36 | extern Ticker sampleRate; |
mwthewsey | 9:ac5673cca703 | 37 | extern Timeout SampleLEDTimeout; |
Swaggie | 8:dbb57b4d5ba4 | 38 | extern BMP280 sensor; |
Swaggie | 8:dbb57b4d5ba4 | 39 | extern AnalogIn LDRSensor; //Input pin for LDR |
Swaggie | 8:dbb57b4d5ba4 | 40 | extern DigitalOut SamplingLED; //Onboard LED showing when a sample happens |
Swaggie | 6:8e1795a5886b | 41 | |
Swaggie | 6:8e1795a5886b | 42 | /*These can be deleted I think |
Swaggie | 6:8e1795a5886b | 43 | extern float fLatestTemp; |
Swaggie | 6:8e1795a5886b | 44 | extern float fLatestLDR; |
Swaggie | 6:8e1795a5886b | 45 | extern float fLatestPres; |
Swaggie | 6:8e1795a5886b | 46 | */ |
Swaggie | 6:8e1795a5886b | 47 | |
mwthewsey | 9:ac5673cca703 | 48 | extern bool NewEnvSample; //Is there new data from the envirom sensor to output? |
mwthewsey | 9:ac5673cca703 | 49 | extern bool NewLDRSample; //Is there new data from the LDR to output? |
Swaggie | 6:8e1795a5886b | 50 | |
Swaggie | 4:2e6d9492b76d | 51 | void SampleTimerISR(void); |
Swaggie | 4:2e6d9492b76d | 52 | //Called by ticker. Calls the sample funcs of each device by flagging the threads |
Swaggie | 4:2e6d9492b76d | 53 | |
Swaggie | 4:2e6d9492b76d | 54 | void ConfigThreadsAndIR(void); |
Swaggie | 4:2e6d9492b76d | 55 | //Setup Interrupts and Threads |
Swaggie | 4:2e6d9492b76d | 56 | |
Swaggie | 7:bf9f92ff02e8 | 57 | void ThreadSampleEnvSensor(void); |
Swaggie | 6:8e1795a5886b | 58 | //when flagged by interrupt will capture a sample then calls the addtobufferfuncs |
Swaggie | 6:8e1795a5886b | 59 | |
Swaggie | 7:bf9f92ff02e8 | 60 | void AddTempSample(float temp); |
Swaggie | 6:8e1795a5886b | 61 | //Producer function |
Swaggie | 6:8e1795a5886b | 62 | |
Swaggie | 7:bf9f92ff02e8 | 63 | void AddPresSample(float pres); |
Swaggie | 6:8e1795a5886b | 64 | //Producer Function |
Swaggie | 6:8e1795a5886b | 65 | |
Swaggie | 6:8e1795a5886b | 66 | void ThreadSampleLDR(void); |
Swaggie | 7:bf9f92ff02e8 | 67 | //When flagged by interrupt will read time and LDR value. |
Swaggie | 6:8e1795a5886b | 68 | |
Swaggie | 7:bf9f92ff02e8 | 69 | void AddLDRSample(float LDR); |
Swaggie | 6:8e1795a5886b | 70 | //Poducer Function |
Swaggie | 4:2e6d9492b76d | 71 | |
Swaggie | 7:bf9f92ff02e8 | 72 | void AddTimeSample(/*Whatever time*/); |
Swaggie | 7:bf9f92ff02e8 | 73 | //Producer Function |
Swaggie | 7:bf9f92ff02e8 | 74 | |
Swaggie | 7:bf9f92ff02e8 | 75 | void IncrementIndex(void); |
Swaggie | 7:bf9f92ff02e8 | 76 | //Called after samples are added. Increments the index and moves the oldest |
Swaggie | 7:bf9f92ff02e8 | 77 | //along if necessary |
Swaggie | 7:bf9f92ff02e8 | 78 | |
Swaggie | 8:dbb57b4d5ba4 | 79 | void FlipSamplingLED(void); |
Swaggie | 8:dbb57b4d5ba4 | 80 | //Called by timeout, turns of LED |
Swaggie | 8:dbb57b4d5ba4 | 81 | |
mwthewsey | 9:ac5673cca703 | 82 | unsigned short IndexIncrement(unsigned short thisIndex); |
mwthewsey | 9:ac5673cca703 | 83 | //Incrementing the index with respect for the buffersize |
mwthewsey | 9:ac5673cca703 | 84 | |
Swaggie | 4:2e6d9492b76d | 85 | #endif |