Part of the Pacemaker Project; this models the Pacemaker.

Dependencies:   mbed TextLCD mbed-rtos

Committer:
lucastai
Date:
Tue Dec 01 21:42:52 2015 +0000
Revision:
25:18923916215b
Parent:
23:08456978fb78
Child:
26:64e2bc7d544a
more random heart stuff;

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 8:5924b2048a27 12 int timer_count;
lucastai 8:5924b2048a27 13 int curr_test;
lucastai 23:08456978fb78 14 int minwaitV;
lucastai 23:08456978fb78 15 int minwaitA;
lucastai 23:08456978fb78 16
lucastai 23:08456978fb78 17 int needs_num_input = 0;
lucastai 23:08456978fb78 18
lucastai 23:08456978fb78 19 struct mode{RANDOM,MANUAL,TEST};
lucastai 23:08456978fb78 20 mode curr_mode = RANDOM;
lucastai 23:08456978fb78 21 Timer t;
lucastai 8:5924b2048a27 22
lucastai 8:5924b2048a27 23 int[][] testfunc;
lucastai 8:5924b2048a27 24
lucastai 23:08456978fb78 25
lucastai 23:08456978fb78 26
lucastai 23:08456978fb78 27
lucastai 23:08456978fb78 28 void random_heart(){
lucastai 23:08456978fb78 29 t.reset();
lucastai 23:08456978fb78 30 t.start();
lucastai 23:08456978fb78 31
lucastai 23:08456978fb78 32 while(curr_mode == RANDOM){
lucastai 23:08456978fb78 33 int r = rand();
lucastai 23:08456978fb78 34
lucastai 23:08456978fb78 35 if(r%2 == 0){
lucastai 23:08456978fb78 36 if(t.read() > minwaitA){
lucastai 23:08456978fb78 37 asense = 1;
lucastai 23:08456978fb78 38 Thread::wait(10);
lucastai 23:08456978fb78 39 asense = 0;
lucastai 23:08456978fb78 40 }
lucastai 23:08456978fb78 41 }else{
lucastai 23:08456978fb78 42 if(t.read() > minwaitV){
lucastai 23:08456978fb78 43 vsense = 1;
lucastai 23:08456978fb78 44 Thread::wait(10);
lucastai 23:08456978fb78 45 vsense = 0;
lucastai 23:08456978fb78 46 }
lucastai 23:08456978fb78 47 }
lucastai 23:08456978fb78 48
lucastai 23:08456978fb78 49
lucastai 23:08456978fb78 50 t.reset();
lucastai 23:08456978fb78 51
lucastai 8:5924b2048a27 52 }
lucastai 8:5924b2048a27 53 }
lucastai 23:08456978fb78 54
lucastai 23:08456978fb78 55
lucastai 23:08456978fb78 56 void kbd_intrp(){
lucastai 23:08456978fb78 57 char a = pc.getc();
lucastai 23:08456978fb78 58
lucastai 23:08456978fb78 59 if(needs_num_input){
lucastai 23:08456978fb78 60 // DO O handling
lucastai 23:08456978fb78 61 needs_num_input = 0;
lucastai 23:08456978fb78 62 return;
lucastai 23:08456978fb78 63 }
lucastai 23:08456978fb78 64
lucastai 23:08456978fb78 65 if(a = 'R'){
lucastai 23:08456978fb78 66 curr_mode = RANDOM;
lucastai 25:18923916215b 67 }else if(a == 'T'){
lucastai 25:18923916215b 68 curr_mode = TEST;
lucastai 25:18923916215b 69 }else if(a == 'M'){
lucastai 25:18923916215b 70 curr_mode = MANUAL;
lucastai 23:08456978fb78 71 }
lucastai 25:18923916215b 72
lucastai 25:18923916215b 73 if(a == 'A' && curr_mode = MANUAL){
lucastai 25:18923916215b 74 asense = 1;
lucastai 25:18923916215b 75 Thread::wait(10);
lucastai 25:18923916215b 76 asense = 0;
lucastai 25:18923916215b 77 }
lucastai 25:18923916215b 78
lucastai 25:18923916215b 79 if(a == 'V' && curr_mode = MANUAL){
lucastai 25:18923916215b 80 vsense = 1;
lucastai 25:18923916215b 81 Thread::wait(10);
lucastai 25:18923916215b 82 vsense = 0;
lucastai 25:18923916215b 83 }
lucastai 25:18923916215b 84
lucastai 23:08456978fb78 85
lucastai 23:08456978fb78 86
lucastai 23:08456978fb78 87
lucastai 8:5924b2048a27 88 }
lucastai 8:5924b2048a27 89
lucastai 23:08456978fb78 90
lucastai 23:08456978fb78 91
lucastai 8:5924b2048a27 92 // interrupt function
lucastai 8:5924b2048a27 93 void interrupt_and_run_test(){
lucastai 8:5924b2048a27 94 // zero timer, set for 1ms interrupt
lucastai 8:5924b2048a27 95 timer0_init(100000)
lucastai 8:5924b2048a27 96
lucastai 8:5924b2048a27 97 // wait for atrial pulse
lucastai 8:5924b2048a27 98 while(apace != 1}{}
lucastai 8:5924b2048a27 99
lucastai 8:5924b2048a27 100 // check if timer was within event
lucastai 8:5924b2048a27 101
lucastai 8:5924b2048a27 102 if(timer_count < testfunc[curr_test][0]){
lucastai 8:5924b2048a27 103 printf("ATRIAL PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n");
lucastai 8:5924b2048a27 104 }
lucastai 8:5924b2048a27 105
lucastai 8:5924b2048a27 106 // send vsense
lucastai 8:5924b2048a27 107
lucastai 8:5924b2048a27 108 while(timer_count < testfunc[curr_test][1]){};
lucastai 8:5924b2048a27 109 vpace = 1;
lucastai 8:5924b2048a27 110
lucastai 8:5924b2048a27 111 // send asense
lucastai 8:5924b2048a27 112 while(timer_count < testfunc[curr_test][2]){};
lucastai 8:5924b2048a27 113 apace = 1;
lucastai 8:5924b2048a27 114
lucastai 8:5924b2048a27 115 // check if timer was in event
lucastai 8:5924b2048a27 116
lucastai 8:5924b2048a27 117 // wait for vpace
lucastai 8:5924b2048a27 118
lucastai 8:5924b2048a27 119 // wait for atrial pulse
lucastai 8:5924b2048a27 120 while(vpace != 1}{}
lucastai 8:5924b2048a27 121
lucastai 8:5924b2048a27 122 // check if timer was within event
lucastai 8:5924b2048a27 123
lucastai 8:5924b2048a27 124 if(timer_count < testfunc[curr_test][0]){
lucastai 8:5924b2048a27 125 printf("VENT PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n");
chadnach1 20:dc272bfaa276 126 }