CIS441 Controller

Dependencies:   TextLCD mbed-rtos mbed

Fork of PacemakerController by Chad Nachiappan

Committer:
lucastai
Date:
Wed Dec 02 00:21:13 2015 +0000
Revision:
26:64e2bc7d544a
Parent:
25:18923916215b
Child:
28:5c5552cd472b
Fixed errors in PM Test (PM TEST doesn't test)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lucastai 8:5924b2048a27 1 #include "mbed.h"
lucastai 8:5924b2048a27 2 #include "LPC17xx.h"
lucastai 8:5924b2048a27 3 #include "TextLCD.h"
lucastai 8:5924b2048a27 4 #include "rtos.h"
lucastai 8:5924b2048a27 5 #include "Thread.h"
lucastai 8:5924b2048a27 6
lucastai 8:5924b2048a27 7 DigitalOut vsense(p23);
lucastai 8:5924b2048a27 8 DigitalOut asense(p24);
chadnach1 20:dc272bfaa276 9 DigitalIn apace(p22);
chadnach1 20:dc272bfaa276 10 DigitalIn vpace(p21);
lucastai 8:5924b2048a27 11
lucastai 26:64e2bc7d544a 12 Serial pc(USBTX, USBRX);
lucastai 26:64e2bc7d544a 13
lucastai 26:64e2bc7d544a 14
lucastai 8:5924b2048a27 15 int timer_count;
lucastai 8:5924b2048a27 16 int curr_test;
lucastai 23:08456978fb78 17 int minwaitV;
lucastai 23:08456978fb78 18 int minwaitA;
lucastai 23:08456978fb78 19
lucastai 23:08456978fb78 20 int needs_num_input = 0;
lucastai 23:08456978fb78 21
lucastai 26:64e2bc7d544a 22 enum mode{RANDOM,MANUAL,TEST};
lucastai 23:08456978fb78 23 mode curr_mode = RANDOM;
lucastai 23:08456978fb78 24 Timer t;
lucastai 8:5924b2048a27 25
lucastai 8:5924b2048a27 26
lucastai 23:08456978fb78 27
lucastai 23:08456978fb78 28
lucastai 23:08456978fb78 29
lucastai 23:08456978fb78 30 void random_heart(){
lucastai 23:08456978fb78 31 t.reset();
lucastai 23:08456978fb78 32 t.start();
lucastai 23:08456978fb78 33
lucastai 23:08456978fb78 34 while(curr_mode == RANDOM){
lucastai 23:08456978fb78 35 int r = rand();
lucastai 23:08456978fb78 36
lucastai 23:08456978fb78 37 if(r%2 == 0){
lucastai 23:08456978fb78 38 if(t.read() > minwaitA){
lucastai 23:08456978fb78 39 asense = 1;
lucastai 23:08456978fb78 40 Thread::wait(10);
lucastai 23:08456978fb78 41 asense = 0;
lucastai 23:08456978fb78 42 }
lucastai 23:08456978fb78 43 }else{
lucastai 23:08456978fb78 44 if(t.read() > minwaitV){
lucastai 23:08456978fb78 45 vsense = 1;
lucastai 23:08456978fb78 46 Thread::wait(10);
lucastai 23:08456978fb78 47 vsense = 0;
lucastai 23:08456978fb78 48 }
lucastai 23:08456978fb78 49 }
lucastai 23:08456978fb78 50
lucastai 23:08456978fb78 51
lucastai 23:08456978fb78 52 t.reset();
lucastai 23:08456978fb78 53
lucastai 8:5924b2048a27 54 }
lucastai 8:5924b2048a27 55 }
lucastai 23:08456978fb78 56
lucastai 23:08456978fb78 57
lucastai 23:08456978fb78 58 void kbd_intrp(){
lucastai 23:08456978fb78 59 char a = pc.getc();
lucastai 23:08456978fb78 60
lucastai 23:08456978fb78 61 if(needs_num_input){
lucastai 23:08456978fb78 62 // DO O handling
lucastai 23:08456978fb78 63 needs_num_input = 0;
lucastai 23:08456978fb78 64 return;
lucastai 23:08456978fb78 65 }
lucastai 23:08456978fb78 66
lucastai 26:64e2bc7d544a 67 if(a == 'R'){
lucastai 23:08456978fb78 68 curr_mode = RANDOM;
lucastai 25:18923916215b 69 }else if(a == 'T'){
lucastai 25:18923916215b 70 curr_mode = TEST;
lucastai 25:18923916215b 71 }else if(a == 'M'){
lucastai 25:18923916215b 72 curr_mode = MANUAL;
lucastai 23:08456978fb78 73 }
lucastai 25:18923916215b 74
lucastai 26:64e2bc7d544a 75 if(a == 'A' && curr_mode == MANUAL){
lucastai 25:18923916215b 76 asense = 1;
lucastai 25:18923916215b 77 Thread::wait(10);
lucastai 25:18923916215b 78 asense = 0;
lucastai 25:18923916215b 79 }
lucastai 25:18923916215b 80
lucastai 26:64e2bc7d544a 81 if(a == 'V' && curr_mode == MANUAL){
lucastai 25:18923916215b 82 vsense = 1;
lucastai 25:18923916215b 83 Thread::wait(10);
lucastai 25:18923916215b 84 vsense = 0;
lucastai 25:18923916215b 85 }
lucastai 25:18923916215b 86
lucastai 23:08456978fb78 87
lucastai 23:08456978fb78 88
lucastai 23:08456978fb78 89
lucastai 8:5924b2048a27 90 }
lucastai 8:5924b2048a27 91
lucastai 23:08456978fb78 92
lucastai 23:08456978fb78 93
lucastai 8:5924b2048a27 94 // interrupt function
lucastai 8:5924b2048a27 95 void interrupt_and_run_test(){
lucastai 8:5924b2048a27 96 // zero timer, set for 1ms interrupt
lucastai 8:5924b2048a27 97
lucastai 8:5924b2048a27 98 // wait for atrial pulse
lucastai 8:5924b2048a27 99
lucastai 8:5924b2048a27 100 // check if timer was within event
lucastai 8:5924b2048a27 101
lucastai 8:5924b2048a27 102
lucastai 8:5924b2048a27 103 // send vsense
lucastai 8:5924b2048a27 104
lucastai 8:5924b2048a27 105
lucastai 8:5924b2048a27 106 // send asense
lucastai 8:5924b2048a27 107
lucastai 8:5924b2048a27 108 // check if timer was in event
lucastai 8:5924b2048a27 109
lucastai 8:5924b2048a27 110 // wait for vpace
lucastai 8:5924b2048a27 111
lucastai 8:5924b2048a27 112 // wait for atrial pulse
lucastai 8:5924b2048a27 113
lucastai 8:5924b2048a27 114 // check if timer was within event
lucastai 26:64e2bc7d544a 115 }