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.
interface.cpp@34:701503855d52, 2016-12-13 (annotated)
- Committer:
- noahzwiep
- Date:
- Tue Dec 13 03:46:34 2016 +0000
- Revision:
- 34:701503855d52
- Parent:
- 32:69cd1390bc21
- Child:
- 35:fa164704f0ca
Added sense module, only thing left is figuring out pins
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noahzwiep | 25:d816de7067da | 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" |
noahzwiep | 16:08d5e5a3ee74 | 9 | #include "rtos.h" |
noahzwiep | 25:d816de7067da | 10 | #include "queue.h" |
FiveDollar | 0:b2b3955cd77b | 11 | #include <stdlib.h> |
FiveDollar | 0:b2b3955cd77b | 12 | #include <stdio.h> |
FiveDollar | 0:b2b3955cd77b | 13 | #include <string> |
FiveDollar | 0:b2b3955cd77b | 14 | |
FiveDollar | 0:b2b3955cd77b | 15 | //CONSTRUCTORS***************************** |
noahzwiep | 32:69cd1390bc21 | 16 | interface::interface():rled(LED_BLUE){ |
FiveDollar | 0:b2b3955cd77b | 17 | } |
FiveDollar | 0:b2b3955cd77b | 18 | |
noahzwiep | 32:69cd1390bc21 | 19 | interface::~interface(){ |
noahzwiep | 32:69cd1390bc21 | 20 | delete myDataStruct; |
noahzwiep | 32:69cd1390bc21 | 21 | } |
trane3 | 7:4eb590c7e064 | 22 | |
noahzwiep | 32:69cd1390bc21 | 23 | interface::interface(Serial* inputPC):rled(LED_BLUE){ |
FiveDollar | 0:b2b3955cd77b | 24 | pc = inputPC; |
FiveDollar | 0:b2b3955cd77b | 25 | } |
FiveDollar | 0:b2b3955cd77b | 26 | |
noahzwiep | 32:69cd1390bc21 | 27 | interface::interface(Serial* inputPC , pulse* p ,genData* genData, chamberData* atrium , chamberData* ventricle, hardware* hardw):rled(LED_BLUE){ |
noahzwiep | 32:69cd1390bc21 | 28 | rled = 1; |
noahzwiep | 32:69cd1390bc21 | 29 | isEgram = true; |
FiveDollar | 9:b48423a135d8 | 30 | generalData = genData; |
FiveDollar | 0:b2b3955cd77b | 31 | pc = inputPC; |
FiveDollar | 0:b2b3955cd77b | 32 | interfacePulse = p; |
FiveDollar | 0:b2b3955cd77b | 33 | atrData = atrium; |
noahzwiep | 25:d816de7067da | 34 | ventData = ventricle; |
noahzwiep | 32:69cd1390bc21 | 35 | myHardware = hardw; |
noahzwiep | 32:69cd1390bc21 | 36 | myDataStruct = new dataStruct(myHardware); |
FiveDollar | 0:b2b3955cd77b | 37 | } |
FiveDollar | 0:b2b3955cd77b | 38 | //******************************************** |
FiveDollar | 0:b2b3955cd77b | 39 | |
FiveDollar | 0:b2b3955cd77b | 40 | |
FiveDollar | 0:b2b3955cd77b | 41 | //USER INTERFACE SCREENS************************** |
FiveDollar | 0:b2b3955cd77b | 42 | |
noahzwiep | 32:69cd1390bc21 | 43 | void interface:: readValues(){ |
noahzwiep | 32:69cd1390bc21 | 44 | bool keepStreaming = true; |
noahzwiep | 32:69cd1390bc21 | 45 | while(keepStreaming){ |
noahzwiep | 32:69cd1390bc21 | 46 | isEgram = true; |
noahzwiep | 32:69cd1390bc21 | 47 | if(pc->readable()){ |
noahzwiep | 32:69cd1390bc21 | 48 | command = pc->getc(); |
noahzwiep | 32:69cd1390bc21 | 49 | switch (command){ |
noahzwiep | 32:69cd1390bc21 | 50 | case 0x1:{ |
noahzwiep | 32:69cd1390bc21 | 51 | rled = !rled; |
noahzwiep | 32:69cd1390bc21 | 52 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 53 | generalData->chngAVdelayOffset(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 54 | break; |
noahzwiep | 32:69cd1390bc21 | 55 | } |
noahzwiep | 32:69cd1390bc21 | 56 | case 0x2:{ |
noahzwiep | 32:69cd1390bc21 | 57 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 58 | generalData->chngLRL(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 59 | break; |
noahzwiep | 32:69cd1390bc21 | 60 | } |
noahzwiep | 32:69cd1390bc21 | 61 | case 0x3:{ |
noahzwiep | 32:69cd1390bc21 | 62 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 63 | generalData->chngURL(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 64 | break; |
noahzwiep | 32:69cd1390bc21 | 65 | } |
noahzwiep | 32:69cd1390bc21 | 66 | case 0x4:{ |
noahzwiep | 32:69cd1390bc21 | 67 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 68 | generalData->chngAVdelay(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 69 | break; |
noahzwiep | 32:69cd1390bc21 | 70 | } |
noahzwiep | 32:69cd1390bc21 | 71 | case 0x5:{ |
noahzwiep | 32:69cd1390bc21 | 72 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 73 | generalData->chngAVdelayOffset(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 74 | break; |
noahzwiep | 32:69cd1390bc21 | 75 | } |
noahzwiep | 32:69cd1390bc21 | 76 | case 0x6:{ |
noahzwiep | 32:69cd1390bc21 | 77 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 78 | generalData->chngRSmooth(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 79 | break; |
noahzwiep | 32:69cd1390bc21 | 80 | } |
noahzwiep | 32:69cd1390bc21 | 81 | case 0x7:{ |
noahzwiep | 32:69cd1390bc21 | 82 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 83 | atrData->chngPaceAmp(atof(value)/10); |
noahzwiep | 32:69cd1390bc21 | 84 | break; |
noahzwiep | 32:69cd1390bc21 | 85 | } |
noahzwiep | 32:69cd1390bc21 | 86 | case 0x8:{ |
noahzwiep | 32:69cd1390bc21 | 87 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 88 | atrData->chngRP(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 89 | break; |
noahzwiep | 32:69cd1390bc21 | 90 | } |
noahzwiep | 32:69cd1390bc21 | 91 | case 0x9:{ |
noahzwiep | 32:69cd1390bc21 | 92 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 93 | atrData->chngPaceWidth(atof(value)/100); |
noahzwiep | 32:69cd1390bc21 | 94 | break; |
noahzwiep | 32:69cd1390bc21 | 95 | } |
noahzwiep | 32:69cd1390bc21 | 96 | case 0xA:{ |
noahzwiep | 32:69cd1390bc21 | 97 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 98 | atrData->chngSensitivity(atof(value)/100); |
noahzwiep | 34:701503855d52 | 99 | double pw = atrData->getSensitivity(); |
noahzwiep | 34:701503855d52 | 100 | if(pw < 0.5){ |
noahzwiep | 34:701503855d52 | 101 | rled = !rled; |
noahzwiep | 34:701503855d52 | 102 | } |
noahzwiep | 32:69cd1390bc21 | 103 | break; |
noahzwiep | 32:69cd1390bc21 | 104 | } |
noahzwiep | 32:69cd1390bc21 | 105 | case 0xB:{ |
noahzwiep | 32:69cd1390bc21 | 106 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 107 | atrData->chngPaceAmp(atof(value)/10); |
noahzwiep | 32:69cd1390bc21 | 108 | break; |
noahzwiep | 32:69cd1390bc21 | 109 | } |
noahzwiep | 32:69cd1390bc21 | 110 | case 0xC:{ |
noahzwiep | 32:69cd1390bc21 | 111 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 112 | ventData->chngPaceWidth(atof(value)/10); |
noahzwiep | 32:69cd1390bc21 | 113 | break; |
noahzwiep | 32:69cd1390bc21 | 114 | } |
noahzwiep | 32:69cd1390bc21 | 115 | case 0xD:{ |
noahzwiep | 32:69cd1390bc21 | 116 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 117 | ventData->chngRP(atof(value)); |
noahzwiep | 32:69cd1390bc21 | 118 | break; |
noahzwiep | 32:69cd1390bc21 | 119 | } |
noahzwiep | 32:69cd1390bc21 | 120 | case 0xE:{ |
noahzwiep | 32:69cd1390bc21 | 121 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 122 | ventData->chngSensitivity(atof(value)/10); |
noahzwiep | 32:69cd1390bc21 | 123 | break; |
noahzwiep | 32:69cd1390bc21 | 124 | } |
noahzwiep | 32:69cd1390bc21 | 125 | case 0xF:{ |
noahzwiep | 32:69cd1390bc21 | 126 | /* value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 127 | if(genData->getMode() == value){ |
noahzwiep | 32:69cd1390bc21 | 128 | break; |
noahzwiep | 32:69cd1390bc21 | 129 | } |
noahzwiep | 32:69cd1390bc21 | 130 | if(value == "VOOR"){ |
noahzwiep | 32:69cd1390bc21 | 131 | break; |
noahzwiep | 32:69cd1390bc21 | 132 | } |
noahzwiep | 32:69cd1390bc21 | 133 | else if(value == "VVI"){ |
noahzwiep | 32:69cd1390bc21 | 134 | break; |
noahzwiep | 32:69cd1390bc21 | 135 | }*/ |
noahzwiep | 32:69cd1390bc21 | 136 | } |
noahzwiep | 32:69cd1390bc21 | 137 | case 0x7a:{ |
noahzwiep | 32:69cd1390bc21 | 138 | while(isEgram){ |
noahzwiep | 32:69cd1390bc21 | 139 | if(pc->readable()){ |
noahzwiep | 32:69cd1390bc21 | 140 | char command = pc->getc(); |
noahzwiep | 32:69cd1390bc21 | 141 | if(command == 0x8a){ |
noahzwiep | 32:69cd1390bc21 | 142 | isEgram = false; |
noahzwiep | 32:69cd1390bc21 | 143 | } |
noahzwiep | 32:69cd1390bc21 | 144 | } |
noahzwiep | 32:69cd1390bc21 | 145 | double myInt = (myDataStruct->getData()); |
noahzwiep | 32:69cd1390bc21 | 146 | pc->printf("%f\n", myInt); |
noahzwiep | 34:701503855d52 | 147 | //rled = !rled; |
noahzwiep | 32:69cd1390bc21 | 148 | Thread::wait(4); |
noahzwiep | 32:69cd1390bc21 | 149 | } |
noahzwiep | 32:69cd1390bc21 | 150 | break; |
noahzwiep | 32:69cd1390bc21 | 151 | } |
noahzwiep | 32:69cd1390bc21 | 152 | case 0x1E:{ |
noahzwiep | 32:69cd1390bc21 | 153 | value = getInput(); |
noahzwiep | 32:69cd1390bc21 | 154 | if((*value) == '1'){ |
noahzwiep | 32:69cd1390bc21 | 155 | generalData->chngHyst(true); |
noahzwiep | 32:69cd1390bc21 | 156 | break; |
noahzwiep | 32:69cd1390bc21 | 157 | } |
noahzwiep | 32:69cd1390bc21 | 158 | else if((*value)== '0'){ |
noahzwiep | 32:69cd1390bc21 | 159 | generalData->chngHyst(false); |
noahzwiep | 32:69cd1390bc21 | 160 | break; |
noahzwiep | 32:69cd1390bc21 | 161 | } |
noahzwiep | 32:69cd1390bc21 | 162 | } |
noahzwiep | 32:69cd1390bc21 | 163 | } |
trane3 | 8:75c1dd8b0d61 | 164 | } |
noahzwiep | 32:69cd1390bc21 | 165 | } |
trane3 | 19:d58e1e1a9a24 | 166 | } |
trane3 | 19:d58e1e1a9a24 | 167 | |
FiveDollar | 0:b2b3955cd77b | 168 | char* interface::getInput(){ |
FiveDollar | 0:b2b3955cd77b | 169 | char buffer[5]; |
FiveDollar | 0:b2b3955cd77b | 170 | fgets (buffer,5,stdin); |
FiveDollar | 0:b2b3955cd77b | 171 | return buffer; |
FiveDollar | 0:b2b3955cd77b | 172 | } |
FiveDollar | 0:b2b3955cd77b | 173 | |
FiveDollar | 0:b2b3955cd77b | 174 | char interface::getChar(){ |
FiveDollar | 0:b2b3955cd77b | 175 | while(true){ |
FiveDollar | 0:b2b3955cd77b | 176 | if(pc->readable()){ |
FiveDollar | 0:b2b3955cd77b | 177 | char command = pc->getc(); |
FiveDollar | 0:b2b3955cd77b | 178 | return command; |
FiveDollar | 0:b2b3955cd77b | 179 | } |
FiveDollar | 0:b2b3955cd77b | 180 | } |
noahzwiep | 32:69cd1390bc21 | 181 | } |
noahzwiep | 32:69cd1390bc21 | 182 | |
noahzwiep | 32:69cd1390bc21 | 183 | |
noahzwiep | 32:69cd1390bc21 | 184 | |
noahzwiep | 32:69cd1390bc21 | 185 | |
noahzwiep | 32:69cd1390bc21 | 186 | //void interface::startScreen(){ |
noahzwiep | 32:69cd1390bc21 | 187 | // |
noahzwiep | 32:69cd1390bc21 | 188 | // pc->printf("\n ____ _ ____ _____ __ __ _ _ _______ ____ "); |
noahzwiep | 32:69cd1390bc21 | 189 | // pc->printf("\n| _ \\ / \\ / ___| ____| \\/ | / \\ | |/ / ____| _ \\"); |
noahzwiep | 32:69cd1390bc21 | 190 | // pc->printf("\n| |_) / _ \\| | | _| | |\\/| | / _ \\ | ' /| _| | |_) |"); |
noahzwiep | 32:69cd1390bc21 | 191 | // pc->printf("\n| __/ ___ \\ |___| |___| | | |/ ___ \\| . \\| |___| _ <"); |
noahzwiep | 32:69cd1390bc21 | 192 | // pc->printf("\n|_| /_/ \\_\\____|_____|_| |_/_/ \\_\\_|\\_\\_____|_| \\_\\"); |
noahzwiep | 32:69cd1390bc21 | 193 | // |
noahzwiep | 32:69cd1390bc21 | 194 | // |
noahzwiep | 32:69cd1390bc21 | 195 | // pc->printf("\nWelcome to the PACEMAKER DCM.\n"); |
noahzwiep | 32:69cd1390bc21 | 196 | // pc->printf("Options:\n"); |
noahzwiep | 32:69cd1390bc21 | 197 | // pc->printf("1. Start VOOR Pulse\n"); // temporary test to get VOOR working |
noahzwiep | 32:69cd1390bc21 | 198 | // pc->printf("2. View/Change data\n"); |
noahzwiep | 32:69cd1390bc21 | 199 | // pc->printf("Please enter a command:"); |
noahzwiep | 32:69cd1390bc21 | 200 | // char command = getChar(); |
noahzwiep | 32:69cd1390bc21 | 201 | // switch (command) { |
noahzwiep | 32:69cd1390bc21 | 202 | // case '1':{ |
noahzwiep | 32:69cd1390bc21 | 203 | // |
noahzwiep | 32:69cd1390bc21 | 204 | // voor v(interfacePulse, ventData); //creates new instance of voor |
noahzwiep | 32:69cd1390bc21 | 205 | // v.startPace(); //starts pacing voor the same way as it used to pace in the user interface |
noahzwiep | 32:69cd1390bc21 | 206 | // //interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse. |
noahzwiep | 32:69cd1390bc21 | 207 | // startScreen(); //realistically we'll never need to call the serial output in pulse, it should all be done in UI |
noahzwiep | 32:69cd1390bc21 | 208 | // break; |
noahzwiep | 32:69cd1390bc21 | 209 | // } |
noahzwiep | 32:69cd1390bc21 | 210 | // case '2': |
noahzwiep | 32:69cd1390bc21 | 211 | // interface::dataScreen(); |
noahzwiep | 32:69cd1390bc21 | 212 | // break; |
noahzwiep | 32:69cd1390bc21 | 213 | // default: |
noahzwiep | 32:69cd1390bc21 | 214 | // pc->printf("\nThat is not an option.\n"); |
noahzwiep | 32:69cd1390bc21 | 215 | // interface::startScreen(); |
noahzwiep | 32:69cd1390bc21 | 216 | // break; |
noahzwiep | 32:69cd1390bc21 | 217 | // } |
noahzwiep | 32:69cd1390bc21 | 218 | //} |
noahzwiep | 32:69cd1390bc21 | 219 | |
noahzwiep | 32:69cd1390bc21 | 220 | |
FiveDollar | 0:b2b3955cd77b | 221 | //**************************** |
FiveDollar | 0:b2b3955cd77b | 222 | |
FiveDollar | 0:b2b3955cd77b | 223 | //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 | 224 | // pulse myPulse(*atr); |
FiveDollar | 0:b2b3955cd77b | 225 | // myPulse.setWidth(1); |
FiveDollar | 0:b2b3955cd77b | 226 | // myPulse.startPulse(); |
FiveDollar | 0:b2b3955cd77b | 227 | // } |
FiveDollar | 0:b2b3955cd77b | 228 | |
FiveDollar | 0:b2b3955cd77b | 229 | //void interface::LEDon(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 230 | // (*out) = 0; |
FiveDollar | 0:b2b3955cd77b | 231 | //// (*pc).printf(led); |
FiveDollar | 0:b2b3955cd77b | 232 | //} |
FiveDollar | 0:b2b3955cd77b | 233 | // |
FiveDollar | 0:b2b3955cd77b | 234 | //void interface::LEDoff(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 235 | // (*out) = 1; |
FiveDollar | 0:b2b3955cd77b | 236 | //} |