Part of the Pacemaker Project; this models the Pacemaker.
Dependencies: mbed TextLCD mbed-rtos
PMTest.cpp@49:62ffd451b1c7, 2015-12-02 (annotated)
- Committer:
- amiche
- Date:
- Wed Dec 02 22:21:00 2015 +0000
- Revision:
- 49:62ffd451b1c7
- Parent:
- 28:5c5552cd472b
put back removed line
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 | 28:5c5552cd472b | 12 | Serial serial_in(USBTX, USBRX); |
lucastai | 26:64e2bc7d544a | 13 | |
lucastai | 26:64e2bc7d544a | 14 | |
lucastai | 28:5c5552cd472b | 15 | int test_time_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 | 28:5c5552cd472b | 23 | mode test_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 | 28:5c5552cd472b | 34 | while(test_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 | 28:5c5552cd472b | 59 | char a = serial_in.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 | 28:5c5552cd472b | 68 | test_curr_mode = RANDOM; |
lucastai | 25:18923916215b | 69 | }else if(a == 'T'){ |
lucastai | 28:5c5552cd472b | 70 | test_curr_mode = TEST; |
lucastai | 25:18923916215b | 71 | }else if(a == 'M'){ |
lucastai | 28:5c5552cd472b | 72 | test_curr_mode = MANUAL; |
lucastai | 23:08456978fb78 | 73 | } |
lucastai | 25:18923916215b | 74 | |
lucastai | 28:5c5552cd472b | 75 | if(a == 'A' && test_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 | 28:5c5552cd472b | 81 | if(a == 'V' && test_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 | } |