Part of the Pacemaker Project; this models the Pacemaker.
Dependencies: mbed TextLCD mbed-rtos
PMTest.cpp@23:08456978fb78, 2015-11-30 (annotated)
- Committer:
- lucastai
- Date:
- Mon Nov 30 21:47:20 2015 +0000
- Revision:
- 23:08456978fb78
- Parent:
- 20:dc272bfaa276
- Child:
- 25:18923916215b
testing random heart;
Who changed what in which revision?
User | Revision | Line number | New 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 | 23:08456978fb78 | 67 | } |
lucastai | 23:08456978fb78 | 68 | |
lucastai | 23:08456978fb78 | 69 | |
lucastai | 23:08456978fb78 | 70 | |
lucastai | 8:5924b2048a27 | 71 | } |
lucastai | 8:5924b2048a27 | 72 | |
lucastai | 23:08456978fb78 | 73 | |
lucastai | 23:08456978fb78 | 74 | |
lucastai | 8:5924b2048a27 | 75 | // interrupt function |
lucastai | 8:5924b2048a27 | 76 | void interrupt_and_run_test(){ |
lucastai | 8:5924b2048a27 | 77 | // zero timer, set for 1ms interrupt |
lucastai | 8:5924b2048a27 | 78 | timer0_init(100000) |
lucastai | 8:5924b2048a27 | 79 | |
lucastai | 8:5924b2048a27 | 80 | // wait for atrial pulse |
lucastai | 8:5924b2048a27 | 81 | while(apace != 1}{} |
lucastai | 8:5924b2048a27 | 82 | |
lucastai | 8:5924b2048a27 | 83 | // check if timer was within event |
lucastai | 8:5924b2048a27 | 84 | |
lucastai | 8:5924b2048a27 | 85 | if(timer_count < testfunc[curr_test][0]){ |
lucastai | 8:5924b2048a27 | 86 | printf("ATRIAL PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n"); |
lucastai | 8:5924b2048a27 | 87 | } |
lucastai | 8:5924b2048a27 | 88 | |
lucastai | 8:5924b2048a27 | 89 | // send vsense |
lucastai | 8:5924b2048a27 | 90 | |
lucastai | 8:5924b2048a27 | 91 | while(timer_count < testfunc[curr_test][1]){}; |
lucastai | 8:5924b2048a27 | 92 | vpace = 1; |
lucastai | 8:5924b2048a27 | 93 | |
lucastai | 8:5924b2048a27 | 94 | // send asense |
lucastai | 8:5924b2048a27 | 95 | while(timer_count < testfunc[curr_test][2]){}; |
lucastai | 8:5924b2048a27 | 96 | apace = 1; |
lucastai | 8:5924b2048a27 | 97 | |
lucastai | 8:5924b2048a27 | 98 | // check if timer was in event |
lucastai | 8:5924b2048a27 | 99 | |
lucastai | 8:5924b2048a27 | 100 | // wait for vpace |
lucastai | 8:5924b2048a27 | 101 | |
lucastai | 8:5924b2048a27 | 102 | // wait for atrial pulse |
lucastai | 8:5924b2048a27 | 103 | while(vpace != 1}{} |
lucastai | 8:5924b2048a27 | 104 | |
lucastai | 8:5924b2048a27 | 105 | // check if timer was within event |
lucastai | 8:5924b2048a27 | 106 | |
lucastai | 8:5924b2048a27 | 107 | if(timer_count < testfunc[curr_test][0]){ |
lucastai | 8:5924b2048a27 | 108 | printf("VENT PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n"); |
chadnach1 | 20:dc272bfaa276 | 109 | } |