Pacemaker code Implementation for SFWRENG 3K04

Dependencies:   FXOS8700Q Queue mbed-rtos mbed

Fork of Pacemaker by Eric dollar

Committer:
trane3
Date:
Thu Nov 24 01:10:08 2016 +0000
Revision:
19:d58e1e1a9a24
Parent:
16:08d5e5a3ee74
Child:
20:bfd23a6845bb
Child:
21:fc6c33206152
added motion class, and accelerometer capabilites for rate modulation (eric); modified user interface by seperating each 'page' into seperate modules (eric)

Who changed what in which revision?

UserRevisionLine numberNew 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"
noahzwiep 16:08d5e5a3ee74 9 #include "rtos.h"
FiveDollar 0:b2b3955cd77b 10 #include <stdlib.h>
FiveDollar 0:b2b3955cd77b 11 #include <stdio.h>
FiveDollar 0:b2b3955cd77b 12 #include <string>
FiveDollar 0:b2b3955cd77b 13
FiveDollar 0:b2b3955cd77b 14 //CONSTRUCTORS*****************************
FiveDollar 0:b2b3955cd77b 15 interface::interface(){
FiveDollar 0:b2b3955cd77b 16 }
FiveDollar 0:b2b3955cd77b 17
trane3 7:4eb590c7e064 18 interface::~interface(){};
trane3 7:4eb590c7e064 19
FiveDollar 0:b2b3955cd77b 20 interface::interface(Serial* inputPC){
FiveDollar 0:b2b3955cd77b 21 pc = inputPC;
FiveDollar 0:b2b3955cd77b 22 }
FiveDollar 0:b2b3955cd77b 23
FiveDollar 9:b48423a135d8 24 interface::interface(Serial* inputPC , pulse* p ,genData* genData, chamberData* atrium , chamberData* ventricle){
FiveDollar 9:b48423a135d8 25 generalData = genData;
FiveDollar 0:b2b3955cd77b 26 pc = inputPC;
FiveDollar 0:b2b3955cd77b 27 interfacePulse = p;
FiveDollar 0:b2b3955cd77b 28 atrData = atrium;
FiveDollar 0:b2b3955cd77b 29 ventData = ventricle;
FiveDollar 0:b2b3955cd77b 30 }
FiveDollar 0:b2b3955cd77b 31 //********************************************
FiveDollar 0:b2b3955cd77b 32
FiveDollar 0:b2b3955cd77b 33
FiveDollar 0:b2b3955cd77b 34 //USER INTERFACE SCREENS**************************
FiveDollar 0:b2b3955cd77b 35
FiveDollar 0:b2b3955cd77b 36 void interface::startScreen(){
trane3 19:d58e1e1a9a24 37
trane3 19:d58e1e1a9a24 38 pc->printf("\n ____ _ ____ _____ __ __ _ _ _______ ____ ");
trane3 19:d58e1e1a9a24 39 pc->printf("\n| _ \\ / \\ / ___| ____| \\/ | / \\ | |/ / ____| _ \\");
trane3 19:d58e1e1a9a24 40 pc->printf("\n| |_) / _ \\| | | _| | |\\/| | / _ \\ | ' /| _| | |_) |");
trane3 19:d58e1e1a9a24 41 pc->printf("\n| __/ ___ \\ |___| |___| | | |/ ___ \\| . \\| |___| _ <");
trane3 19:d58e1e1a9a24 42 pc->printf("\n|_| /_/ \\_\\____|_____|_| |_/_/ \\_\\_|\\_\\_____|_| \\_\\");
trane3 19:d58e1e1a9a24 43
trane3 19:d58e1e1a9a24 44
trane3 19:d58e1e1a9a24 45 pc->printf("\nWelcome to the PACEMAKER DCM.\n");
trane3 19:d58e1e1a9a24 46 pc->printf("Options:\n");
trane3 19:d58e1e1a9a24 47 pc->printf("1. Start VOOR Pulse\n"); // temporary test to get VOOR working
trane3 19:d58e1e1a9a24 48 pc->printf("2. View/Change data\n");
trane3 19:d58e1e1a9a24 49 pc->printf("Please enter a command:");
FiveDollar 0:b2b3955cd77b 50 char command = getChar();
FiveDollar 0:b2b3955cd77b 51 switch (command) {
trane3 8:75c1dd8b0d61 52 case '1':{
trane3 19:d58e1e1a9a24 53
trane3 19:d58e1e1a9a24 54 voor v(interfacePulse, ventData); //creates new instance of voor
trane3 8:75c1dd8b0d61 55 v.startPace(); //starts pacing voor the same way as it used to pace in the user interface
trane3 8:75c1dd8b0d61 56 //interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse.
FiveDollar 0:b2b3955cd77b 57 startScreen(); //realistically we'll never need to call the serial output in pulse, it should all be done in UI
FiveDollar 0:b2b3955cd77b 58 break;
trane3 8:75c1dd8b0d61 59 }
FiveDollar 0:b2b3955cd77b 60 case '2':
FiveDollar 0:b2b3955cd77b 61 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 62 break;
FiveDollar 1:fbba2687ddfe 63 default:
trane3 19:d58e1e1a9a24 64 pc->printf("\nThat is not an option.\n");
FiveDollar 1:fbba2687ddfe 65 interface::startScreen();
FiveDollar 1:fbba2687ddfe 66 break;
FiveDollar 1:fbba2687ddfe 67 }
FiveDollar 0:b2b3955cd77b 68 }
FiveDollar 0:b2b3955cd77b 69
FiveDollar 0:b2b3955cd77b 70 void interface::dataScreen(){
FiveDollar 0:b2b3955cd77b 71 (*pc).printf("\nDCM Data sets:\n");
FiveDollar 1:fbba2687ddfe 72 (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. General Data\n4. Egram Data\n5. Back to start page\n");
FiveDollar 0:b2b3955cd77b 73 (*pc).printf("Choose a data set:");
FiveDollar 0:b2b3955cd77b 74 char command = getChar();
FiveDollar 0:b2b3955cd77b 75 switch (command) {
FiveDollar 0:b2b3955cd77b 76 case '1':
trane3 19:d58e1e1a9a24 77 interface::chamberDataScreen(atrData);
FiveDollar 0:b2b3955cd77b 78 case '2':
trane3 19:d58e1e1a9a24 79 interface::chamberDataScreen(ventData);
FiveDollar 0:b2b3955cd77b 80 case '3':
trane3 19:d58e1e1a9a24 81 interface::genDataScreen();
FiveDollar 1:fbba2687ddfe 82 case '4':
FiveDollar 1:fbba2687ddfe 83 pc->printf("\nNot setup yet");
FiveDollar 0:b2b3955cd77b 84 break;
FiveDollar 1:fbba2687ddfe 85 case '5':
FiveDollar 0:b2b3955cd77b 86 interface::startScreen();
FiveDollar 0:b2b3955cd77b 87 default:
trane3 19:d58e1e1a9a24 88 pc->printf("\nThat is not an option.\n");
FiveDollar 0:b2b3955cd77b 89 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 90 }
FiveDollar 0:b2b3955cd77b 91 }
FiveDollar 0:b2b3955cd77b 92
trane3 19:d58e1e1a9a24 93 void interface::chamberDataScreen(chamberData* chamber){
trane3 19:d58e1e1a9a24 94 if (chamber == atrData)
trane3 19:d58e1e1a9a24 95 pc->printf("\nAtrium Data");
trane3 19:d58e1e1a9a24 96
trane3 19:d58e1e1a9a24 97 if (chamber == ventData)
trane3 19:d58e1e1a9a24 98 pc->printf("\nVentricle Data");
trane3 19:d58e1e1a9a24 99
trane3 19:d58e1e1a9a24 100 pc->printf("\n1. Pace Amplitude: %f", chamber->getPaceAmp()*7);
trane3 19:d58e1e1a9a24 101 pc->printf("\n2. Pace Width: %f", chamber->getPaceWidth());
trane3 19:d58e1e1a9a24 102 pc->printf("\n3. Refractory Period: %f", chamber->getRP());
trane3 19:d58e1e1a9a24 103 pc->printf("\n4. Sensitivity: %f", chamber->getSensitivity());
trane3 19:d58e1e1a9a24 104 pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
trane3 19:d58e1e1a9a24 105 interface::getData(chamber);
trane3 19:d58e1e1a9a24 106 }
trane3 19:d58e1e1a9a24 107
trane3 19:d58e1e1a9a24 108 void interface::genDataScreen(){ //moved option 3 from dataScreen() into its own method
trane3 19:d58e1e1a9a24 109 pc->printf("\nGeneral Data");
trane3 19:d58e1e1a9a24 110 pc->printf("\n1. Hysteresis: %s", generalData->getHyst() ? "true" : "false");
trane3 19:d58e1e1a9a24 111 pc->printf("\n2. Hysteresis Interval: %f", generalData->getHystInterval());
trane3 19:d58e1e1a9a24 112 pc->printf("\n3. Lower Rate Limit: %f", generalData->getLRL());
trane3 19:d58e1e1a9a24 113 pc->printf("\n4. Upper Rate Limit: %f", generalData->getURL());
trane3 19:d58e1e1a9a24 114 pc->printf("\n5. Atrial-Ventricular Delay: %f", generalData->getAVdelay());
trane3 19:d58e1e1a9a24 115 pc->printf("\n6. Atrial-Ventricular Delay Offset: %f" , generalData->getAVdelayOffset());
trane3 19:d58e1e1a9a24 116 pc->printf("\n7. Rate Smoothing: %f", generalData->getRSmooth());
trane3 19:d58e1e1a9a24 117 pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
trane3 19:d58e1e1a9a24 118 char command = getChar();
trane3 19:d58e1e1a9a24 119 switch (command) {
trane3 19:d58e1e1a9a24 120 case '1':
trane3 19:d58e1e1a9a24 121 pc->printf("\nNot setup yet\n");
trane3 19:d58e1e1a9a24 122 interface::genDataScreen();
trane3 19:d58e1e1a9a24 123 break;
trane3 19:d58e1e1a9a24 124 case '2':
trane3 19:d58e1e1a9a24 125 pc->printf("\nNot setup yet\n");
trane3 19:d58e1e1a9a24 126 interface::genDataScreen();
trane3 19:d58e1e1a9a24 127 break;
trane3 19:d58e1e1a9a24 128 case '3':
trane3 19:d58e1e1a9a24 129 pc->printf("\nNot setup yet\n");
trane3 19:d58e1e1a9a24 130 interface::genDataScreen();
trane3 19:d58e1e1a9a24 131 case '4':
trane3 19:d58e1e1a9a24 132 pc->printf("\nNot setup yet\n");
trane3 19:d58e1e1a9a24 133 interface::genDataScreen();
trane3 19:d58e1e1a9a24 134 break;
trane3 19:d58e1e1a9a24 135 case '5':
trane3 19:d58e1e1a9a24 136 interface::dataScreen();
trane3 19:d58e1e1a9a24 137 default:
trane3 19:d58e1e1a9a24 138 pc->printf("\nThat is not an option.\n");
trane3 19:d58e1e1a9a24 139 interface::genDataScreen();
trane3 19:d58e1e1a9a24 140 }
trane3 19:d58e1e1a9a24 141 }
trane3 19:d58e1e1a9a24 142
trane3 19:d58e1e1a9a24 143
FiveDollar 0:b2b3955cd77b 144 void interface::getData(chamberData* chamber){
FiveDollar 0:b2b3955cd77b 145 char command = getChar();
FiveDollar 0:b2b3955cd77b 146 switch (command){
FiveDollar 0:b2b3955cd77b 147 case '1':
FiveDollar 1:fbba2687ddfe 148 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 149 char* value = getInput();
FiveDollar 0:b2b3955cd77b 150 chamber->chngPaceAmp(atof(value));
FiveDollar 0:b2b3955cd77b 151 pc->printf("\t%f",chamber->getPaceAmp()*7);
FiveDollar 0:b2b3955cd77b 152 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 153 break;
FiveDollar 0:b2b3955cd77b 154 case '2':
FiveDollar 1:fbba2687ddfe 155 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 156 value = getInput();
FiveDollar 0:b2b3955cd77b 157 chamber->chngPaceWidth(atof(value));
FiveDollar 0:b2b3955cd77b 158 pc->printf("\t%f",chamber->getPaceWidth());
FiveDollar 0:b2b3955cd77b 159 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 160 break;
FiveDollar 0:b2b3955cd77b 161 case '3':
FiveDollar 1:fbba2687ddfe 162 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 163 value = getInput();
FiveDollar 0:b2b3955cd77b 164 chamber->chngRP(atof(value));
FiveDollar 0:b2b3955cd77b 165 pc->printf("\t%f",chamber->getRP());
FiveDollar 0:b2b3955cd77b 166 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 167 break;
FiveDollar 0:b2b3955cd77b 168 case '4':
FiveDollar 1:fbba2687ddfe 169 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 170 value = getInput();
FiveDollar 0:b2b3955cd77b 171 chamber->chngSensitivity(atof(value));
FiveDollar 0:b2b3955cd77b 172 pc->printf("\t%f",chamber->getSensitivity());
FiveDollar 0:b2b3955cd77b 173 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 174 break;
FiveDollar 0:b2b3955cd77b 175 case '5':
FiveDollar 0:b2b3955cd77b 176 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 177 break;
FiveDollar 0:b2b3955cd77b 178 default:
FiveDollar 0:b2b3955cd77b 179 pc->printf("\nThat is not an option.");
FiveDollar 0:b2b3955cd77b 180 interface::getData(chamber);
FiveDollar 0:b2b3955cd77b 181 }
FiveDollar 0:b2b3955cd77b 182 }
FiveDollar 0:b2b3955cd77b 183
FiveDollar 13:bb80794b6727 184
FiveDollar 13:bb80794b6727 185
FiveDollar 0:b2b3955cd77b 186 char* interface::getInput(){
FiveDollar 0:b2b3955cd77b 187 char buffer[5];
FiveDollar 0:b2b3955cd77b 188 fgets (buffer,5,stdin);
FiveDollar 0:b2b3955cd77b 189 return buffer;
FiveDollar 0:b2b3955cd77b 190 }
FiveDollar 0:b2b3955cd77b 191
FiveDollar 0:b2b3955cd77b 192 char interface::getChar(){
FiveDollar 0:b2b3955cd77b 193 while(true){
FiveDollar 0:b2b3955cd77b 194 if(pc->readable()){
FiveDollar 0:b2b3955cd77b 195 char command = pc->getc();
FiveDollar 0:b2b3955cd77b 196 return command;
FiveDollar 0:b2b3955cd77b 197 }
FiveDollar 0:b2b3955cd77b 198 }
FiveDollar 0:b2b3955cd77b 199 }
FiveDollar 0:b2b3955cd77b 200 //****************************
FiveDollar 0:b2b3955cd77b 201
FiveDollar 0:b2b3955cd77b 202 //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 203 // pulse myPulse(*atr);
FiveDollar 0:b2b3955cd77b 204 // myPulse.setWidth(1);
FiveDollar 0:b2b3955cd77b 205 // myPulse.startPulse();
FiveDollar 0:b2b3955cd77b 206 // }
FiveDollar 0:b2b3955cd77b 207
FiveDollar 0:b2b3955cd77b 208 //void interface::LEDon(AnalogOut* out){
FiveDollar 0:b2b3955cd77b 209 // (*out) = 0;
FiveDollar 0:b2b3955cd77b 210 //// (*pc).printf(led);
FiveDollar 0:b2b3955cd77b 211 //}
FiveDollar 0:b2b3955cd77b 212 //
FiveDollar 0:b2b3955cd77b 213 //void interface::LEDoff(AnalogOut* out){
FiveDollar 0:b2b3955cd77b 214 // (*out) = 1;
FiveDollar 0:b2b3955cd77b 215 //}