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.

interface.cpp

Committer:
FiveDollar
Date:
2016-10-30
Revision:
0:b2b3955cd77b
Child:
2:fbba2687ddfe

File content as of revision 0:b2b3955cd77b:

#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;
//}