mbed heart
Dependencies: TextLCD mbed-rtos mbed
PMTest.cpp@2:4761ca8ba841, 2015-12-02 (annotated)
- Committer:
- lucastai
- Date:
- Wed Dec 02 01:58:23 2015 +0000
- Revision:
- 2:4761ca8ba841
- Parent:
- 0:54ec65701097
- Child:
- 3:189e64d01258
almost working;
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:54ec65701097 | 12 | Serial serial_in(USBTX, USBRX); |
lucastai | 0:54ec65701097 | 13 | |
lucastai | 0:54ec65701097 | 14 | |
lucastai | 0:54ec65701097 | 15 | int test_time_count; |
lucastai | 0:54ec65701097 | 16 | int curr_test; |
lucastai | 2:4761ca8ba841 | 17 | int minwaitV = 100000; |
lucastai | 2:4761ca8ba841 | 18 | int minwaitA = 200000; |
lucastai | 0:54ec65701097 | 19 | |
lucastai | 0:54ec65701097 | 20 | int needs_num_input = 0; |
lucastai | 0:54ec65701097 | 21 | |
lucastai | 0:54ec65701097 | 22 | enum mode{RANDOM,MANUAL,TEST}; |
lucastai | 0:54ec65701097 | 23 | mode test_curr_mode = RANDOM; |
lucastai | 0:54ec65701097 | 24 | Timer t; |
lucastai | 0:54ec65701097 | 25 | |
lucastai | 0:54ec65701097 | 26 | |
lucastai | 0:54ec65701097 | 27 | |
lucastai | 0:54ec65701097 | 28 | |
lucastai | 0:54ec65701097 | 29 | |
lucastai | 2:4761ca8ba841 | 30 | void random_heart(void const *args){ |
lucastai | 0:54ec65701097 | 31 | t.reset(); |
lucastai | 0:54ec65701097 | 32 | t.start(); |
lucastai | 0:54ec65701097 | 33 | |
lucastai | 0:54ec65701097 | 34 | while(test_curr_mode == RANDOM){ |
lucastai | 0:54ec65701097 | 35 | int r = rand(); |
lucastai | 0:54ec65701097 | 36 | if(r%2 == 0){ |
lucastai | 2:4761ca8ba841 | 37 | serial_in.printf("timer was %i",t.read()); |
lucastai | 2:4761ca8ba841 | 38 | if(1){ |
lucastai | 0:54ec65701097 | 39 | asense = 1; |
lucastai | 2:4761ca8ba841 | 40 | serial_in.printf("asense "); |
lucastai | 0:54ec65701097 | 41 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 42 | asense = 0; |
lucastai | 2:4761ca8ba841 | 43 | t.reset(); |
lucastai | 2:4761ca8ba841 | 44 | |
lucastai | 0:54ec65701097 | 45 | } |
lucastai | 0:54ec65701097 | 46 | }else{ |
lucastai | 2:4761ca8ba841 | 47 | if(1){ |
lucastai | 0:54ec65701097 | 48 | vsense = 1; |
lucastai | 2:4761ca8ba841 | 49 | serial_in.printf("vsense "); |
lucastai | 0:54ec65701097 | 50 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 51 | vsense = 0; |
lucastai | 2:4761ca8ba841 | 52 | t.reset(); |
lucastai | 2:4761ca8ba841 | 53 | |
lucastai | 0:54ec65701097 | 54 | } |
lucastai | 0:54ec65701097 | 55 | } |
lucastai | 2:4761ca8ba841 | 56 | |
lucastai | 2:4761ca8ba841 | 57 | Thread::wait(500); |
lucastai | 0:54ec65701097 | 58 | |
lucastai | 0:54ec65701097 | 59 | |
lucastai | 0:54ec65701097 | 60 | |
lucastai | 0:54ec65701097 | 61 | } |
lucastai | 0:54ec65701097 | 62 | } |
lucastai | 0:54ec65701097 | 63 | |
lucastai | 0:54ec65701097 | 64 | |
lucastai | 0:54ec65701097 | 65 | void kbd_intrp(){ |
lucastai | 2:4761ca8ba841 | 66 | |
lucastai | 0:54ec65701097 | 67 | char a = serial_in.getc(); |
lucastai | 2:4761ca8ba841 | 68 | serial_in.printf("char was " + a); |
lucastai | 0:54ec65701097 | 69 | if(needs_num_input){ |
lucastai | 0:54ec65701097 | 70 | // DO O handling |
lucastai | 0:54ec65701097 | 71 | needs_num_input = 0; |
lucastai | 0:54ec65701097 | 72 | return; |
lucastai | 0:54ec65701097 | 73 | } |
lucastai | 0:54ec65701097 | 74 | |
lucastai | 0:54ec65701097 | 75 | if(a == 'R'){ |
lucastai | 0:54ec65701097 | 76 | test_curr_mode = RANDOM; |
lucastai | 0:54ec65701097 | 77 | }else if(a == 'T'){ |
lucastai | 0:54ec65701097 | 78 | test_curr_mode = TEST; |
lucastai | 0:54ec65701097 | 79 | }else if(a == 'M'){ |
lucastai | 0:54ec65701097 | 80 | test_curr_mode = MANUAL; |
lucastai | 0:54ec65701097 | 81 | } |
lucastai | 0:54ec65701097 | 82 | |
lucastai | 0:54ec65701097 | 83 | if(a == 'A' && test_curr_mode == MANUAL){ |
lucastai | 0:54ec65701097 | 84 | asense = 1; |
lucastai | 0:54ec65701097 | 85 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 86 | asense = 0; |
lucastai | 0:54ec65701097 | 87 | } |
lucastai | 0:54ec65701097 | 88 | |
lucastai | 0:54ec65701097 | 89 | if(a == 'V' && test_curr_mode == MANUAL){ |
lucastai | 0:54ec65701097 | 90 | vsense = 1; |
lucastai | 0:54ec65701097 | 91 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 92 | vsense = 0; |
lucastai | 0:54ec65701097 | 93 | } |
lucastai | 0:54ec65701097 | 94 | |
lucastai | 0:54ec65701097 | 95 | } |
lucastai | 0:54ec65701097 | 96 | |
lucastai | 0:54ec65701097 | 97 | |
lucastai | 0:54ec65701097 | 98 | |
lucastai | 0:54ec65701097 | 99 | // interrupt function |
lucastai | 0:54ec65701097 | 100 | void interrupt_and_run_test(){ |
lucastai | 0:54ec65701097 | 101 | // zero timer, set for 1ms interrupt |
lucastai | 0:54ec65701097 | 102 | |
lucastai | 0:54ec65701097 | 103 | // wait for atrial pulse |
lucastai | 0:54ec65701097 | 104 | |
lucastai | 0:54ec65701097 | 105 | // check if timer was within event |
lucastai | 0:54ec65701097 | 106 | |
lucastai | 0:54ec65701097 | 107 | |
lucastai | 0:54ec65701097 | 108 | // send vsense |
lucastai | 0:54ec65701097 | 109 | |
lucastai | 0:54ec65701097 | 110 | |
lucastai | 0:54ec65701097 | 111 | // send asense |
lucastai | 0:54ec65701097 | 112 | |
lucastai | 0:54ec65701097 | 113 | // check if timer was in event |
lucastai | 0:54ec65701097 | 114 | |
lucastai | 0:54ec65701097 | 115 | // wait for vpace |
lucastai | 0:54ec65701097 | 116 | |
lucastai | 0:54ec65701097 | 117 | // wait for atrial pulse |
lucastai | 0:54ec65701097 | 118 | |
lucastai | 0:54ec65701097 | 119 | // check if timer was within event |
lucastai | 0:54ec65701097 | 120 | } |
lucastai | 0:54ec65701097 | 121 | |
lucastai | 0:54ec65701097 | 122 | int main(void){ |
lucastai | 2:4761ca8ba841 | 123 | |
lucastai | 2:4761ca8ba841 | 124 | Thread t3(random_heart, (void *)""); |
lucastai | 2:4761ca8ba841 | 125 | |
lucastai | 2:4761ca8ba841 | 126 | |
lucastai | 2:4761ca8ba841 | 127 | while(1){ |
lucastai | 2:4761ca8ba841 | 128 | |
lucastai | 2:4761ca8ba841 | 129 | if(serial_in.readable()){ |
lucastai | 2:4761ca8ba841 | 130 | char a = serial_in.getc(); |
lucastai | 2:4761ca8ba841 | 131 | serial_in.printf("char was " + a); |
lucastai | 2:4761ca8ba841 | 132 | if(needs_num_input){ |
lucastai | 2:4761ca8ba841 | 133 | // DO O handling |
lucastai | 2:4761ca8ba841 | 134 | needs_num_input = 0; |
lucastai | 2:4761ca8ba841 | 135 | } |
lucastai | 2:4761ca8ba841 | 136 | |
lucastai | 2:4761ca8ba841 | 137 | if(a == 'R'){ |
lucastai | 2:4761ca8ba841 | 138 | test_curr_mode = RANDOM; |
lucastai | 2:4761ca8ba841 | 139 | }else if(a == 'T'){ |
lucastai | 2:4761ca8ba841 | 140 | test_curr_mode = TEST; |
lucastai | 2:4761ca8ba841 | 141 | }else if(a == 'M'){ |
lucastai | 2:4761ca8ba841 | 142 | test_curr_mode = MANUAL; |
lucastai | 2:4761ca8ba841 | 143 | } |
lucastai | 2:4761ca8ba841 | 144 | |
lucastai | 2:4761ca8ba841 | 145 | if(a == 'A' && test_curr_mode == MANUAL){ |
lucastai | 2:4761ca8ba841 | 146 | asense = 1; |
lucastai | 2:4761ca8ba841 | 147 | Thread::wait(10); |
lucastai | 2:4761ca8ba841 | 148 | asense = 0; |
lucastai | 2:4761ca8ba841 | 149 | } |
lucastai | 2:4761ca8ba841 | 150 | |
lucastai | 2:4761ca8ba841 | 151 | if(a == 'V' && test_curr_mode == MANUAL){ |
lucastai | 2:4761ca8ba841 | 152 | vsense = 1; |
lucastai | 2:4761ca8ba841 | 153 | Thread::wait(10); |
lucastai | 2:4761ca8ba841 | 154 | vsense = 0; |
lucastai | 2:4761ca8ba841 | 155 | } |
lucastai | 2:4761ca8ba841 | 156 | |
lucastai | 2:4761ca8ba841 | 157 | |
lucastai | 2:4761ca8ba841 | 158 | } |
lucastai | 0:54ec65701097 | 159 | } |
lucastai | 0:54ec65701097 | 160 | } |