eric's fork test

Dependencies:   mbed

Fork of Pacemaker by 3k04 team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers interface.cpp Source File

interface.cpp

00001 #pragma once
00002 #include "mbed.h"
00003 #include "interface.h"
00004 #include "hardware.h"
00005 #include "chamberData.h"
00006 #include "genData.h"
00007 #include "pulse.h"
00008 #include "voor.h"
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include <string>
00012 
00013 //CONSTRUCTORS*****************************
00014 interface::interface(){
00015     }
00016 
00017 interface::~interface(){};
00018 
00019 interface::interface(Serial* inputPC){
00020     pc = inputPC;
00021     }
00022 
00023 interface::interface(Serial* inputPC , pulse* p , chamberData* atrium , chamberData* ventricle){
00024     pc = inputPC;
00025     interfacePulse = p;
00026     atrData = atrium;
00027     ventData = ventricle;
00028     startScreen();
00029     }
00030 //********************************************
00031 
00032 
00033 //USER INTERFACE SCREENS**************************   
00034 
00035 void interface::startScreen(){
00036     (*pc).printf("\nWelcome to the PACEMAKER DCM.\n");
00037     (*pc).printf("Options:\n");
00038     (*pc).printf("1. Start VOOR Pulse\n"); // temporary test to get VOOR working
00039     (*pc).printf("2. View/Change data\n");
00040     (*pc).printf("Please enter a command:");
00041     char command = getChar();
00042     switch (command) {
00043         case '1':{
00044             voor v(interfacePulse); //creates new instance of voor
00045             v.startPace(); //starts pacing voor the same way as it used to pace in the user interface
00046             //interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse.
00047             startScreen();                             //realistically we'll never need to call the serial output in pulse, it should all be done in UI
00048             break;
00049             }
00050         case '2':
00051             interface::dataScreen();
00052             break;
00053         default:
00054             pc->printf("\nThat is not an option.");
00055             interface::startScreen();
00056             break;
00057     }   
00058 }
00059 
00060 void interface::dataScreen(){
00061     (*pc).printf("\nDCM Data sets:\n");
00062     (*pc).printf("1. Atrium Data\n2. Ventricle Data\n3. General Data\n4. Egram Data\n5. Back to start page\n");
00063     (*pc).printf("Choose a data set:");
00064     char command = getChar();
00065     switch (command) {
00066         case '1':
00067             pc->printf("\nAtrium Data");
00068             pc->printf("\n1. Pace Amplitude: %f", atrData->getPaceAmp()*7);
00069             pc->printf("\n2. Pace Width: %f", atrData->getPaceWidth());
00070             pc->printf("\n3. Refractory Period: %f", atrData->getRP());
00071             pc->printf("\n4. Sensitivity: %f", atrData->getSensitivity());
00072             pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
00073             interface::getData(atrData);
00074             break;
00075         case '2':
00076             pc->printf("\nVentricle Data");
00077             pc->printf("\n1. Pace Amplitude: %f", ventData->getPaceAmp()*7);
00078             pc->printf("\n2. Pace Width: %f", ventData->getPaceWidth());
00079             pc->printf("\n3. Refractory Period: %f", ventData->getRP());
00080             pc->printf("\n4. Sensitivity: %f", ventData->getSensitivity());
00081             pc->printf("\nChoose variable to be changed or 5 To return to Data Sets");
00082             interface::getData(ventData);
00083             break;
00084         case '3':
00085             pc->printf("\nGeneral Data");
00086 //            pc->printf("\n1. Hysteresis: %f",
00087         case '4':
00088             pc->printf("\nNot setup yet");
00089             break;
00090         case '5':
00091             interface::startScreen();  
00092         default:
00093             pc->printf("\nThat is not an option.");
00094             interface::dataScreen();
00095     }  
00096 }
00097 
00098 void interface::getData(chamberData* chamber){
00099     char command = getChar();
00100     switch (command){
00101         case '1':
00102             pc->printf("\nChoose New Value:");
00103             char* value = getInput();
00104             chamber->chngPaceAmp(atof(value));
00105             pc->printf("\t%f",chamber->getPaceAmp()*7);
00106             interface::dataScreen();
00107             break;
00108         case '2':
00109             pc->printf("\nChoose New Value:");
00110             value = getInput();
00111             chamber->chngPaceWidth(atof(value));
00112             pc->printf("\t%f",chamber->getPaceWidth());
00113             interface::dataScreen();
00114             break;
00115         case '3':
00116             pc->printf("\nChoose New Value:");
00117             value = getInput();
00118             chamber->chngRP(atof(value));
00119             pc->printf("\t%f",chamber->getRP());
00120             interface::dataScreen();
00121             break;
00122         case '4':
00123             pc->printf("\nChoose New Value:");
00124             value = getInput();
00125             chamber->chngSensitivity(atof(value));
00126             pc->printf("\t%f",chamber->getSensitivity());
00127             interface::dataScreen();
00128             break;
00129         case '5':
00130             interface::dataScreen();
00131             break;
00132         default:
00133             pc->printf("\nThat is not an option.");
00134             interface::getData(chamber);
00135     }  
00136  }
00137  
00138 char* interface::getInput(){
00139     char buffer[5];
00140     fgets (buffer,5,stdin);
00141     return buffer;
00142 }
00143 
00144 char interface::getChar(){
00145     while(true){
00146         if(pc->readable()){
00147             char command = pc->getc();
00148             return command;   
00149             }   
00150         }   
00151 }
00152 //****************************
00153 
00154 //void interface::getAPulse(){ //TODO get this to work, the wait command has issues, see pulse.cpp . wait takes in seconds as argument
00155 //    pulse myPulse(*atr);
00156 //    myPulse.setWidth(1);
00157 //    myPulse.startPulse();
00158 //    }
00159     
00160 //void interface::LEDon(AnalogOut* out){
00161 //    (*out) = 0;
00162 ////    (*pc).printf(led);
00163 //}
00164 //    
00165 //void interface::LEDoff(AnalogOut* out){
00166 //    (*out) = 1;
00167 //}