Pacemaker code Implementation for SFWRENG 3K04
Dependencies: FXOS8700Q Queue mbed-rtos mbed
Fork of Pacemaker by
interface.cpp@13:bb80794b6727, 2016-11-15 (annotated)
- Committer:
- FiveDollar
- Date:
- Tue Nov 15 22:17:03 2016 +0000
- Revision:
- 13:bb80794b6727
- Parent:
- 10:0e0130742e87
- Child:
- 15:3b8acee3510d
added print true and false properly (gareth)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
FiveDollar | 0:b2b3955cd77b | 1 | #pragma once |
FiveDollar | 0:b2b3955cd77b | 2 | #include "mbed.h" |
FiveDollar | 0:b2b3955cd77b | 3 | #include "interface.h" |
FiveDollar | 0:b2b3955cd77b | 4 | #include "hardware.h" |
FiveDollar | 0:b2b3955cd77b | 5 | #include "chamberData.h" |
FiveDollar | 0:b2b3955cd77b | 6 | #include "genData.h" |
FiveDollar | 0:b2b3955cd77b | 7 | #include "pulse.h" |
trane3 | 8:75c1dd8b0d61 | 8 | #include "voor.h" |
FiveDollar | 0:b2b3955cd77b | 9 | #include <stdlib.h> |
FiveDollar | 0:b2b3955cd77b | 10 | #include <stdio.h> |
FiveDollar | 0:b2b3955cd77b | 11 | #include <string> |
FiveDollar | 0:b2b3955cd77b | 12 | |
FiveDollar | 0:b2b3955cd77b | 13 | //CONSTRUCTORS***************************** |
FiveDollar | 0:b2b3955cd77b | 14 | interface::interface(){ |
FiveDollar | 0:b2b3955cd77b | 15 | } |
FiveDollar | 0:b2b3955cd77b | 16 | |
trane3 | 7:4eb590c7e064 | 17 | interface::~interface(){}; |
trane3 | 7:4eb590c7e064 | 18 | |
FiveDollar | 0:b2b3955cd77b | 19 | interface::interface(Serial* inputPC){ |
FiveDollar | 0:b2b3955cd77b | 20 | pc = inputPC; |
FiveDollar | 0:b2b3955cd77b | 21 | } |
FiveDollar | 0:b2b3955cd77b | 22 | |
FiveDollar | 9:b48423a135d8 | 23 | interface::interface(Serial* inputPC , pulse* p ,genData* genData, chamberData* atrium , chamberData* ventricle){ |
FiveDollar | 9:b48423a135d8 | 24 | generalData = genData; |
FiveDollar | 0:b2b3955cd77b | 25 | pc = inputPC; |
FiveDollar | 0:b2b3955cd77b | 26 | interfacePulse = p; |
FiveDollar | 0:b2b3955cd77b | 27 | atrData = atrium; |
FiveDollar | 0:b2b3955cd77b | 28 | ventData = ventricle; |
FiveDollar | 0:b2b3955cd77b | 29 | } |
FiveDollar | 0:b2b3955cd77b | 30 | //******************************************** |
FiveDollar | 0:b2b3955cd77b | 31 | |
FiveDollar | 0:b2b3955cd77b | 32 | |
FiveDollar | 0:b2b3955cd77b | 33 | //USER INTERFACE SCREENS************************** |
FiveDollar | 0:b2b3955cd77b | 34 | |
FiveDollar | 0:b2b3955cd77b | 35 | void interface::startScreen(){ |
FiveDollar | 0:b2b3955cd77b | 36 | (*pc).printf("\nWelcome to the PACEMAKER DCM.\n"); |
FiveDollar | 0:b2b3955cd77b | 37 | (*pc).printf("Options:\n"); |
trane3 | 8:75c1dd8b0d61 | 38 | (*pc).printf("1. Start VOOR Pulse\n"); // temporary test to get VOOR working |
FiveDollar | 0:b2b3955cd77b | 39 | (*pc).printf("2. View/Change data\n"); |
FiveDollar | 0:b2b3955cd77b | 40 | (*pc).printf("Please enter a command:"); |
FiveDollar | 0:b2b3955cd77b | 41 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 42 | switch (command) { |
trane3 | 8:75c1dd8b0d61 | 43 | case '1':{ |
trane3 | 8:75c1dd8b0d61 | 44 | voor v(interfacePulse); //creates new instance of voor |
trane3 | 8:75c1dd8b0d61 | 45 | v.startPace(); //starts pacing voor the same way as it used to pace in the user interface |
trane3 | 8:75c1dd8b0d61 | 46 | //interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse. |
FiveDollar | 0:b2b3955cd77b | 47 | startScreen(); //realistically we'll never need to call the serial output in pulse, it should all be done in UI |
FiveDollar | 0:b2b3955cd77b | 48 | break; |
trane3 | 8:75c1dd8b0d61 | 49 | } |
FiveDollar | 0:b2b3955cd77b | 50 | case '2': |
FiveDollar | 0:b2b3955cd77b | 51 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 52 | break; |
FiveDollar | 1:fbba2687ddfe | 53 | default: |
FiveDollar | 1:fbba2687ddfe | 54 | pc->printf("\nThat is not an option."); |
FiveDollar | 1:fbba2687ddfe | 55 | interface::startScreen(); |
FiveDollar | 1:fbba2687ddfe | 56 | break; |
FiveDollar | 1:fbba2687ddfe | 57 | } |
FiveDollar | 0:b2b3955cd77b | 58 | } |
FiveDollar | 0:b2b3955cd77b | 59 | |
FiveDollar | 0:b2b3955cd77b | 60 | void interface::dataScreen(){ |
FiveDollar | 0:b2b3955cd77b | 61 | (*pc).printf("\nDCM Data sets:\n"); |
FiveDollar | 1:fbba2687ddfe | 62 | (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. General Data\n4. Egram Data\n5. Back to start page\n"); |
FiveDollar | 0:b2b3955cd77b | 63 | (*pc).printf("Choose a data set:"); |
FiveDollar | 0:b2b3955cd77b | 64 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 65 | switch (command) { |
FiveDollar | 0:b2b3955cd77b | 66 | case '1': |
FiveDollar | 1:fbba2687ddfe | 67 | pc->printf("\nAtrium Data"); |
FiveDollar | 1:fbba2687ddfe | 68 | pc->printf("\n1. Pace Amplitude: %f", atrData->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 69 | pc->printf("\n2. Pace Width: %f", atrData->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 70 | pc->printf("\n3. Refractory Period: %f", atrData->getRP()); |
FiveDollar | 0:b2b3955cd77b | 71 | pc->printf("\n4. Sensitivity: %f", atrData->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 72 | pc->printf("\nChoose variable to be changed or 5 To return to Data Sets"); |
FiveDollar | 0:b2b3955cd77b | 73 | interface::getData(atrData); |
FiveDollar | 0:b2b3955cd77b | 74 | break; |
FiveDollar | 0:b2b3955cd77b | 75 | case '2': |
FiveDollar | 1:fbba2687ddfe | 76 | pc->printf("\nVentricle Data"); |
FiveDollar | 1:fbba2687ddfe | 77 | pc->printf("\n1. Pace Amplitude: %f", ventData->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 78 | pc->printf("\n2. Pace Width: %f", ventData->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 79 | pc->printf("\n3. Refractory Period: %f", ventData->getRP()); |
FiveDollar | 0:b2b3955cd77b | 80 | pc->printf("\n4. Sensitivity: %f", ventData->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 81 | pc->printf("\nChoose variable to be changed or 5 To return to Data Sets"); |
FiveDollar | 0:b2b3955cd77b | 82 | interface::getData(ventData); |
FiveDollar | 0:b2b3955cd77b | 83 | break; |
FiveDollar | 0:b2b3955cd77b | 84 | case '3': |
FiveDollar | 1:fbba2687ddfe | 85 | pc->printf("\nGeneral Data"); |
FiveDollar | 13:bb80794b6727 | 86 | pc->printf("\n1. Hysteresis: %s", generalData->getHyst() ? "true" : "false"); |
FiveDollar | 9:b48423a135d8 | 87 | pc->printf("\n2. Hysteresis Interval: %f", generalData->getHystInterval()); |
FiveDollar | 9:b48423a135d8 | 88 | pc->printf("\n3. Lower Rate Limit: %f", generalData->getLRL()); |
FiveDollar | 9:b48423a135d8 | 89 | pc->printf("\n4. Upper Rate Limit: %f", generalData->getURL()); |
FiveDollar | 9:b48423a135d8 | 90 | pc->printf("\n5. Atrial-Ventricular Delay: %f", generalData->getAVdelay()); |
FiveDollar | 9:b48423a135d8 | 91 | pc->printf("\n6. Atrial-Ventricular Delay Offset: %f" , generalData->getAVdelayOffset()); |
FiveDollar | 9:b48423a135d8 | 92 | pc->printf("\n7. Rate Smoothing: %f", generalData->getRSmooth()); |
FiveDollar | 1:fbba2687ddfe | 93 | case '4': |
FiveDollar | 1:fbba2687ddfe | 94 | pc->printf("\nNot setup yet"); |
FiveDollar | 0:b2b3955cd77b | 95 | break; |
FiveDollar | 1:fbba2687ddfe | 96 | case '5': |
FiveDollar | 0:b2b3955cd77b | 97 | interface::startScreen(); |
FiveDollar | 0:b2b3955cd77b | 98 | default: |
FiveDollar | 1:fbba2687ddfe | 99 | pc->printf("\nThat is not an option."); |
FiveDollar | 0:b2b3955cd77b | 100 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 101 | } |
FiveDollar | 0:b2b3955cd77b | 102 | } |
FiveDollar | 0:b2b3955cd77b | 103 | |
FiveDollar | 0:b2b3955cd77b | 104 | void interface::getData(chamberData* chamber){ |
FiveDollar | 0:b2b3955cd77b | 105 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 106 | switch (command){ |
FiveDollar | 0:b2b3955cd77b | 107 | case '1': |
FiveDollar | 1:fbba2687ddfe | 108 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 109 | char* value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 110 | chamber->chngPaceAmp(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 111 | pc->printf("\t%f",chamber->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 112 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 113 | break; |
FiveDollar | 0:b2b3955cd77b | 114 | case '2': |
FiveDollar | 1:fbba2687ddfe | 115 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 116 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 117 | chamber->chngPaceWidth(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 118 | pc->printf("\t%f",chamber->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 119 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 120 | break; |
FiveDollar | 0:b2b3955cd77b | 121 | case '3': |
FiveDollar | 1:fbba2687ddfe | 122 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 123 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 124 | chamber->chngRP(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 125 | pc->printf("\t%f",chamber->getRP()); |
FiveDollar | 0:b2b3955cd77b | 126 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 127 | break; |
FiveDollar | 0:b2b3955cd77b | 128 | case '4': |
FiveDollar | 1:fbba2687ddfe | 129 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 130 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 131 | chamber->chngSensitivity(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 132 | pc->printf("\t%f",chamber->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 133 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 134 | break; |
FiveDollar | 0:b2b3955cd77b | 135 | case '5': |
FiveDollar | 0:b2b3955cd77b | 136 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 137 | break; |
FiveDollar | 0:b2b3955cd77b | 138 | default: |
FiveDollar | 0:b2b3955cd77b | 139 | pc->printf("\nThat is not an option."); |
FiveDollar | 0:b2b3955cd77b | 140 | interface::getData(chamber); |
FiveDollar | 0:b2b3955cd77b | 141 | } |
FiveDollar | 0:b2b3955cd77b | 142 | } |
FiveDollar | 0:b2b3955cd77b | 143 | |
FiveDollar | 13:bb80794b6727 | 144 | |
FiveDollar | 13:bb80794b6727 | 145 | |
FiveDollar | 0:b2b3955cd77b | 146 | char* interface::getInput(){ |
FiveDollar | 0:b2b3955cd77b | 147 | char buffer[5]; |
FiveDollar | 0:b2b3955cd77b | 148 | fgets (buffer,5,stdin); |
FiveDollar | 0:b2b3955cd77b | 149 | return buffer; |
FiveDollar | 0:b2b3955cd77b | 150 | } |
FiveDollar | 0:b2b3955cd77b | 151 | |
FiveDollar | 0:b2b3955cd77b | 152 | char interface::getChar(){ |
FiveDollar | 0:b2b3955cd77b | 153 | while(true){ |
FiveDollar | 0:b2b3955cd77b | 154 | if(pc->readable()){ |
FiveDollar | 0:b2b3955cd77b | 155 | char command = pc->getc(); |
FiveDollar | 0:b2b3955cd77b | 156 | return command; |
FiveDollar | 0:b2b3955cd77b | 157 | } |
FiveDollar | 0:b2b3955cd77b | 158 | } |
FiveDollar | 0:b2b3955cd77b | 159 | } |
FiveDollar | 0:b2b3955cd77b | 160 | //**************************** |
FiveDollar | 0:b2b3955cd77b | 161 | |
FiveDollar | 0:b2b3955cd77b | 162 | //void interface::getAPulse(){ //TODO get this to work, the wait command has issues, see pulse.cpp . wait takes in seconds as argument |
FiveDollar | 0:b2b3955cd77b | 163 | // pulse myPulse(*atr); |
FiveDollar | 0:b2b3955cd77b | 164 | // myPulse.setWidth(1); |
FiveDollar | 0:b2b3955cd77b | 165 | // myPulse.startPulse(); |
FiveDollar | 0:b2b3955cd77b | 166 | // } |
FiveDollar | 0:b2b3955cd77b | 167 | |
FiveDollar | 0:b2b3955cd77b | 168 | //void interface::LEDon(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 169 | // (*out) = 0; |
FiveDollar | 0:b2b3955cd77b | 170 | //// (*pc).printf(led); |
FiveDollar | 0:b2b3955cd77b | 171 | //} |
FiveDollar | 0:b2b3955cd77b | 172 | // |
FiveDollar | 0:b2b3955cd77b | 173 | //void interface::LEDoff(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 174 | // (*out) = 1; |
FiveDollar | 0:b2b3955cd77b | 175 | //} |