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:
Tue Dec 06 20:57:56 2016 +0000
Revision:
32:69cd1390bc21
Parent:
31:5e55042e025a
Child:
34:701503855d52
Updated interface and pulse classes - Noah

Who changed what in which revision?

UserRevisionLine numberNew contents of line
noahzwiep 25:d816de7067da 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"
noahzwiep 25:d816de7067da 10 #include "queue.h"
FiveDollar 0:b2b3955cd77b 11 #include <stdlib.h>
FiveDollar 0:b2b3955cd77b 12 #include <stdio.h>
FiveDollar 0:b2b3955cd77b 13 #include <string>
FiveDollar 0:b2b3955cd77b 14
FiveDollar 0:b2b3955cd77b 15 //CONSTRUCTORS*****************************
noahzwiep 32:69cd1390bc21 16 interface::interface():rled(LED_BLUE){
FiveDollar 0:b2b3955cd77b 17 }
FiveDollar 0:b2b3955cd77b 18
noahzwiep 32:69cd1390bc21 19 interface::~interface(){
noahzwiep 32:69cd1390bc21 20 delete myDataStruct;
noahzwiep 32:69cd1390bc21 21 }
trane3 7:4eb590c7e064 22
noahzwiep 32:69cd1390bc21 23 interface::interface(Serial* inputPC):rled(LED_BLUE){
FiveDollar 0:b2b3955cd77b 24 pc = inputPC;
FiveDollar 0:b2b3955cd77b 25 }
FiveDollar 0:b2b3955cd77b 26
noahzwiep 32:69cd1390bc21 27 interface::interface(Serial* inputPC , pulse* p ,genData* genData, chamberData* atrium , chamberData* ventricle, hardware* hardw):rled(LED_BLUE){
noahzwiep 32:69cd1390bc21 28 rled = 1;
noahzwiep 32:69cd1390bc21 29 isEgram = true;
FiveDollar 9:b48423a135d8 30 generalData = genData;
FiveDollar 0:b2b3955cd77b 31 pc = inputPC;
FiveDollar 0:b2b3955cd77b 32 interfacePulse = p;
FiveDollar 0:b2b3955cd77b 33 atrData = atrium;
noahzwiep 25:d816de7067da 34 ventData = ventricle;
noahzwiep 32:69cd1390bc21 35 myHardware = hardw;
noahzwiep 32:69cd1390bc21 36 myDataStruct = new dataStruct(myHardware);
FiveDollar 0:b2b3955cd77b 37 }
FiveDollar 0:b2b3955cd77b 38 //********************************************
FiveDollar 0:b2b3955cd77b 39
FiveDollar 0:b2b3955cd77b 40
FiveDollar 0:b2b3955cd77b 41 //USER INTERFACE SCREENS**************************
FiveDollar 0:b2b3955cd77b 42
noahzwiep 32:69cd1390bc21 43 void interface:: readValues(){
noahzwiep 32:69cd1390bc21 44 bool keepStreaming = true;
noahzwiep 32:69cd1390bc21 45 while(keepStreaming){
noahzwiep 32:69cd1390bc21 46 isEgram = true;
noahzwiep 32:69cd1390bc21 47 if(pc->readable()){
noahzwiep 32:69cd1390bc21 48 command = pc->getc();
noahzwiep 32:69cd1390bc21 49 switch (command){
noahzwiep 32:69cd1390bc21 50 case 0x1:{
noahzwiep 32:69cd1390bc21 51 rled = !rled;
noahzwiep 32:69cd1390bc21 52 value = getInput();
noahzwiep 32:69cd1390bc21 53 generalData->chngAVdelayOffset(atof(value));
noahzwiep 32:69cd1390bc21 54 break;
noahzwiep 32:69cd1390bc21 55 }
noahzwiep 32:69cd1390bc21 56 case 0x2:{
noahzwiep 32:69cd1390bc21 57 value = getInput();
noahzwiep 32:69cd1390bc21 58 generalData->chngLRL(atof(value));
noahzwiep 32:69cd1390bc21 59 break;
noahzwiep 32:69cd1390bc21 60 }
noahzwiep 32:69cd1390bc21 61 case 0x3:{
noahzwiep 32:69cd1390bc21 62 value = getInput();
noahzwiep 32:69cd1390bc21 63 generalData->chngURL(atof(value));
noahzwiep 32:69cd1390bc21 64 break;
noahzwiep 32:69cd1390bc21 65 }
noahzwiep 32:69cd1390bc21 66 case 0x4:{
noahzwiep 32:69cd1390bc21 67 value = getInput();
noahzwiep 32:69cd1390bc21 68 generalData->chngAVdelay(atof(value));
noahzwiep 32:69cd1390bc21 69 break;
noahzwiep 32:69cd1390bc21 70 }
noahzwiep 32:69cd1390bc21 71 case 0x5:{
noahzwiep 32:69cd1390bc21 72 value = getInput();
noahzwiep 32:69cd1390bc21 73 generalData->chngAVdelayOffset(atof(value));
noahzwiep 32:69cd1390bc21 74 break;
noahzwiep 32:69cd1390bc21 75 }
noahzwiep 32:69cd1390bc21 76 case 0x6:{
noahzwiep 32:69cd1390bc21 77 value = getInput();
noahzwiep 32:69cd1390bc21 78 generalData->chngRSmooth(atof(value));
noahzwiep 32:69cd1390bc21 79 break;
noahzwiep 32:69cd1390bc21 80 }
noahzwiep 32:69cd1390bc21 81 case 0x7:{
noahzwiep 32:69cd1390bc21 82 value = getInput();
noahzwiep 32:69cd1390bc21 83 atrData->chngPaceAmp(atof(value)/10);
noahzwiep 32:69cd1390bc21 84 break;
noahzwiep 32:69cd1390bc21 85 }
noahzwiep 32:69cd1390bc21 86 case 0x8:{
noahzwiep 32:69cd1390bc21 87 value = getInput();
noahzwiep 32:69cd1390bc21 88 atrData->chngRP(atof(value));
noahzwiep 32:69cd1390bc21 89 break;
noahzwiep 32:69cd1390bc21 90 }
noahzwiep 32:69cd1390bc21 91 case 0x9:{
noahzwiep 32:69cd1390bc21 92 value = getInput();
noahzwiep 32:69cd1390bc21 93 atrData->chngPaceWidth(atof(value)/100);
noahzwiep 32:69cd1390bc21 94 break;
noahzwiep 32:69cd1390bc21 95 }
noahzwiep 32:69cd1390bc21 96 case 0xA:{
noahzwiep 32:69cd1390bc21 97 value = getInput();
noahzwiep 32:69cd1390bc21 98 atrData->chngSensitivity(atof(value)/100);
noahzwiep 32:69cd1390bc21 99 break;
noahzwiep 32:69cd1390bc21 100 }
noahzwiep 32:69cd1390bc21 101 case 0xB:{
noahzwiep 32:69cd1390bc21 102 value = getInput();
noahzwiep 32:69cd1390bc21 103 atrData->chngPaceAmp(atof(value)/10);
noahzwiep 32:69cd1390bc21 104 break;
noahzwiep 32:69cd1390bc21 105 }
noahzwiep 32:69cd1390bc21 106 case 0xC:{
noahzwiep 32:69cd1390bc21 107 value = getInput();
noahzwiep 32:69cd1390bc21 108 ventData->chngPaceWidth(atof(value)/10);
noahzwiep 32:69cd1390bc21 109 break;
noahzwiep 32:69cd1390bc21 110 }
noahzwiep 32:69cd1390bc21 111 case 0xD:{
noahzwiep 32:69cd1390bc21 112 value = getInput();
noahzwiep 32:69cd1390bc21 113 ventData->chngRP(atof(value));
noahzwiep 32:69cd1390bc21 114 break;
noahzwiep 32:69cd1390bc21 115 }
noahzwiep 32:69cd1390bc21 116 case 0xE:{
noahzwiep 32:69cd1390bc21 117 value = getInput();
noahzwiep 32:69cd1390bc21 118 ventData->chngSensitivity(atof(value)/10);
noahzwiep 32:69cd1390bc21 119 break;
noahzwiep 32:69cd1390bc21 120 }
noahzwiep 32:69cd1390bc21 121 case 0xF:{
noahzwiep 32:69cd1390bc21 122 /* value = getInput();
noahzwiep 32:69cd1390bc21 123 if(genData->getMode() == value){
noahzwiep 32:69cd1390bc21 124 break;
noahzwiep 32:69cd1390bc21 125 }
noahzwiep 32:69cd1390bc21 126 if(value == "VOOR"){
noahzwiep 32:69cd1390bc21 127 break;
noahzwiep 32:69cd1390bc21 128 }
noahzwiep 32:69cd1390bc21 129 else if(value == "VVI"){
noahzwiep 32:69cd1390bc21 130 break;
noahzwiep 32:69cd1390bc21 131 }*/
noahzwiep 32:69cd1390bc21 132 }
noahzwiep 32:69cd1390bc21 133 case 0x7a:{
noahzwiep 32:69cd1390bc21 134 while(isEgram){
noahzwiep 32:69cd1390bc21 135 if(pc->readable()){
noahzwiep 32:69cd1390bc21 136 char command = pc->getc();
noahzwiep 32:69cd1390bc21 137 if(command == 0x8a){
noahzwiep 32:69cd1390bc21 138 isEgram = false;
noahzwiep 32:69cd1390bc21 139 }
noahzwiep 32:69cd1390bc21 140 }
noahzwiep 32:69cd1390bc21 141 double myInt = (myDataStruct->getData());
noahzwiep 32:69cd1390bc21 142 pc->printf("%f\n", myInt);
noahzwiep 32:69cd1390bc21 143 rled = !rled;
noahzwiep 32:69cd1390bc21 144 Thread::wait(4);
noahzwiep 32:69cd1390bc21 145 }
noahzwiep 32:69cd1390bc21 146 break;
noahzwiep 32:69cd1390bc21 147 }
noahzwiep 32:69cd1390bc21 148 case 0x1E:{
noahzwiep 32:69cd1390bc21 149 value = getInput();
noahzwiep 32:69cd1390bc21 150 if((*value) == '1'){
noahzwiep 32:69cd1390bc21 151 generalData->chngHyst(true);
noahzwiep 32:69cd1390bc21 152 break;
noahzwiep 32:69cd1390bc21 153 }
noahzwiep 32:69cd1390bc21 154 else if((*value)== '0'){
noahzwiep 32:69cd1390bc21 155 generalData->chngHyst(false);
noahzwiep 32:69cd1390bc21 156 break;
noahzwiep 32:69cd1390bc21 157 }
noahzwiep 32:69cd1390bc21 158 }
noahzwiep 32:69cd1390bc21 159 }
trane3 8:75c1dd8b0d61 160 }
noahzwiep 32:69cd1390bc21 161 }
trane3 19:d58e1e1a9a24 162 }
trane3 19:d58e1e1a9a24 163
FiveDollar 0:b2b3955cd77b 164 char* interface::getInput(){
FiveDollar 0:b2b3955cd77b 165 char buffer[5];
FiveDollar 0:b2b3955cd77b 166 fgets (buffer,5,stdin);
FiveDollar 0:b2b3955cd77b 167 return buffer;
FiveDollar 0:b2b3955cd77b 168 }
FiveDollar 0:b2b3955cd77b 169
FiveDollar 0:b2b3955cd77b 170 char interface::getChar(){
FiveDollar 0:b2b3955cd77b 171 while(true){
FiveDollar 0:b2b3955cd77b 172 if(pc->readable()){
FiveDollar 0:b2b3955cd77b 173 char command = pc->getc();
FiveDollar 0:b2b3955cd77b 174 return command;
FiveDollar 0:b2b3955cd77b 175 }
FiveDollar 0:b2b3955cd77b 176 }
noahzwiep 32:69cd1390bc21 177 }
noahzwiep 32:69cd1390bc21 178
noahzwiep 32:69cd1390bc21 179
noahzwiep 32:69cd1390bc21 180
noahzwiep 32:69cd1390bc21 181
noahzwiep 32:69cd1390bc21 182 //void interface::startScreen(){
noahzwiep 32:69cd1390bc21 183 //
noahzwiep 32:69cd1390bc21 184 // pc->printf("\n ____ _ ____ _____ __ __ _ _ _______ ____ ");
noahzwiep 32:69cd1390bc21 185 // pc->printf("\n| _ \\ / \\ / ___| ____| \\/ | / \\ | |/ / ____| _ \\");
noahzwiep 32:69cd1390bc21 186 // pc->printf("\n| |_) / _ \\| | | _| | |\\/| | / _ \\ | ' /| _| | |_) |");
noahzwiep 32:69cd1390bc21 187 // pc->printf("\n| __/ ___ \\ |___| |___| | | |/ ___ \\| . \\| |___| _ <");
noahzwiep 32:69cd1390bc21 188 // pc->printf("\n|_| /_/ \\_\\____|_____|_| |_/_/ \\_\\_|\\_\\_____|_| \\_\\");
noahzwiep 32:69cd1390bc21 189 //
noahzwiep 32:69cd1390bc21 190 //
noahzwiep 32:69cd1390bc21 191 // pc->printf("\nWelcome to the PACEMAKER DCM.\n");
noahzwiep 32:69cd1390bc21 192 // pc->printf("Options:\n");
noahzwiep 32:69cd1390bc21 193 // pc->printf("1. Start VOOR Pulse\n"); // temporary test to get VOOR working
noahzwiep 32:69cd1390bc21 194 // pc->printf("2. View/Change data\n");
noahzwiep 32:69cd1390bc21 195 // pc->printf("Please enter a command:");
noahzwiep 32:69cd1390bc21 196 // char command = getChar();
noahzwiep 32:69cd1390bc21 197 // switch (command) {
noahzwiep 32:69cd1390bc21 198 // case '1':{
noahzwiep 32:69cd1390bc21 199 //
noahzwiep 32:69cd1390bc21 200 // voor v(interfacePulse, ventData); //creates new instance of voor
noahzwiep 32:69cd1390bc21 201 // v.startPace(); //starts pacing voor the same way as it used to pace in the user interface
noahzwiep 32:69cd1390bc21 202 // //interfacePulse->startPulse(); //problems with this method: you create the pc output twice, once in UI and once in pulse.
noahzwiep 32:69cd1390bc21 203 // startScreen(); //realistically we'll never need to call the serial output in pulse, it should all be done in UI
noahzwiep 32:69cd1390bc21 204 // break;
noahzwiep 32:69cd1390bc21 205 // }
noahzwiep 32:69cd1390bc21 206 // case '2':
noahzwiep 32:69cd1390bc21 207 // interface::dataScreen();
noahzwiep 32:69cd1390bc21 208 // break;
noahzwiep 32:69cd1390bc21 209 // default:
noahzwiep 32:69cd1390bc21 210 // pc->printf("\nThat is not an option.\n");
noahzwiep 32:69cd1390bc21 211 // interface::startScreen();
noahzwiep 32:69cd1390bc21 212 // break;
noahzwiep 32:69cd1390bc21 213 // }
noahzwiep 32:69cd1390bc21 214 //}
noahzwiep 32:69cd1390bc21 215
noahzwiep 32:69cd1390bc21 216
FiveDollar 0:b2b3955cd77b 217 //****************************
FiveDollar 0:b2b3955cd77b 218
FiveDollar 0:b2b3955cd77b 219 //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 220 // pulse myPulse(*atr);
FiveDollar 0:b2b3955cd77b 221 // myPulse.setWidth(1);
FiveDollar 0:b2b3955cd77b 222 // myPulse.startPulse();
FiveDollar 0:b2b3955cd77b 223 // }
FiveDollar 0:b2b3955cd77b 224
FiveDollar 0:b2b3955cd77b 225 //void interface::LEDon(AnalogOut* out){
FiveDollar 0:b2b3955cd77b 226 // (*out) = 0;
FiveDollar 0:b2b3955cd77b 227 //// (*pc).printf(led);
FiveDollar 0:b2b3955cd77b 228 //}
FiveDollar 0:b2b3955cd77b 229 //
FiveDollar 0:b2b3955cd77b 230 //void interface::LEDoff(AnalogOut* out){
FiveDollar 0:b2b3955cd77b 231 // (*out) = 1;
FiveDollar 0:b2b3955cd77b 232 //}