mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Committer:
lucastai
Date:
Wed Dec 02 05:24:01 2015 +0000
Revision:
5:8d9bcf25accb
Parent:
4:6d3ddf74b49a
Child:
6:315e6d6b1174
tests for LRI URI VRP

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lucastai 0:54ec65701097 1 #include "mbed.h"
lucastai 0:54ec65701097 2 #include "LPC17xx.h"
lucastai 0:54ec65701097 3 #include "TextLCD.h"
lucastai 0:54ec65701097 4 #include "rtos.h"
lucastai 0:54ec65701097 5 #include "Thread.h"
lucastai 0:54ec65701097 6
lucastai 0:54ec65701097 7 DigitalOut vsense(p23);
lucastai 0:54ec65701097 8 DigitalOut asense(p24);
lucastai 0:54ec65701097 9 DigitalIn apace(p22);
lucastai 0:54ec65701097 10 DigitalIn vpace(p21);
lucastai 0:54ec65701097 11
lucastai 4:6d3ddf74b49a 12 DigitalOut led_apace(LED1);
lucastai 4:6d3ddf74b49a 13 DigitalOut led_vpace(LED2);
lucastai 4:6d3ddf74b49a 14 DigitalOut led_asense(LED3);
lucastai 4:6d3ddf74b49a 15 DigitalOut led_vsense(LED4);
lucastai 4:6d3ddf74b49a 16
lucastai 0:54ec65701097 17 Serial serial_in(USBTX, USBRX);
lucastai 0:54ec65701097 18
lucastai 0:54ec65701097 19
lucastai 0:54ec65701097 20 int test_time_count;
lucastai 0:54ec65701097 21 int curr_test;
lucastai 5:8d9bcf25accb 22 int minwaitV = 200;
lucastai 5:8d9bcf25accb 23 int minwaitA = 400;
lucastai 0:54ec65701097 24
lucastai 0:54ec65701097 25 int needs_num_input = 0;
lucastai 0:54ec65701097 26
chadnach1 3:189e64d01258 27 enum mode {RANDOM,MANUAL,TEST};
lucastai 0:54ec65701097 28 mode test_curr_mode = RANDOM;
lucastai 0:54ec65701097 29 Timer t;
lucastai 0:54ec65701097 30
lucastai 0:54ec65701097 31
lucastai 5:8d9bcf25accb 32 void test_LRI(){
lucastai 5:8d9bcf25accb 33 Timer test_timer;
lucastai 5:8d9bcf25accb 34
lucastai 5:8d9bcf25accb 35 test_timer.start();
lucastai 5:8d9bcf25accb 36 // wait for next vpace
lucastai 5:8d9bcf25accb 37 while(vpace != 1 && vsense != 1){}
lucastai 5:8d9bcf25accb 38 serial_in.printf("LRI: The separation between Ventricle events was %i ", test_timer.read_ms());
lucastai 5:8d9bcf25accb 39
lucastai 5:8d9bcf25accb 40 }
lucastai 5:8d9bcf25accb 41
lucastai 5:8d9bcf25accb 42 void test_VRP(){
lucastai 5:8d9bcf25accb 43 Timer test_timer;
lucastai 5:8d9bcf25accb 44
lucastai 5:8d9bcf25accb 45 test_timer.start();
lucastai 5:8d9bcf25accb 46
lucastai 5:8d9bcf25accb 47 while(vpace != 1 || vsense != 1){}
lucastai 5:8d9bcf25accb 48 serial_in.printf("VRP: The separation between Ventricle events was %i ", test_timer.read_ms());
lucastai 5:8d9bcf25accb 49
lucastai 5:8d9bcf25accb 50
lucastai 5:8d9bcf25accb 51 }
lucastai 5:8d9bcf25accb 52
lucastai 5:8d9bcf25accb 53 void test_AVI(){
lucastai 5:8d9bcf25accb 54 Timer test_timer;
lucastai 5:8d9bcf25accb 55
lucastai 5:8d9bcf25accb 56 test_timer.start();
lucastai 5:8d9bcf25accb 57
lucastai 5:8d9bcf25accb 58 while(vpace != 1){}
lucastai 5:8d9bcf25accb 59 serial_in.printf("AVI: The separation between Atrial and Ventricle events was %i ", test_timer.read_ms());
lucastai 5:8d9bcf25accb 60
lucastai 5:8d9bcf25accb 61
lucastai 5:8d9bcf25accb 62 }
lucastai 5:8d9bcf25accb 63
lucastai 0:54ec65701097 64
lucastai 0:54ec65701097 65
lucastai 0:54ec65701097 66
chadnach1 3:189e64d01258 67 void random_heart(void const *args)
chadnach1 3:189e64d01258 68 {
lucastai 0:54ec65701097 69 t.reset();
lucastai 0:54ec65701097 70 t.start();
lucastai 4:6d3ddf74b49a 71 while(1){
chadnach1 3:189e64d01258 72 while(test_curr_mode == RANDOM) {
lucastai 0:54ec65701097 73 int r = rand();
chadnach1 3:189e64d01258 74 if(r%2 == 0) {
lucastai 5:8d9bcf25accb 75 serial_in.printf("timer was %i",t.read_ms());
chadnach1 3:189e64d01258 76 if(1) {
lucastai 4:6d3ddf74b49a 77 led_asense = 1;
lucastai 0:54ec65701097 78 asense = 1;
lucastai 5:8d9bcf25accb 79 serial_in.printf("| ASENSE FIRED |");
lucastai 0:54ec65701097 80 Thread::wait(10);
lucastai 0:54ec65701097 81 asense = 0;
lucastai 4:6d3ddf74b49a 82 led_asense = 0;
lucastai 2:4761ca8ba841 83 t.reset();
lucastai 2:4761ca8ba841 84
lucastai 5:8d9bcf25accb 85 }else{
lucastai 5:8d9bcf25accb 86 Thread::wait(100);
lucastai 0:54ec65701097 87 }
chadnach1 3:189e64d01258 88 } else {
chadnach1 3:189e64d01258 89 if(1) {
lucastai 4:6d3ddf74b49a 90 led_vsense = 1;
lucastai 0:54ec65701097 91 vsense = 1;
lucastai 5:8d9bcf25accb 92 serial_in.printf("| VSENSE FIRED | ");
lucastai 0:54ec65701097 93 Thread::wait(10);
lucastai 0:54ec65701097 94 vsense = 0;
lucastai 4:6d3ddf74b49a 95 led_vsense = 0;
lucastai 2:4761ca8ba841 96 t.reset();
lucastai 2:4761ca8ba841 97
lucastai 5:8d9bcf25accb 98 }else{
lucastai 5:8d9bcf25accb 99 Thread::wait(100);
lucastai 0:54ec65701097 100 }
lucastai 0:54ec65701097 101 }
lucastai 5:8d9bcf25accb 102
lucastai 5:8d9bcf25accb 103 Thread::wait(150);
lucastai 0:54ec65701097 104
lucastai 0:54ec65701097 105
lucastai 0:54ec65701097 106
lucastai 0:54ec65701097 107 }
lucastai 4:6d3ddf74b49a 108 }
lucastai 0:54ec65701097 109 }
lucastai 0:54ec65701097 110
lucastai 0:54ec65701097 111
chadnach1 3:189e64d01258 112 void kbd_intrp()
chadnach1 3:189e64d01258 113 {
lucastai 2:4761ca8ba841 114
lucastai 0:54ec65701097 115 char a = serial_in.getc();
lucastai 2:4761ca8ba841 116 serial_in.printf("char was " + a);
chadnach1 3:189e64d01258 117 if(needs_num_input) {
lucastai 0:54ec65701097 118 // DO O handling
lucastai 0:54ec65701097 119 needs_num_input = 0;
lucastai 0:54ec65701097 120 return;
lucastai 0:54ec65701097 121 }
lucastai 0:54ec65701097 122
chadnach1 3:189e64d01258 123 if(a == 'R') {
lucastai 0:54ec65701097 124 test_curr_mode = RANDOM;
chadnach1 3:189e64d01258 125 } else if(a == 'T') {
lucastai 0:54ec65701097 126 test_curr_mode = TEST;
chadnach1 3:189e64d01258 127 } else if(a == 'M') {
lucastai 0:54ec65701097 128 test_curr_mode = MANUAL;
lucastai 0:54ec65701097 129 }
chadnach1 3:189e64d01258 130
chadnach1 3:189e64d01258 131 if(a == 'A' && test_curr_mode == MANUAL) {
lucastai 0:54ec65701097 132 asense = 1;
lucastai 0:54ec65701097 133 Thread::wait(10);
lucastai 0:54ec65701097 134 asense = 0;
lucastai 0:54ec65701097 135 }
chadnach1 3:189e64d01258 136
chadnach1 3:189e64d01258 137 if(a == 'V' && test_curr_mode == MANUAL) {
lucastai 0:54ec65701097 138 vsense = 1;
lucastai 0:54ec65701097 139 Thread::wait(10);
lucastai 0:54ec65701097 140 vsense = 0;
lucastai 0:54ec65701097 141 }
chadnach1 3:189e64d01258 142
lucastai 0:54ec65701097 143 }
lucastai 0:54ec65701097 144
lucastai 4:6d3ddf74b49a 145 void rec_apace(){
lucastai 4:6d3ddf74b49a 146 led_apace = 1;
lucastai 5:8d9bcf25accb 147 serial_in.printf("| A FIRED |");
lucastai 4:6d3ddf74b49a 148 Thread::wait(10);
lucastai 5:8d9bcf25accb 149 test_AVI();
lucastai 4:6d3ddf74b49a 150 led_apace = 0;
lucastai 4:6d3ddf74b49a 151 }
lucastai 0:54ec65701097 152
lucastai 4:6d3ddf74b49a 153 void rec_vpace(){
lucastai 4:6d3ddf74b49a 154 led_vpace = 1;
lucastai 5:8d9bcf25accb 155 serial_in.printf("| V FIRED |");
lucastai 4:6d3ddf74b49a 156 Thread::wait(10);
lucastai 5:8d9bcf25accb 157 test_LRI();
lucastai 4:6d3ddf74b49a 158 led_vpace = 0;
lucastai 4:6d3ddf74b49a 159 }
lucastai 4:6d3ddf74b49a 160
lucastai 5:8d9bcf25accb 161 void heart_response1(void const *args){
lucastai 4:6d3ddf74b49a 162 while(1){
lucastai 4:6d3ddf74b49a 163 if(apace == 1){
lucastai 4:6d3ddf74b49a 164 rec_apace();
lucastai 4:6d3ddf74b49a 165 }
lucastai 5:8d9bcf25accb 166
lucastai 5:8d9bcf25accb 167 }
lucastai 5:8d9bcf25accb 168
lucastai 5:8d9bcf25accb 169 }
lucastai 5:8d9bcf25accb 170
lucastai 5:8d9bcf25accb 171 void heart_response2(void const *args){
lucastai 5:8d9bcf25accb 172 while(1){
lucastai 4:6d3ddf74b49a 173
lucastai 4:6d3ddf74b49a 174 if(vpace == 1){
lucastai 4:6d3ddf74b49a 175 rec_vpace();
lucastai 4:6d3ddf74b49a 176 }
lucastai 4:6d3ddf74b49a 177 }
lucastai 4:6d3ddf74b49a 178
lucastai 4:6d3ddf74b49a 179 }
lucastai 0:54ec65701097 180
lucastai 0:54ec65701097 181 // interrupt function
chadnach1 3:189e64d01258 182 void interrupt_and_run_test()
chadnach1 3:189e64d01258 183 {
lucastai 0:54ec65701097 184 // zero timer, set for 1ms interrupt
chadnach1 3:189e64d01258 185
lucastai 0:54ec65701097 186 // wait for atrial pulse
chadnach1 3:189e64d01258 187
lucastai 0:54ec65701097 188 // check if timer was within event
chadnach1 3:189e64d01258 189
chadnach1 3:189e64d01258 190
lucastai 0:54ec65701097 191 // send vsense
chadnach1 3:189e64d01258 192
chadnach1 3:189e64d01258 193
lucastai 0:54ec65701097 194 // send asense
chadnach1 3:189e64d01258 195
lucastai 0:54ec65701097 196 // check if timer was in event
lucastai 0:54ec65701097 197
lucastai 0:54ec65701097 198 // wait for vpace
chadnach1 3:189e64d01258 199
lucastai 0:54ec65701097 200 // wait for atrial pulse
chadnach1 3:189e64d01258 201
lucastai 0:54ec65701097 202 // check if timer was within event
chadnach1 3:189e64d01258 203 }
lucastai 0:54ec65701097 204
chadnach1 3:189e64d01258 205 int main(void)
chadnach1 3:189e64d01258 206 {
lucastai 5:8d9bcf25accb 207
lucastai 5:8d9bcf25accb 208
chadnach1 3:189e64d01258 209
lucastai 2:4761ca8ba841 210 Thread t3(random_heart, (void *)"");
lucastai 5:8d9bcf25accb 211 Thread t2(heart_response1, (void *)"");
lucastai 5:8d9bcf25accb 212 Thread t4(heart_response2, (void *)"");
lucastai 5:8d9bcf25accb 213
lucastai 2:4761ca8ba841 214
chadnach1 3:189e64d01258 215 char a = 'Z';
chadnach1 3:189e64d01258 216
chadnach1 3:189e64d01258 217 while(1) {
chadnach1 3:189e64d01258 218
chadnach1 3:189e64d01258 219 if(serial_in.readable()) {
chadnach1 3:189e64d01258 220 a = serial_in.getc();
lucastai 5:8d9bcf25accb 221 serial_in.printf("GOT %c!!",a);
lucastai 5:8d9bcf25accb 222 if(needs_num_input){
chadnach1 3:189e64d01258 223 // DO O handling
chadnach1 3:189e64d01258 224 needs_num_input = 0;
chadnach1 3:189e64d01258 225 }
lucastai 2:4761ca8ba841 226
chadnach1 3:189e64d01258 227 if(a == 'R') {
lucastai 5:8d9bcf25accb 228 serial_in.printf("GOT R!!");
chadnach1 3:189e64d01258 229 test_curr_mode = RANDOM;
chadnach1 3:189e64d01258 230 } else if(a == 'T') {
lucastai 5:8d9bcf25accb 231 serial_in.printf("GOT T!!");
chadnach1 3:189e64d01258 232 test_curr_mode = TEST;
lucastai 5:8d9bcf25accb 233
chadnach1 3:189e64d01258 234 } else if(a == 'M') {
lucastai 5:8d9bcf25accb 235 serial_in.printf("GOT M!!");
chadnach1 3:189e64d01258 236 test_curr_mode = MANUAL;
chadnach1 3:189e64d01258 237 }
chadnach1 3:189e64d01258 238
chadnach1 3:189e64d01258 239 if(a == 'A' && test_curr_mode == MANUAL) {
chadnach1 3:189e64d01258 240 asense = 1;
chadnach1 3:189e64d01258 241 Thread::wait(10);
chadnach1 3:189e64d01258 242 asense = 0;
chadnach1 3:189e64d01258 243 }
chadnach1 3:189e64d01258 244
chadnach1 3:189e64d01258 245 if(a == 'V' && test_curr_mode == MANUAL) {
chadnach1 3:189e64d01258 246 vsense = 1;
chadnach1 3:189e64d01258 247 Thread::wait(10);
chadnach1 3:189e64d01258 248 vsense = 0;
chadnach1 3:189e64d01258 249 }
lucastai 5:8d9bcf25accb 250
lucastai 5:8d9bcf25accb 251 while(serial_in.readable()){
lucastai 5:8d9bcf25accb 252 serial_in.printf("GOT TO CONSUME!!",a);
lucastai 5:8d9bcf25accb 253 serial_in.getc();
lucastai 5:8d9bcf25accb 254 }
chadnach1 3:189e64d01258 255
chadnach1 3:189e64d01258 256
chadnach1 3:189e64d01258 257 }
lucastai 0:54ec65701097 258 }
lucastai 5:8d9bcf25accb 259
lucastai 0:54ec65701097 260 }