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