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@2:fbba2687ddfe, 2016-11-14 (annotated)
- Committer:
- FiveDollar
- Date:
- Mon Nov 14 01:27:31 2016 +0000
- Revision:
- 2:fbba2687ddfe
- Parent:
- 0:b2b3955cd77b
- Child:
- 7:4eb590c7e064
nov 13 commit
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" |
FiveDollar | 0:b2b3955cd77b | 8 | #include <stdlib.h> |
FiveDollar | 0:b2b3955cd77b | 9 | #include <stdio.h> |
FiveDollar | 0:b2b3955cd77b | 10 | #include <string> |
FiveDollar | 0:b2b3955cd77b | 11 | |
FiveDollar | 0:b2b3955cd77b | 12 | //CONSTRUCTORS***************************** |
FiveDollar | 0:b2b3955cd77b | 13 | interface::interface(){ |
FiveDollar | 0:b2b3955cd77b | 14 | } |
FiveDollar | 0:b2b3955cd77b | 15 | |
FiveDollar | 0:b2b3955cd77b | 16 | interface::interface(Serial* inputPC){ |
FiveDollar | 0:b2b3955cd77b | 17 | pc = inputPC; |
FiveDollar | 0:b2b3955cd77b | 18 | } |
FiveDollar | 0:b2b3955cd77b | 19 | |
FiveDollar | 0:b2b3955cd77b | 20 | interface::interface(Serial* inputPC , pulse* p , chamberData* atrium , chamberData* ventricle){ |
FiveDollar | 0:b2b3955cd77b | 21 | pc = inputPC; |
FiveDollar | 0:b2b3955cd77b | 22 | interfacePulse = p; |
FiveDollar | 0:b2b3955cd77b | 23 | atrData = atrium; |
FiveDollar | 0:b2b3955cd77b | 24 | ventData = ventricle; |
FiveDollar | 0:b2b3955cd77b | 25 | startScreen(); |
FiveDollar | 0:b2b3955cd77b | 26 | } |
FiveDollar | 0:b2b3955cd77b | 27 | //******************************************** |
FiveDollar | 0:b2b3955cd77b | 28 | |
FiveDollar | 0:b2b3955cd77b | 29 | |
FiveDollar | 0:b2b3955cd77b | 30 | //USER INTERFACE SCREENS************************** |
FiveDollar | 0:b2b3955cd77b | 31 | |
FiveDollar | 0:b2b3955cd77b | 32 | void interface::startScreen(){ |
FiveDollar | 0:b2b3955cd77b | 33 | (*pc).printf("\nWelcome to the PACEMAKER DCM.\n"); |
FiveDollar | 0:b2b3955cd77b | 34 | (*pc).printf("Options:\n"); |
FiveDollar | 0:b2b3955cd77b | 35 | (*pc).printf("1. Start pulse\n"); |
FiveDollar | 0:b2b3955cd77b | 36 | (*pc).printf("2. View/Change data\n"); |
FiveDollar | 0:b2b3955cd77b | 37 | (*pc).printf("Please enter a command:"); |
FiveDollar | 0:b2b3955cd77b | 38 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 39 | switch (command) { |
FiveDollar | 0:b2b3955cd77b | 40 | case '1': |
FiveDollar | 0:b2b3955cd77b | 41 | interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse. |
FiveDollar | 0:b2b3955cd77b | 42 | startScreen(); //realistically we'll never need to call the serial output in pulse, it should all be done in UI |
FiveDollar | 0:b2b3955cd77b | 43 | break; |
FiveDollar | 0:b2b3955cd77b | 44 | case '2': |
FiveDollar | 0:b2b3955cd77b | 45 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 46 | break; |
FiveDollar | 2:fbba2687ddfe | 47 | default: |
FiveDollar | 2:fbba2687ddfe | 48 | pc->printf("\nThat is not an option."); |
FiveDollar | 2:fbba2687ddfe | 49 | interface::startScreen(); |
FiveDollar | 2:fbba2687ddfe | 50 | break; |
FiveDollar | 2:fbba2687ddfe | 51 | } |
FiveDollar | 0:b2b3955cd77b | 52 | } |
FiveDollar | 0:b2b3955cd77b | 53 | |
FiveDollar | 0:b2b3955cd77b | 54 | void interface::dataScreen(){ |
FiveDollar | 0:b2b3955cd77b | 55 | (*pc).printf("\nDCM Data sets:\n"); |
FiveDollar | 2:fbba2687ddfe | 56 | (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. General Data\n4. Egram Data\n5. Back to start page\n"); |
FiveDollar | 0:b2b3955cd77b | 57 | (*pc).printf("Choose a data set:"); |
FiveDollar | 0:b2b3955cd77b | 58 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 59 | switch (command) { |
FiveDollar | 0:b2b3955cd77b | 60 | case '1': |
FiveDollar | 2:fbba2687ddfe | 61 | pc->printf("\nAtrium Data"); |
FiveDollar | 2:fbba2687ddfe | 62 | pc->printf("\n1. Pace Amplitude: %f", atrData->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 63 | pc->printf("\n2. Pace Width: %f", atrData->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 64 | pc->printf("\n3. Refractory Period: %f", atrData->getRP()); |
FiveDollar | 0:b2b3955cd77b | 65 | pc->printf("\n4. Sensitivity: %f", atrData->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 66 | pc->printf("\nChoose variable to be changed or 5 To return to Data Sets"); |
FiveDollar | 0:b2b3955cd77b | 67 | interface::getData(atrData); |
FiveDollar | 0:b2b3955cd77b | 68 | break; |
FiveDollar | 0:b2b3955cd77b | 69 | case '2': |
FiveDollar | 2:fbba2687ddfe | 70 | pc->printf("\nVentricle Data"); |
FiveDollar | 2:fbba2687ddfe | 71 | pc->printf("\n1. Pace Amplitude: %f", ventData->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 72 | pc->printf("\n2. Pace Width: %f", ventData->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 73 | pc->printf("\n3. Refractory Period: %f", ventData->getRP()); |
FiveDollar | 0:b2b3955cd77b | 74 | pc->printf("\n4. Sensitivity: %f", ventData->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 75 | pc->printf("\nChoose variable to be changed or 5 To return to Data Sets"); |
FiveDollar | 0:b2b3955cd77b | 76 | interface::getData(ventData); |
FiveDollar | 0:b2b3955cd77b | 77 | break; |
FiveDollar | 0:b2b3955cd77b | 78 | case '3': |
FiveDollar | 2:fbba2687ddfe | 79 | pc->printf("\nGeneral Data"); |
FiveDollar | 2:fbba2687ddfe | 80 | // pc->printf("\n1. Hysteresis: %f", |
FiveDollar | 2:fbba2687ddfe | 81 | case '4': |
FiveDollar | 2:fbba2687ddfe | 82 | pc->printf("\nNot setup yet"); |
FiveDollar | 0:b2b3955cd77b | 83 | break; |
FiveDollar | 2:fbba2687ddfe | 84 | case '5': |
FiveDollar | 0:b2b3955cd77b | 85 | interface::startScreen(); |
FiveDollar | 0:b2b3955cd77b | 86 | default: |
FiveDollar | 2:fbba2687ddfe | 87 | pc->printf("\nThat is not an option."); |
FiveDollar | 0:b2b3955cd77b | 88 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 89 | } |
FiveDollar | 0:b2b3955cd77b | 90 | } |
FiveDollar | 0:b2b3955cd77b | 91 | |
FiveDollar | 0:b2b3955cd77b | 92 | void interface::getData(chamberData* chamber){ |
FiveDollar | 0:b2b3955cd77b | 93 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 94 | switch (command){ |
FiveDollar | 0:b2b3955cd77b | 95 | case '1': |
FiveDollar | 2:fbba2687ddfe | 96 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 97 | char* value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 98 | chamber->chngPaceAmp(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 99 | pc->printf("\t%f",chamber->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 100 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 101 | break; |
FiveDollar | 0:b2b3955cd77b | 102 | case '2': |
FiveDollar | 2:fbba2687ddfe | 103 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 104 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 105 | chamber->chngPaceWidth(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 106 | pc->printf("\t%f",chamber->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 107 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 108 | break; |
FiveDollar | 0:b2b3955cd77b | 109 | case '3': |
FiveDollar | 2:fbba2687ddfe | 110 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 111 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 112 | chamber->chngRP(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 113 | pc->printf("\t%f",chamber->getRP()); |
FiveDollar | 0:b2b3955cd77b | 114 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 115 | break; |
FiveDollar | 0:b2b3955cd77b | 116 | case '4': |
FiveDollar | 2:fbba2687ddfe | 117 | pc->printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 118 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 119 | chamber->chngSensitivity(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 120 | pc->printf("\t%f",chamber->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 121 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 122 | break; |
FiveDollar | 0:b2b3955cd77b | 123 | case '5': |
FiveDollar | 0:b2b3955cd77b | 124 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 125 | break; |
FiveDollar | 0:b2b3955cd77b | 126 | default: |
FiveDollar | 0:b2b3955cd77b | 127 | pc->printf("\nThat is not an option."); |
FiveDollar | 0:b2b3955cd77b | 128 | interface::getData(chamber); |
FiveDollar | 0:b2b3955cd77b | 129 | } |
FiveDollar | 0:b2b3955cd77b | 130 | } |
FiveDollar | 0:b2b3955cd77b | 131 | |
FiveDollar | 0:b2b3955cd77b | 132 | char* interface::getInput(){ |
FiveDollar | 0:b2b3955cd77b | 133 | char buffer[5]; |
FiveDollar | 0:b2b3955cd77b | 134 | fgets (buffer,5,stdin); |
FiveDollar | 0:b2b3955cd77b | 135 | return buffer; |
FiveDollar | 0:b2b3955cd77b | 136 | } |
FiveDollar | 0:b2b3955cd77b | 137 | |
FiveDollar | 0:b2b3955cd77b | 138 | char interface::getChar(){ |
FiveDollar | 0:b2b3955cd77b | 139 | while(true){ |
FiveDollar | 0:b2b3955cd77b | 140 | if(pc->readable()){ |
FiveDollar | 0:b2b3955cd77b | 141 | char command = pc->getc(); |
FiveDollar | 0:b2b3955cd77b | 142 | return command; |
FiveDollar | 0:b2b3955cd77b | 143 | } |
FiveDollar | 0:b2b3955cd77b | 144 | } |
FiveDollar | 0:b2b3955cd77b | 145 | } |
FiveDollar | 0:b2b3955cd77b | 146 | //**************************** |
FiveDollar | 0:b2b3955cd77b | 147 | |
FiveDollar | 0:b2b3955cd77b | 148 | //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 | 149 | // pulse myPulse(*atr); |
FiveDollar | 0:b2b3955cd77b | 150 | // myPulse.setWidth(1); |
FiveDollar | 0:b2b3955cd77b | 151 | // myPulse.startPulse(); |
FiveDollar | 0:b2b3955cd77b | 152 | // } |
FiveDollar | 0:b2b3955cd77b | 153 | |
FiveDollar | 0:b2b3955cd77b | 154 | //void interface::LEDon(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 155 | // (*out) = 0; |
FiveDollar | 0:b2b3955cd77b | 156 | //// (*pc).printf(led); |
FiveDollar | 0:b2b3955cd77b | 157 | //} |
FiveDollar | 0:b2b3955cd77b | 158 | // |
FiveDollar | 0:b2b3955cd77b | 159 | //void interface::LEDoff(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 160 | // (*out) = 1; |
FiveDollar | 0:b2b3955cd77b | 161 | //} |