Pacemaker code Implementation for SFWRENG 3K04

Dependencies:   mbed Queue mbed-rtos FXOS8700Q

Fork of Pacemaker by Eric dollar

SWFRENG 3K04 Project to design, develop, and document a functional pacemaker.

The project uses the Freescale K64F Microcontroller and C++ mbed library.

Committer:
noahzwiep
Date:
Thu Nov 17 04:03:25 2016 +0000
Revision:
16:08d5e5a3ee74
Parent:
15:3b8acee3510d
Child:
19:d58e1e1a9a24
- Made change to hardware class that provides sensing pin; - Made dataStruct class in which there is multiple threading for grabbing queue data; - Made queue in datastruct to allow storage of data

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(){
FiveDollar 0:b2b3955cd77b 37 (*pc).printf("\nWelcome to the PACEMAKER DCM.\n");
FiveDollar 0:b2b3955cd77b 38 (*pc).printf("Options:\n");
trane3 8:75c1dd8b0d61 39 (*pc).printf("1. Start VOOR Pulse\n"); // temporary test to get VOOR working
FiveDollar 0:b2b3955cd77b 40 (*pc).printf("2. View/Change data\n");
FiveDollar 0:b2b3955cd77b 41 (*pc).printf("Please enter a command:");
FiveDollar 0:b2b3955cd77b 42 char command = getChar();
FiveDollar 0:b2b3955cd77b 43 switch (command) {
trane3 8:75c1dd8b0d61 44 case '1':{
trane3 8:75c1dd8b0d61 45 voor v(interfacePulse); //creates new instance of voor
trane3 8:75c1dd8b0d61 46 v.startPace(); //starts pacing voor the same way as it used to pace in the user interface
trane3 8:75c1dd8b0d61 47 //interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse.
FiveDollar 0:b2b3955cd77b 48 startScreen(); //realistically we'll never need to call the serial output in pulse, it should all be done in UI
FiveDollar 0:b2b3955cd77b 49 break;
trane3 8:75c1dd8b0d61 50 }
FiveDollar 0:b2b3955cd77b 51 case '2':
FiveDollar 0:b2b3955cd77b 52 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 53 break;
FiveDollar 2:fbba2687ddfe 54 default:
FiveDollar 2:fbba2687ddfe 55 pc->printf("\nThat is not an option.");
FiveDollar 2:fbba2687ddfe 56 interface::startScreen();
FiveDollar 2:fbba2687ddfe 57 break;
FiveDollar 2:fbba2687ddfe 58 }
FiveDollar 0:b2b3955cd77b 59 }
FiveDollar 0:b2b3955cd77b 60
FiveDollar 0:b2b3955cd77b 61 void interface::dataScreen(){
FiveDollar 0:b2b3955cd77b 62 (*pc).printf("\nDCM Data sets:\n");
FiveDollar 2:fbba2687ddfe 63 (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. General Data\n4. Egram Data\n5. Back to start page\n");
FiveDollar 0:b2b3955cd77b 64 (*pc).printf("Choose a data set:");
FiveDollar 0:b2b3955cd77b 65 char command = getChar();
FiveDollar 0:b2b3955cd77b 66 switch (command) {
FiveDollar 0:b2b3955cd77b 67 case '1':
FiveDollar 2:fbba2687ddfe 68 pc->printf("\nAtrium Data");
FiveDollar 2:fbba2687ddfe 69 pc->printf("\n1. Pace Amplitude: %f", atrData->getPaceAmp()*7);
FiveDollar 0:b2b3955cd77b 70 pc->printf("\n2. Pace Width: %f", atrData->getPaceWidth());
FiveDollar 0:b2b3955cd77b 71 pc->printf("\n3. Refractory Period: %f", atrData->getRP());
FiveDollar 0:b2b3955cd77b 72 pc->printf("\n4. Sensitivity: %f", atrData->getSensitivity());
FiveDollar 0:b2b3955cd77b 73 pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
FiveDollar 0:b2b3955cd77b 74 interface::getData(atrData);
FiveDollar 0:b2b3955cd77b 75 break;
FiveDollar 0:b2b3955cd77b 76 case '2':
FiveDollar 2:fbba2687ddfe 77 pc->printf("\nVentricle Data");
FiveDollar 2:fbba2687ddfe 78 pc->printf("\n1. Pace Amplitude: %f", ventData->getPaceAmp()*7);
FiveDollar 0:b2b3955cd77b 79 pc->printf("\n2. Pace Width: %f", ventData->getPaceWidth());
FiveDollar 0:b2b3955cd77b 80 pc->printf("\n3. Refractory Period: %f", ventData->getRP());
FiveDollar 0:b2b3955cd77b 81 pc->printf("\n4. Sensitivity: %f", ventData->getSensitivity());
FiveDollar 0:b2b3955cd77b 82 pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
FiveDollar 0:b2b3955cd77b 83 interface::getData(ventData);
FiveDollar 0:b2b3955cd77b 84 break;
FiveDollar 0:b2b3955cd77b 85 case '3':
FiveDollar 2:fbba2687ddfe 86 pc->printf("\nGeneral Data");
FiveDollar 13:bb80794b6727 87 pc->printf("\n1. Hysteresis: %s", generalData->getHyst() ? "true" : "false");
FiveDollar 9:b48423a135d8 88 pc->printf("\n2. Hysteresis Interval: %f", generalData->getHystInterval());
FiveDollar 9:b48423a135d8 89 pc->printf("\n3. Lower Rate Limit: %f", generalData->getLRL());
FiveDollar 9:b48423a135d8 90 pc->printf("\n4. Upper Rate Limit: %f", generalData->getURL());
FiveDollar 9:b48423a135d8 91 pc->printf("\n5. Atrial-Ventricular Delay: %f", generalData->getAVdelay());
FiveDollar 9:b48423a135d8 92 pc->printf("\n6. Atrial-Ventricular Delay Offset: %f" , generalData->getAVdelayOffset());
FiveDollar 9:b48423a135d8 93 pc->printf("\n7. Rate Smoothing: %f", generalData->getRSmooth());
FiveDollar 2:fbba2687ddfe 94 case '4':
FiveDollar 2:fbba2687ddfe 95 pc->printf("\nNot setup yet");
FiveDollar 0:b2b3955cd77b 96 break;
FiveDollar 2:fbba2687ddfe 97 case '5':
FiveDollar 0:b2b3955cd77b 98 interface::startScreen();
FiveDollar 0:b2b3955cd77b 99 default:
FiveDollar 2:fbba2687ddfe 100 pc->printf("\nThat is not an option.");
FiveDollar 0:b2b3955cd77b 101 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 102 }
FiveDollar 0:b2b3955cd77b 103 }
FiveDollar 0:b2b3955cd77b 104
FiveDollar 0:b2b3955cd77b 105 void interface::getData(chamberData* chamber){
FiveDollar 0:b2b3955cd77b 106 char command = getChar();
FiveDollar 0:b2b3955cd77b 107 switch (command){
FiveDollar 0:b2b3955cd77b 108 case '1':
FiveDollar 2:fbba2687ddfe 109 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 110 char* value = getInput();
FiveDollar 0:b2b3955cd77b 111 chamber->chngPaceAmp(atof(value));
FiveDollar 0:b2b3955cd77b 112 pc->printf("\t%f",chamber->getPaceAmp()*7);
FiveDollar 0:b2b3955cd77b 113 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 114 break;
FiveDollar 0:b2b3955cd77b 115 case '2':
FiveDollar 2:fbba2687ddfe 116 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 117 value = getInput();
FiveDollar 0:b2b3955cd77b 118 chamber->chngPaceWidth(atof(value));
FiveDollar 0:b2b3955cd77b 119 pc->printf("\t%f",chamber->getPaceWidth());
FiveDollar 0:b2b3955cd77b 120 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 121 break;
FiveDollar 0:b2b3955cd77b 122 case '3':
FiveDollar 2:fbba2687ddfe 123 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 124 value = getInput();
FiveDollar 0:b2b3955cd77b 125 chamber->chngRP(atof(value));
FiveDollar 0:b2b3955cd77b 126 pc->printf("\t%f",chamber->getRP());
FiveDollar 0:b2b3955cd77b 127 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 128 break;
FiveDollar 0:b2b3955cd77b 129 case '4':
FiveDollar 2:fbba2687ddfe 130 pc->printf("\nChoose New Value:");
FiveDollar 0:b2b3955cd77b 131 value = getInput();
FiveDollar 0:b2b3955cd77b 132 chamber->chngSensitivity(atof(value));
FiveDollar 0:b2b3955cd77b 133 pc->printf("\t%f",chamber->getSensitivity());
FiveDollar 0:b2b3955cd77b 134 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 135 break;
FiveDollar 0:b2b3955cd77b 136 case '5':
FiveDollar 0:b2b3955cd77b 137 interface::dataScreen();
FiveDollar 0:b2b3955cd77b 138 break;
FiveDollar 0:b2b3955cd77b 139 default:
FiveDollar 0:b2b3955cd77b 140 pc->printf("\nThat is not an option.");
FiveDollar 0:b2b3955cd77b 141 interface::getData(chamber);
FiveDollar 0:b2b3955cd77b 142 }
FiveDollar 0:b2b3955cd77b 143 }
FiveDollar 0:b2b3955cd77b 144
FiveDollar 13:bb80794b6727 145
FiveDollar 13:bb80794b6727 146
FiveDollar 0:b2b3955cd77b 147 char* interface::getInput(){
FiveDollar 0:b2b3955cd77b 148 char buffer[5];
FiveDollar 0:b2b3955cd77b 149 fgets (buffer,5,stdin);
FiveDollar 0:b2b3955cd77b 150 return buffer;
FiveDollar 0:b2b3955cd77b 151 }
FiveDollar 0:b2b3955cd77b 152
FiveDollar 0:b2b3955cd77b 153 char interface::getChar(){
FiveDollar 0:b2b3955cd77b 154 while(true){
FiveDollar 0:b2b3955cd77b 155 if(pc->readable()){
FiveDollar 0:b2b3955cd77b 156 char command = pc->getc();
FiveDollar 0:b2b3955cd77b 157 return command;
FiveDollar 0:b2b3955cd77b 158 }
FiveDollar 0:b2b3955cd77b 159 }
FiveDollar 0:b2b3955cd77b 160 }
FiveDollar 0:b2b3955cd77b 161 //****************************
FiveDollar 0:b2b3955cd77b 162
FiveDollar 0:b2b3955cd77b 163 //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 164 // pulse myPulse(*atr);
FiveDollar 0:b2b3955cd77b 165 // myPulse.setWidth(1);
FiveDollar 0:b2b3955cd77b 166 // myPulse.startPulse();
FiveDollar 0:b2b3955cd77b 167 // }
FiveDollar 0:b2b3955cd77b 168
FiveDollar 0:b2b3955cd77b 169 //void interface::LEDon(AnalogOut* out){
FiveDollar 0:b2b3955cd77b 170 // (*out) = 0;
FiveDollar 0:b2b3955cd77b 171 //// (*pc).printf(led);
FiveDollar 0:b2b3955cd77b 172 //}
FiveDollar 0:b2b3955cd77b 173 //
FiveDollar 0:b2b3955cd77b 174 //void interface::LEDoff(AnalogOut* out){
FiveDollar 0:b2b3955cd77b 175 // (*out) = 1;
FiveDollar 0:b2b3955cd77b 176 //}