Eric Tran
/
3K04EricTheadfork
eric's fork test
Fork of Pacemaker by
interface.cpp@0:b2b3955cd77b, 2016-10-30 (annotated)
- Committer:
- FiveDollar
- Date:
- Sun Oct 30 16:04:52 2016 +0000
- Revision:
- 0:b2b3955cd77b
- Child:
- 2:fbba2687ddfe
Initial 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 | 0:b2b3955cd77b | 47 | } |
FiveDollar | 0:b2b3955cd77b | 48 | } |
FiveDollar | 0:b2b3955cd77b | 49 | |
FiveDollar | 0:b2b3955cd77b | 50 | void interface::dataScreen(){ |
FiveDollar | 0:b2b3955cd77b | 51 | (*pc).printf("\nDCM Data sets:\n"); |
FiveDollar | 0:b2b3955cd77b | 52 | (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. Egram Data\n4. Back to start page\n"); |
FiveDollar | 0:b2b3955cd77b | 53 | (*pc).printf("Choose a data set:"); |
FiveDollar | 0:b2b3955cd77b | 54 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 55 | switch (command) { |
FiveDollar | 0:b2b3955cd77b | 56 | case '1': |
FiveDollar | 0:b2b3955cd77b | 57 | pc->printf("\nAtrium Data\n"); |
FiveDollar | 0:b2b3955cd77b | 58 | pc->printf("1. Pace Amplitude: %f", atrData->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 59 | pc->printf("\n2. Pace Width: %f", atrData->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 60 | pc->printf("\n3. Refractory Period: %f", atrData->getRP()); |
FiveDollar | 0:b2b3955cd77b | 61 | pc->printf("\n4. Sensitivity: %f", atrData->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 62 | pc->printf("\nChoose variable to be changed or 5 To return to Data Sets"); |
FiveDollar | 0:b2b3955cd77b | 63 | interface::getData(atrData); |
FiveDollar | 0:b2b3955cd77b | 64 | break; |
FiveDollar | 0:b2b3955cd77b | 65 | case '2': |
FiveDollar | 0:b2b3955cd77b | 66 | pc->printf("\nVentricle Data\n"); |
FiveDollar | 0:b2b3955cd77b | 67 | pc->printf("1. Pace Amplitude: %f", ventData->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 68 | pc->printf("\n2. Pace Width: %f", ventData->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 69 | pc->printf("\n3. Refractory Period: %f", ventData->getRP()); |
FiveDollar | 0:b2b3955cd77b | 70 | pc->printf("\n4. Sensitivity: %f", ventData->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 71 | pc->printf("\nChoose variable to be changed or 5 To return to Data Sets"); |
FiveDollar | 0:b2b3955cd77b | 72 | interface::getData(ventData); |
FiveDollar | 0:b2b3955cd77b | 73 | break; |
FiveDollar | 0:b2b3955cd77b | 74 | case '3': |
FiveDollar | 0:b2b3955cd77b | 75 | printf("\nNot setup yet"); |
FiveDollar | 0:b2b3955cd77b | 76 | break; |
FiveDollar | 0:b2b3955cd77b | 77 | case '4': |
FiveDollar | 0:b2b3955cd77b | 78 | interface::startScreen(); |
FiveDollar | 0:b2b3955cd77b | 79 | default: |
FiveDollar | 0:b2b3955cd77b | 80 | printf("\nThat is not an option."); |
FiveDollar | 0:b2b3955cd77b | 81 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 82 | } |
FiveDollar | 0:b2b3955cd77b | 83 | } |
FiveDollar | 0:b2b3955cd77b | 84 | |
FiveDollar | 0:b2b3955cd77b | 85 | void interface::getData(chamberData* chamber){ |
FiveDollar | 0:b2b3955cd77b | 86 | char command = getChar(); |
FiveDollar | 0:b2b3955cd77b | 87 | switch (command){ |
FiveDollar | 0:b2b3955cd77b | 88 | case '1': |
FiveDollar | 0:b2b3955cd77b | 89 | printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 90 | char* value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 91 | chamber->chngPaceAmp(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 92 | pc->printf("\t%f",chamber->getPaceAmp()*7); |
FiveDollar | 0:b2b3955cd77b | 93 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 94 | break; |
FiveDollar | 0:b2b3955cd77b | 95 | case '2': |
FiveDollar | 0:b2b3955cd77b | 96 | printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 97 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 98 | chamber->chngPaceWidth(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 99 | pc->printf("\t%f",chamber->getPaceWidth()); |
FiveDollar | 0:b2b3955cd77b | 100 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 101 | break; |
FiveDollar | 0:b2b3955cd77b | 102 | case '3': |
FiveDollar | 0:b2b3955cd77b | 103 | printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 104 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 105 | chamber->chngRP(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 106 | pc->printf("\t%f",chamber->getRP()); |
FiveDollar | 0:b2b3955cd77b | 107 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 108 | break; |
FiveDollar | 0:b2b3955cd77b | 109 | case '4': |
FiveDollar | 0:b2b3955cd77b | 110 | printf("\nChoose New Value:"); |
FiveDollar | 0:b2b3955cd77b | 111 | value = getInput(); |
FiveDollar | 0:b2b3955cd77b | 112 | chamber->chngSensitivity(atof(value)); |
FiveDollar | 0:b2b3955cd77b | 113 | pc->printf("\t%f",chamber->getSensitivity()); |
FiveDollar | 0:b2b3955cd77b | 114 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 115 | break; |
FiveDollar | 0:b2b3955cd77b | 116 | case '5': |
FiveDollar | 0:b2b3955cd77b | 117 | interface::dataScreen(); |
FiveDollar | 0:b2b3955cd77b | 118 | break; |
FiveDollar | 0:b2b3955cd77b | 119 | default: |
FiveDollar | 0:b2b3955cd77b | 120 | pc->printf("\nThat is not an option."); |
FiveDollar | 0:b2b3955cd77b | 121 | interface::getData(chamber); |
FiveDollar | 0:b2b3955cd77b | 122 | } |
FiveDollar | 0:b2b3955cd77b | 123 | } |
FiveDollar | 0:b2b3955cd77b | 124 | |
FiveDollar | 0:b2b3955cd77b | 125 | char* interface::getInput(){ |
FiveDollar | 0:b2b3955cd77b | 126 | char buffer[5]; |
FiveDollar | 0:b2b3955cd77b | 127 | fgets (buffer,5,stdin); |
FiveDollar | 0:b2b3955cd77b | 128 | return buffer; |
FiveDollar | 0:b2b3955cd77b | 129 | } |
FiveDollar | 0:b2b3955cd77b | 130 | |
FiveDollar | 0:b2b3955cd77b | 131 | char interface::getChar(){ |
FiveDollar | 0:b2b3955cd77b | 132 | while(true){ |
FiveDollar | 0:b2b3955cd77b | 133 | if(pc->readable()){ |
FiveDollar | 0:b2b3955cd77b | 134 | char command = pc->getc(); |
FiveDollar | 0:b2b3955cd77b | 135 | return command; |
FiveDollar | 0:b2b3955cd77b | 136 | } |
FiveDollar | 0:b2b3955cd77b | 137 | } |
FiveDollar | 0:b2b3955cd77b | 138 | } |
FiveDollar | 0:b2b3955cd77b | 139 | //**************************** |
FiveDollar | 0:b2b3955cd77b | 140 | |
FiveDollar | 0:b2b3955cd77b | 141 | //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 | 142 | // pulse myPulse(*atr); |
FiveDollar | 0:b2b3955cd77b | 143 | // myPulse.setWidth(1); |
FiveDollar | 0:b2b3955cd77b | 144 | // myPulse.startPulse(); |
FiveDollar | 0:b2b3955cd77b | 145 | // } |
FiveDollar | 0:b2b3955cd77b | 146 | |
FiveDollar | 0:b2b3955cd77b | 147 | //void interface::LEDon(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 148 | // (*out) = 0; |
FiveDollar | 0:b2b3955cd77b | 149 | //// (*pc).printf(led); |
FiveDollar | 0:b2b3955cd77b | 150 | //} |
FiveDollar | 0:b2b3955cd77b | 151 | // |
FiveDollar | 0:b2b3955cd77b | 152 | //void interface::LEDoff(AnalogOut* out){ |
FiveDollar | 0:b2b3955cd77b | 153 | // (*out) = 1; |
FiveDollar | 0:b2b3955cd77b | 154 | //} |