Pacemaker code Implementation for SFWRENG 3K04
Dependencies: mbed Queue mbed-rtos FXOS8700Q
Fork of Pacemaker by
SWFRENG 3K04 Project to design, develop, and document a functional pacemaker.
The project uses the Freescale K64F Microcontroller and C++ mbed library.
sense.cpp@36:b6431cd8ecd6, 2016-12-18 (annotated)
- Committer:
- noahzwiep
- Date:
- Sun Dec 18 02:29:59 2016 +0000
- Revision:
- 36:b6431cd8ecd6
- Parent:
- 34:701503855d52
All ogre.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
trane3 | 5:253c33930e91 | 1 | #pragma once |
trane3 | 5:253c33930e91 | 2 | #include "mbed.h" |
trane3 | 5:253c33930e91 | 3 | #include "sense.h" |
noahzwiep | 34:701503855d52 | 4 | #include "VVI.h" |
trane3 | 5:253c33930e91 | 5 | |
noahzwiep | 36:b6431cd8ecd6 | 6 | sense::sense(genData* a): mySense(PTB2){ |
noahzwiep | 34:701503855d52 | 7 | myGenData = a; |
noahzwiep | 34:701503855d52 | 8 | isSensed = false; |
trane3 | 5:253c33930e91 | 9 | } |
trane3 | 5:253c33930e91 | 10 | |
noahzwiep | 34:701503855d52 | 11 | sense::~sense(){}; |
noahzwiep | 34:701503855d52 | 12 | |
noahzwiep | 34:701503855d52 | 13 | bool sense::returnedSense(){ |
noahzwiep | 34:701503855d52 | 14 | timeout = false; |
noahzwiep | 36:b6431cd8ecd6 | 15 | isSensed = false; |
noahzwiep | 34:701503855d52 | 16 | mbed::Timer t; |
noahzwiep | 34:701503855d52 | 17 | t.start(); |
noahzwiep | 34:701503855d52 | 18 | while(!timeout){ |
noahzwiep | 34:701503855d52 | 19 | //Here we check if we should still be sensing or if we should give up |
noahzwiep | 34:701503855d52 | 20 | if(myGenData->getHyst()){ //This is the case where hysteresis is enabled, we wait the lrl plus hysteresis |
noahzwiep | 34:701503855d52 | 21 | if(t.read_ms() >= (myGenData->getLRL()+myGenData->getHystRL())){ |
noahzwiep | 34:701503855d52 | 22 | timeout = true; |
noahzwiep | 34:701503855d52 | 23 | } |
noahzwiep | 34:701503855d52 | 24 | } |
noahzwiep | 34:701503855d52 | 25 | else{ //Here hysteresis isn't enabled, so its just waiting the LRL. |
noahzwiep | 34:701503855d52 | 26 | if(t.read_ms() >= myGenData->getLRL()){ |
noahzwiep | 34:701503855d52 | 27 | timeout = true; |
noahzwiep | 34:701503855d52 | 28 | } |
noahzwiep | 34:701503855d52 | 29 | } |
noahzwiep | 34:701503855d52 | 30 | //Here we have to check the pin and see if it is above threshold. |
noahzwiep | 36:b6431cd8ecd6 | 31 | if(mySense.read() > 0.995){ |
noahzwiep | 34:701503855d52 | 32 | isSensed = true; |
noahzwiep | 34:701503855d52 | 33 | timeout = true; |
noahzwiep | 36:b6431cd8ecd6 | 34 | } |
noahzwiep | 34:701503855d52 | 35 | } |
noahzwiep | 34:701503855d52 | 36 | t.stop(); |
noahzwiep | 34:701503855d52 | 37 | return isSensed; |
noahzwiep | 34:701503855d52 | 38 | } |
noahzwiep | 34:701503855d52 | 39 | |
noahzwiep | 34:701503855d52 | 40 |