hack gt final code
Dependencies: 4DGL-uLCD-SE BMP085 PinDetect SDFileSystem mbed wave_player
Revision 2:a111a0137d95, committed 2014-09-20
- Comitter:
- otis22894
- Date:
- Sat Sep 20 06:00:39 2014 +0000
- Parent:
- 1:15fa67e32958
- Child:
- 3:14195e423d13
- Commit message:
- TIME: 2:00AM
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Sep 20 04:23:20 2014 +0000 +++ b/main.cpp Sat Sep 20 06:00:39 2014 +0000 @@ -3,18 +3,62 @@ #include "SDFileSystem.h" #include "wave_player.h" #include "uLCD_4DGL.h" +#include <string> +#include <sstream> + +using namespace std; SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card AnalogOut DACout(p18); wave_player waver(&DACout); uLCD_4DGL uLCD(p28, p27, p29); -AnalogIn ain(p17); -float data; +I2C i2c(p9, p10); +const int address = 0x77 << 1; +bool breathing; +bool pulse; +bool breath_success = true; +ostringstream stream; + +int getSensorData(); +void playMessage(string messageName); +void getBreathing(); +void getPulse(); +void getVitals(); +bool checkBreath(); +void promptBreaths(int amt); +void chestCompressions(); +void CPR(); +void rescueBreathing(); +void auditVitals(); +void unconsciousChocking(); -// sda pin followed by the scl pin -I2C i2c(p9, p10); - -const int address = 0x77 << 1; +int main(){ + playMessage("Place mask on face"); + playMessage("Clip sensor to ear"); + playMessage("Tilt Head"); + getVitals(); + + if(pulse&&breathing){ + playMessage("Roll victim to side"); + while(1){ + playMessage("Monitor Condition, return mask if breathing stops"); + wait(5); + } + } + + promptBreaths(2); + if(breath_success){ + auditVitals(); + }else{ + playMessage("Retilt Head"); + promptBreaths(1); + if(breath_success){ + auditVitals(); + }else{ + unconsciousChocking(); + } + } +} int getSensorData() { i2c.start(); @@ -33,21 +77,101 @@ } } +void playMessage(string messageName){ + messageName = "/sd/" + messageName; + char * cstrName = new char[messageName.length() + 1]; + FILE *wave_file; + wave_file=fopen(cstrName,"r"); + waver.play(wave_file); + fclose(wave_file); +} +void getBreathing(){ + //SENSOR DATA + breathing = false; +} + +void getPulse(){ + //SENSOR DATA + pulse = false; +} + +void getVitals(){ + getBreathing(); + getPulse(); +} -int main() -{ +bool checkBreath(){ + //SENSOR DATA + return false; +} + +void promptBreaths(int amt){ + bool local_check;; + for(int i = 0;i<amt;i++){ + playMessage("Prepare to breathe"); + wait(1); + playMessage("Breathe"); + local_check = checkBreath(); + breath_success = breath_success & local_check; + } +} + +void chestCompressions(){ + playMessage("Prepare for chest compressions"); + playMessage("Begin chest compressions"); + for(int i=1;i<31;i++){ + const int i = 3; + stream << i; + playMessage(stream.str()); + wait(0.5); + } + playMessage("Stop Chest Compressions"); +} + +void CPR(){ while(1){ - uLCD.cls(); - data = ain; - uLCD.printf("Sensor: %d",getSensorData()); - wait(0.1); + chestCompressions(); + } +} + +void rescueBreathing(){ + Timer timer; + while(pulse){ + timer.start(); + while(timer.read()<120){ + playMessage("Prepare to breathe"); + playMessage("Breate"); + wait(3); //Need 5s total loop time + } + timer.stop(); + timer.reset(); + playMessage("Tilt head"); + getVitals(); } - //changes - //changes - /*FILE *wave_file; - printf("\n\n\nHello, wave world!\n"); - wave_file=fopen("/sd/A Team.wav","r"); - waver.play(wave_file); - fclose(wave_file);*/ + CPR(); +} + +void auditVitals(){ + if(pulse && !breathing){ + rescueBreathing(); + }else if(!pulse && !breathing){ + CPR(); + }else{//ERROR} + } +} + +void unconsciousChocking(){ + bool stillChocking = true; + while(stillChocking){ + chestCompressions(); + playMessage("Check airway and replace mask"); + promptBreaths(2); + if(breath_success){ + stillChocking = false; + } + } + playMessage("Tilt head"); + getVitals(); + auditVitals(); } \ No newline at end of file