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.

Files at this revision

API Documentation at this revision

Comitter:
FiveDollar
Date:
Sun Oct 30 16:04:52 2016 +0000
Child:
1:9f1091a53ff5
Child:
2:fbba2687ddfe
Commit message:
Initial Commit

Changed in this revision

chamberData.cpp Show annotated file Show diff for this revision Revisions of this file
chamberData.h Show annotated file Show diff for this revision Revisions of this file
genData.cpp Show annotated file Show diff for this revision Revisions of this file
genData.h Show annotated file Show diff for this revision Revisions of this file
hardware.cpp Show annotated file Show diff for this revision Revisions of this file
hardware.h Show annotated file Show diff for this revision Revisions of this file
interface.cpp Show annotated file Show diff for this revision Revisions of this file
interface.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
pulse.cpp Show annotated file Show diff for this revision Revisions of this file
pulse.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chamberData.cpp	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,78 @@
+#pragma once
+#include "mbed.h"
+#include "chamberData.h"
+
+chamberData::chamberData(){
+}
+
+chamberData::chamberData(Serial* inputPC, char chamberType){
+    p_PaceAmp = 0; //decimal value between 0 and 1 which is a factor applied to 3.3V output.  ie. 0.5 will give 0.5(3.3) V of output
+    p_PaceWidth = 0;
+    p_RP = 0;
+    p_Sensitivity = 0;
+    mychamber = chamberType;
+    pc = inputPC;
+       
+}
+char chamberData::getChamberType(){
+    return mychamber;
+}
+
+void chamberData::chngPaceAmp(double amp){
+    if(mychamber == 'a'){
+        if(amp>3.2 || amp<0.5){
+            pc->printf("\nThat value is not within range."); 
+        }else p_PaceAmp = (amp-0)/(7-0);
+    }else{
+        if(amp>7 || amp<3.5){
+            pc->printf("\nThat value is not within range.");
+        }else p_PaceAmp = (amp-0)/(7-0);
+    }
+}
+
+double chamberData::getPaceAmp(){
+    return p_PaceAmp;
+}
+
+void chamberData::chngPaceWidth(double width){
+    if(mychamber == 'a'){
+        if(width!=0.05){pc->printf("\nThat value is not within range.");
+        }else p_PaceWidth = width;
+    }else{
+        if(width>1.9 || width< 0.1){pc->printf("\nThat value is not within range.");
+        }else p_PaceWidth = width;
+    }
+}
+
+double chamberData::getPaceWidth(){
+    return p_PaceWidth;
+}
+
+void chamberData::chngRP(double RP){
+    if(mychamber == 'a'){
+        if(RP>500 || RP<150){pc->printf("\nThat value is not within range.");
+        }else p_RP = RP;
+    }else{
+        if(RP>500 || RP< 150){pc->printf("\nThat value is not within range.");
+        }else p_RP = RP;
+    }
+}
+
+double chamberData::getRP(){
+    return p_RP;
+}
+
+void chamberData::chngSensitivity(double sensitivity){
+   if(mychamber == 'a'){
+        if(sensitivity!=0.05 || sensitivity!= 0.25 || sensitivity!=0.75){pc->printf("\nThat value is not within range.");
+        }else p_Sensitivity = sensitivity;
+    }else{
+        if(sensitivity>10 || sensitivity< 1){pc->printf("\nThat value is not within range.");
+        }else p_Sensitivity = sensitivity;
+    }
+}
+
+double chamberData::getSensitivity(){
+    return p_Sensitivity;
+}
+chamberData::~chamberData(){}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/chamberData.h	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,27 @@
+#pragma once
+#include "mbed.h"
+#include "genData.h"
+
+class chamberData : public genData {
+public:
+    chamberData();
+    ~chamberData();
+    chamberData(Serial*, char);
+    char getChamberType();
+    void chngPaceAmp(double);
+    double getPaceAmp();
+    void chngPaceWidth(double);
+    double getPaceWidth();
+    void chngRP(double);
+    double getRP();
+    void chngSensitivity(double);
+    double getSensitivity();
+private:
+    Serial* pc;
+    char mychamber;
+    double p_PaceAmp;
+    double p_PaceWidth;
+    double p_RP;
+    double p_Sensitivity;
+    
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/genData.cpp	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,35 @@
+#pragma once
+#include "mbed.h"
+#include "genData.h"
+
+genData::genData(){
+    p_hysteresis = false;
+    p_hysteresisInterval = 0;
+    p_lowerRateLimit = 0;
+    p_upperRateLimit = 0;
+    p_AVdelay = 0;
+    p_AVdelayOffset = 0;
+    p_rateSmoothing = 0;
+    p_pacingMode = VVI;
+    p_pacingState = PERMANENT;
+}
+
+void genData::chngMode(Mode mode){
+    p_pacingMode = mode;
+}
+
+genData::Mode genData::getMode(){
+    return p_pacingMode;
+}
+
+void genData::chngState(State state){
+    p_pacingState = state;
+}
+
+genData::State genData::getState(){
+    return p_pacingState;
+}
+
+
+
+genData::~genData(){}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/genData.h	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,37 @@
+#pragma once
+#include "mbed.h"
+
+class genData{
+public:
+    enum Mode
+    {
+        VVI,
+        VOOR 
+    };
+    enum State
+    {
+        PERMANENT,
+        TEMPORARY
+    };
+    
+    genData();
+    ~genData();
+    virtual void chngMode(Mode mode);
+    virtual Mode getMode();
+    virtual void chngState(State state);
+    virtual State getState();
+    //virtual bool isMagnet();
+    //virtual void chngMagnet(bool state);
+
+protected:
+    double p_hysteresis;
+    double p_hysteresisInterval;
+    double p_lowerRateLimit;
+    double p_upperRateLimit;
+    double p_AVdelay;
+    double p_AVdelayOffset;
+    double p_rateSmoothing;
+    Mode p_pacingMode;
+    State p_pacingState;
+    
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hardware.cpp	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,30 @@
+#pragma once
+#include "hardware.h"
+#include "mbed.h"
+
+AnalogOut atrium(DAC0_OUT);
+AnalogOut ventricle(DAC0_OUT);
+Serial pc(USBTX,USBRX);
+
+
+hardware::hardware(): atrium(DAC0_OUT) , ventricle(DAC0_OUT) , pc(USBTX,USBRX){
+    pc.baud(9600);
+    }
+    
+hardware::~hardware(){};
+    
+Serial* hardware::getSerial(){
+    Serial* p = &pc;
+    return p;
+}
+
+AnalogOut* hardware::getChamber(char chamber){
+    if(chamber == 'a'){
+        AnalogOut* a = &atrium;
+        return a;
+        }
+    else {
+        AnalogOut* v = &ventricle;
+        return v;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hardware.h	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,15 @@
+#pragma once
+#include "mbed.h"
+
+class hardware{
+    public:
+        hardware();
+        ~hardware();
+        Serial* getSerial();
+        AnalogOut* getChamber(char);
+    
+    private:
+        AnalogOut atrium;
+        AnalogOut ventricle;
+        Serial pc;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/interface.cpp	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,154 @@
+#pragma once
+#include "mbed.h"
+#include "interface.h"
+#include "hardware.h"
+#include "chamberData.h"
+#include "genData.h"
+#include "pulse.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string>
+
+//CONSTRUCTORS*****************************
+interface::interface(){
+    }
+
+interface::interface(Serial* inputPC){
+    pc = inputPC;
+    }
+
+interface::interface(Serial* inputPC , pulse* p , chamberData* atrium , chamberData* ventricle){
+    pc = inputPC;
+    interfacePulse = p;
+    atrData = atrium;
+    ventData = ventricle;
+    startScreen();
+    }
+//********************************************
+
+
+//USER INTERFACE SCREENS**************************   
+
+void interface::startScreen(){
+    (*pc).printf("\nWelcome to the PACEMAKER DCM.\n");
+    (*pc).printf("Options:\n");
+    (*pc).printf("1. Start pulse\n");
+    (*pc).printf("2. View/Change data\n");
+    (*pc).printf("Please enter a command:");
+    char command = getChar();
+    switch (command) {
+        case '1':
+            interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse.
+            startScreen();                             //realistically we'll never need to call the serial output in pulse, it should all be done in UI
+            break;
+        case '2':
+            interface::dataScreen();
+            break;
+    }
+}
+
+void interface::dataScreen(){
+    (*pc).printf("\nDCM Data sets:\n");
+    (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. Egram Data\n4. Back to start page\n");
+    (*pc).printf("Choose a data set:");
+    char command = getChar();
+    switch (command) {
+        case '1':
+            pc->printf("\nAtrium Data\n");
+            pc->printf("1. Pace Amplitude: %f", atrData->getPaceAmp()*7);
+            pc->printf("\n2. Pace Width: %f", atrData->getPaceWidth());
+            pc->printf("\n3. Refractory Period: %f", atrData->getRP());
+            pc->printf("\n4. Sensitivity: %f", atrData->getSensitivity());
+            pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
+            interface::getData(atrData);
+            break;
+        case '2':
+            pc->printf("\nVentricle Data\n");
+            pc->printf("1. Pace Amplitude: %f", ventData->getPaceAmp()*7);
+            pc->printf("\n2. Pace Width: %f", ventData->getPaceWidth());
+            pc->printf("\n3. Refractory Period: %f", ventData->getRP());
+            pc->printf("\n4. Sensitivity: %f", ventData->getSensitivity());
+            pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
+            interface::getData(ventData);
+            break;
+        case '3':
+            printf("\nNot setup yet");
+            break;
+        case '4':
+            interface::startScreen();  
+        default:
+            printf("\nThat is not an option.");
+            interface::dataScreen();
+    }  
+}
+
+void interface::getData(chamberData* chamber){
+    char command = getChar();
+    switch (command){
+        case '1':
+            printf("\nChoose New Value:");
+            char* value = getInput();
+            chamber->chngPaceAmp(atof(value));
+            pc->printf("\t%f",chamber->getPaceAmp()*7);
+            interface::dataScreen();
+            break;
+        case '2':
+            printf("\nChoose New Value:");
+            value = getInput();
+            chamber->chngPaceWidth(atof(value));
+            pc->printf("\t%f",chamber->getPaceWidth());
+            interface::dataScreen();
+            break;
+        case '3':
+            printf("\nChoose New Value:");
+            value = getInput();
+            chamber->chngRP(atof(value));
+            pc->printf("\t%f",chamber->getRP());
+            interface::dataScreen();
+            break;
+        case '4':
+            printf("\nChoose New Value:");
+            value = getInput();
+            chamber->chngSensitivity(atof(value));
+            pc->printf("\t%f",chamber->getSensitivity());
+            interface::dataScreen();
+            break;
+        case '5':
+            interface::dataScreen();
+            break;
+        default:
+            pc->printf("\nThat is not an option.");
+            interface::getData(chamber);
+    }  
+ }
+ 
+char* interface::getInput(){
+    char buffer[5];
+    fgets (buffer,5,stdin);
+    return buffer;
+}
+
+char interface::getChar(){
+    while(true){
+        if(pc->readable()){
+            char command = pc->getc();
+            return command;   
+            }   
+        }   
+}
+//****************************
+
+//void interface::getAPulse(){ //TODO get this to work, the wait command has issues, see pulse.cpp . wait takes in seconds as argument
+//    pulse myPulse(*atr);
+//    myPulse.setWidth(1);
+//    myPulse.startPulse();
+//    }
+    
+//void interface::LEDon(AnalogOut* out){
+//    (*out) = 0;
+////    (*pc).printf(led);
+//}
+//    
+//void interface::LEDoff(AnalogOut* out){
+//    (*out) = 1;
+//}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/interface.h	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,32 @@
+#pragma once
+#include "mbed.h"
+#include "hardware.h"
+#include "chamberData.h"
+#include "genData.h"
+#include "pulse.h"
+class interface{
+
+public:
+    interface();
+    interface(Serial*);
+    interface(Serial* , pulse* , chamberData* , chamberData*);
+    void startScreen();
+    void dataScreen();
+    void getData(chamberData*);
+    void chngVentData();
+    char* getInput();
+    char getChar();
+//    void setAtrium(AnalogOut&);
+//    void setVentricle(AnalogOut&);
+//    void LEDon(AnalogOut*);
+//    void LEDoff(AnalogOut*);
+    void changeData(int , double); // UI tells the user to you 1 for atrium, 2 for ventricle, etc.
+    void getData(int);
+    void getEgram();
+      
+private:
+    Serial* pc;
+    pulse* interfacePulse;
+    chamberData* atrData;
+    chamberData* ventData;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,23 @@
+#pragma once
+#include "mbed.h"
+#include "chamberData.h"
+#include "genData.h"
+#include "pulse.h"
+#include "hardware.h"
+#include "interface.h"
+
+int main(){
+    hardware* io = new hardware();
+    chamberData* atrium = new chamberData(io->getSerial(),'a');
+    chamberData* ventricle = new chamberData(io->getSerial(), 'v');
+    pulse* ventPulse = new pulse(ventricle,io);
+    interface a(io->getSerial() , ventPulse , atrium , ventricle);
+    
+    
+    delete ventricle; //code never reaches here, since we're stuck in the while loops of the pacing, user interface, etc.
+    delete atrium;
+    delete ventPulse;
+    delete io;
+    
+return 0;
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pulse.cpp	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,41 @@
+#pragma once
+#include "mbed.h"
+#include "pulse.h"
+
+pulse::pulse(){}
+    
+pulse::pulse(chamberData* chamber, hardware* IOpins){
+    myIOpins = IOpins;
+    myChamber = chamber;
+   // myPaceWidth = 0; //mSec, width of ventricular pace
+//    myPaceAmp = 0; //mV, amplitude of ventricular pace
+//    myRP = 0; //mSec, duration of refractory period
+//    p_hysteresisInterval = 0;
+//    p_lowrateInterval = 0;
+//    p_hysteresis = false;
+    
+}
+
+pulse::~pulse(){
+    delete myChamber;
+    delete myIOpins;
+    delete pc;
+    delete aOut;
+}
+
+    
+
+void pulse::startPulse(){
+   // while(true){
+        pc = myIOpins->getSerial();  
+        aOut = myIOpins->getChamber(myChamber->getChamberType());
+        aOut->write(myChamber->getPaceAmp());    
+        wait(myChamber->getPaceWidth());
+        aOut->write(0);
+        
+        pc->printf("\nPulsing...check your oscilloscope!");
+       // wait(myChamber->getPaceWidth());
+        
+       // }
+}
+    
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pulse.h	Sun Oct 30 16:04:52 2016 +0000
@@ -0,0 +1,25 @@
+#pragma once
+#include "mbed.h"
+#include "hardware.h"
+#include "chamberData.h"
+
+class pulse{
+public:
+    pulse();
+    pulse(chamberData*, hardware*);
+    ~pulse();
+    void startPulse();
+    
+private:
+    double myPaceWidth; //mSec, width of ventricular pace
+    double myPaceAmp; //mV, amplitude of ventricular pace
+    double myRP; //mSec, duration of refractory period
+    float p_hysteresisInterval;
+    float p_lowrateInterval;
+    bool p_hysteresis;
+    Serial* pc;
+    AnalogOut* aOut;
+    chamberData* myChamber;
+    hardware* myIOpins;
+        
+};
\ No newline at end of file