mbed heart
Dependencies: TextLCD mbed-rtos mbed
PMTest.cpp@8:0f92ac2b9d0e, 2015-12-02 (annotated)
- Committer:
- lucastai
- Date:
- Wed Dec 02 20:41:31 2015 +0000
- Revision:
- 8:0f92ac2b9d0e
- Parent:
- 7:1c32e8f6bde8
- Child:
- 9:917f6d407d78
Manual Mode works
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 | 8:0f92ac2b9d0e | 12 | Ticker rate_monitor; |
lucastai | 8:0f92ac2b9d0e | 13 | |
lucastai | 8:0f92ac2b9d0e | 14 | |
lucastai | 8:0f92ac2b9d0e | 15 | TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7 |
lucastai | 8:0f92ac2b9d0e | 16 | |
lucastai | 8:0f92ac2b9d0e | 17 | volatile int beats = 0; |
lucastai | 8:0f92ac2b9d0e | 18 | volatile double bpm = 0; |
lucastai | 8:0f92ac2b9d0e | 19 | |
lucastai | 4:6d3ddf74b49a | 20 | DigitalOut led_apace(LED1); |
lucastai | 4:6d3ddf74b49a | 21 | DigitalOut led_vpace(LED2); |
lucastai | 4:6d3ddf74b49a | 22 | DigitalOut led_asense(LED3); |
lucastai | 4:6d3ddf74b49a | 23 | DigitalOut led_vsense(LED4); |
lucastai | 4:6d3ddf74b49a | 24 | |
lucastai | 0:54ec65701097 | 25 | Serial serial_in(USBTX, USBRX); |
lucastai | 0:54ec65701097 | 26 | |
lucastai | 0:54ec65701097 | 27 | |
lucastai | 0:54ec65701097 | 28 | int test_time_count; |
lucastai | 0:54ec65701097 | 29 | int curr_test; |
lucastai | 5:8d9bcf25accb | 30 | int minwaitV = 200; |
lucastai | 5:8d9bcf25accb | 31 | int minwaitA = 400; |
lucastai | 0:54ec65701097 | 32 | |
lucastai | 8:0f92ac2b9d0e | 33 | int obs_int = 10; |
lucastai | 8:0f92ac2b9d0e | 34 | |
lucastai | 8:0f92ac2b9d0e | 35 | |
lucastai | 0:54ec65701097 | 36 | int needs_num_input = 0; |
lucastai | 0:54ec65701097 | 37 | |
chadnach1 | 3:189e64d01258 | 38 | enum mode {RANDOM,MANUAL,TEST}; |
lucastai | 0:54ec65701097 | 39 | mode test_curr_mode = RANDOM; |
lucastai | 0:54ec65701097 | 40 | Timer t; |
lucastai | 0:54ec65701097 | 41 | |
lucastai | 0:54ec65701097 | 42 | |
lucastai | 5:8d9bcf25accb | 43 | void test_LRI(){ |
lucastai | 5:8d9bcf25accb | 44 | Timer test_timer; |
lucastai | 5:8d9bcf25accb | 45 | |
lucastai | 5:8d9bcf25accb | 46 | test_timer.start(); |
lucastai | 5:8d9bcf25accb | 47 | // wait for next vpace |
lucastai | 6:315e6d6b1174 | 48 | while(vpace != 1){} |
lucastai | 5:8d9bcf25accb | 49 | serial_in.printf("LRI: The separation between Ventricle events was %i ", test_timer.read_ms()); |
lucastai | 5:8d9bcf25accb | 50 | |
lucastai | 5:8d9bcf25accb | 51 | } |
lucastai | 5:8d9bcf25accb | 52 | |
lucastai | 7:1c32e8f6bde8 | 53 | void test_PVARP(){ |
lucastai | 7:1c32e8f6bde8 | 54 | Timer test_timer; |
lucastai | 7:1c32e8f6bde8 | 55 | |
lucastai | 7:1c32e8f6bde8 | 56 | test_timer.start(); |
lucastai | 7:1c32e8f6bde8 | 57 | |
lucastai | 7:1c32e8f6bde8 | 58 | while(apace != 1){} |
lucastai | 7:1c32e8f6bde8 | 59 | serial_in.printf("PVARP: The separation between Ventricular and Atrial events was %i ", test_timer.read_ms()); |
lucastai | 7:1c32e8f6bde8 | 60 | |
lucastai | 7:1c32e8f6bde8 | 61 | |
lucastai | 7:1c32e8f6bde8 | 62 | } |
lucastai | 7:1c32e8f6bde8 | 63 | |
lucastai | 5:8d9bcf25accb | 64 | void test_VRP(){ |
lucastai | 5:8d9bcf25accb | 65 | Timer test_timer; |
lucastai | 5:8d9bcf25accb | 66 | |
lucastai | 5:8d9bcf25accb | 67 | test_timer.start(); |
lucastai | 5:8d9bcf25accb | 68 | |
lucastai | 5:8d9bcf25accb | 69 | while(vpace != 1 || vsense != 1){} |
lucastai | 5:8d9bcf25accb | 70 | serial_in.printf("VRP: The separation between Ventricle events was %i ", test_timer.read_ms()); |
lucastai | 5:8d9bcf25accb | 71 | |
lucastai | 5:8d9bcf25accb | 72 | |
lucastai | 5:8d9bcf25accb | 73 | } |
lucastai | 5:8d9bcf25accb | 74 | |
lucastai | 7:1c32e8f6bde8 | 75 | |
lucastai | 5:8d9bcf25accb | 76 | void test_AVI(){ |
lucastai | 5:8d9bcf25accb | 77 | Timer test_timer; |
lucastai | 5:8d9bcf25accb | 78 | |
lucastai | 5:8d9bcf25accb | 79 | test_timer.start(); |
lucastai | 5:8d9bcf25accb | 80 | |
lucastai | 5:8d9bcf25accb | 81 | while(vpace != 1){} |
lucastai | 5:8d9bcf25accb | 82 | serial_in.printf("AVI: The separation between Atrial and Ventricle events was %i ", test_timer.read_ms()); |
lucastai | 5:8d9bcf25accb | 83 | |
lucastai | 5:8d9bcf25accb | 84 | |
lucastai | 5:8d9bcf25accb | 85 | } |
lucastai | 7:1c32e8f6bde8 | 86 | |
lucastai | 7:1c32e8f6bde8 | 87 | void test_AVI2(){ |
lucastai | 7:1c32e8f6bde8 | 88 | Timer test_timer; |
lucastai | 7:1c32e8f6bde8 | 89 | |
lucastai | 7:1c32e8f6bde8 | 90 | test_timer.start(); |
lucastai | 7:1c32e8f6bde8 | 91 | |
lucastai | 7:1c32e8f6bde8 | 92 | while(apace != 1){} |
lucastai | 7:1c32e8f6bde8 | 93 | serial_in.printf("LRI-AVI: The separation between Ventricle and Atrial events was %i ", test_timer.read_ms()); |
lucastai | 7:1c32e8f6bde8 | 94 | |
lucastai | 7:1c32e8f6bde8 | 95 | |
lucastai | 7:1c32e8f6bde8 | 96 | } |
lucastai | 5:8d9bcf25accb | 97 | |
lucastai | 0:54ec65701097 | 98 | |
lucastai | 0:54ec65701097 | 99 | |
lucastai | 0:54ec65701097 | 100 | |
chadnach1 | 3:189e64d01258 | 101 | void random_heart(void const *args) |
chadnach1 | 3:189e64d01258 | 102 | { |
lucastai | 0:54ec65701097 | 103 | t.reset(); |
lucastai | 0:54ec65701097 | 104 | t.start(); |
lucastai | 4:6d3ddf74b49a | 105 | while(1){ |
chadnach1 | 3:189e64d01258 | 106 | while(test_curr_mode == RANDOM) { |
lucastai | 0:54ec65701097 | 107 | int r = rand(); |
chadnach1 | 3:189e64d01258 | 108 | if(r%2 == 0) { |
lucastai | 5:8d9bcf25accb | 109 | serial_in.printf("timer was %i",t.read_ms()); |
chadnach1 | 3:189e64d01258 | 110 | if(1) { |
lucastai | 4:6d3ddf74b49a | 111 | led_asense = 1; |
lucastai | 0:54ec65701097 | 112 | asense = 1; |
lucastai | 5:8d9bcf25accb | 113 | serial_in.printf("| ASENSE FIRED |"); |
lucastai | 0:54ec65701097 | 114 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 115 | asense = 0; |
lucastai | 4:6d3ddf74b49a | 116 | led_asense = 0; |
lucastai | 2:4761ca8ba841 | 117 | t.reset(); |
lucastai | 2:4761ca8ba841 | 118 | |
lucastai | 5:8d9bcf25accb | 119 | }else{ |
lucastai | 5:8d9bcf25accb | 120 | Thread::wait(100); |
lucastai | 0:54ec65701097 | 121 | } |
chadnach1 | 3:189e64d01258 | 122 | } else { |
chadnach1 | 3:189e64d01258 | 123 | if(1) { |
lucastai | 4:6d3ddf74b49a | 124 | led_vsense = 1; |
lucastai | 0:54ec65701097 | 125 | vsense = 1; |
lucastai | 5:8d9bcf25accb | 126 | serial_in.printf("| VSENSE FIRED | "); |
lucastai | 0:54ec65701097 | 127 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 128 | vsense = 0; |
lucastai | 8:0f92ac2b9d0e | 129 | beats++; |
lucastai | 4:6d3ddf74b49a | 130 | led_vsense = 0; |
lucastai | 2:4761ca8ba841 | 131 | t.reset(); |
lucastai | 2:4761ca8ba841 | 132 | |
lucastai | 5:8d9bcf25accb | 133 | }else{ |
lucastai | 5:8d9bcf25accb | 134 | Thread::wait(100); |
lucastai | 0:54ec65701097 | 135 | } |
lucastai | 0:54ec65701097 | 136 | } |
lucastai | 5:8d9bcf25accb | 137 | |
lucastai | 5:8d9bcf25accb | 138 | Thread::wait(150); |
lucastai | 0:54ec65701097 | 139 | |
lucastai | 0:54ec65701097 | 140 | |
lucastai | 0:54ec65701097 | 141 | |
lucastai | 0:54ec65701097 | 142 | } |
lucastai | 4:6d3ddf74b49a | 143 | } |
lucastai | 0:54ec65701097 | 144 | } |
lucastai | 0:54ec65701097 | 145 | |
lucastai | 8:0f92ac2b9d0e | 146 | void pm_beat_update(void const *args){ |
lucastai | 8:0f92ac2b9d0e | 147 | while(1){ |
lucastai | 8:0f92ac2b9d0e | 148 | lcd.locate(0,0); |
lucastai | 8:0f92ac2b9d0e | 149 | lcd.printf("BPM: %.1f ", bpm); |
lucastai | 8:0f92ac2b9d0e | 150 | } |
lucastai | 8:0f92ac2b9d0e | 151 | } |
lucastai | 8:0f92ac2b9d0e | 152 | |
lucastai | 0:54ec65701097 | 153 | |
chadnach1 | 3:189e64d01258 | 154 | void kbd_intrp() |
chadnach1 | 3:189e64d01258 | 155 | { |
lucastai | 2:4761ca8ba841 | 156 | |
lucastai | 0:54ec65701097 | 157 | char a = serial_in.getc(); |
lucastai | 2:4761ca8ba841 | 158 | serial_in.printf("char was " + a); |
chadnach1 | 3:189e64d01258 | 159 | if(needs_num_input) { |
lucastai | 0:54ec65701097 | 160 | // DO O handling |
lucastai | 0:54ec65701097 | 161 | needs_num_input = 0; |
lucastai | 0:54ec65701097 | 162 | return; |
lucastai | 0:54ec65701097 | 163 | } |
lucastai | 0:54ec65701097 | 164 | |
chadnach1 | 3:189e64d01258 | 165 | if(a == 'R') { |
lucastai | 0:54ec65701097 | 166 | test_curr_mode = RANDOM; |
chadnach1 | 3:189e64d01258 | 167 | } else if(a == 'T') { |
lucastai | 0:54ec65701097 | 168 | test_curr_mode = TEST; |
chadnach1 | 3:189e64d01258 | 169 | } else if(a == 'M') { |
lucastai | 0:54ec65701097 | 170 | test_curr_mode = MANUAL; |
lucastai | 0:54ec65701097 | 171 | } |
chadnach1 | 3:189e64d01258 | 172 | |
chadnach1 | 3:189e64d01258 | 173 | if(a == 'A' && test_curr_mode == MANUAL) { |
lucastai | 0:54ec65701097 | 174 | asense = 1; |
lucastai | 0:54ec65701097 | 175 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 176 | asense = 0; |
lucastai | 0:54ec65701097 | 177 | } |
chadnach1 | 3:189e64d01258 | 178 | |
chadnach1 | 3:189e64d01258 | 179 | if(a == 'V' && test_curr_mode == MANUAL) { |
lucastai | 0:54ec65701097 | 180 | vsense = 1; |
lucastai | 0:54ec65701097 | 181 | Thread::wait(10); |
lucastai | 0:54ec65701097 | 182 | vsense = 0; |
lucastai | 0:54ec65701097 | 183 | } |
chadnach1 | 3:189e64d01258 | 184 | |
lucastai | 0:54ec65701097 | 185 | } |
lucastai | 0:54ec65701097 | 186 | |
lucastai | 4:6d3ddf74b49a | 187 | void rec_apace(){ |
lucastai | 4:6d3ddf74b49a | 188 | led_apace = 1; |
lucastai | 5:8d9bcf25accb | 189 | serial_in.printf("| A FIRED |"); |
lucastai | 4:6d3ddf74b49a | 190 | Thread::wait(10); |
lucastai | 4:6d3ddf74b49a | 191 | led_apace = 0; |
lucastai | 4:6d3ddf74b49a | 192 | } |
lucastai | 0:54ec65701097 | 193 | |
lucastai | 4:6d3ddf74b49a | 194 | void rec_vpace(){ |
lucastai | 4:6d3ddf74b49a | 195 | led_vpace = 1; |
lucastai | 5:8d9bcf25accb | 196 | serial_in.printf("| V FIRED |"); |
lucastai | 4:6d3ddf74b49a | 197 | Thread::wait(10); |
lucastai | 4:6d3ddf74b49a | 198 | led_vpace = 0; |
lucastai | 4:6d3ddf74b49a | 199 | } |
lucastai | 4:6d3ddf74b49a | 200 | |
lucastai | 5:8d9bcf25accb | 201 | void heart_response1(void const *args){ |
lucastai | 4:6d3ddf74b49a | 202 | while(1){ |
lucastai | 4:6d3ddf74b49a | 203 | if(apace == 1){ |
lucastai | 4:6d3ddf74b49a | 204 | rec_apace(); |
lucastai | 4:6d3ddf74b49a | 205 | } |
lucastai | 5:8d9bcf25accb | 206 | |
lucastai | 5:8d9bcf25accb | 207 | } |
lucastai | 5:8d9bcf25accb | 208 | |
lucastai | 5:8d9bcf25accb | 209 | } |
lucastai | 5:8d9bcf25accb | 210 | |
lucastai | 5:8d9bcf25accb | 211 | void heart_response2(void const *args){ |
lucastai | 5:8d9bcf25accb | 212 | while(1){ |
lucastai | 4:6d3ddf74b49a | 213 | |
lucastai | 4:6d3ddf74b49a | 214 | if(vpace == 1){ |
lucastai | 4:6d3ddf74b49a | 215 | rec_vpace(); |
lucastai | 4:6d3ddf74b49a | 216 | } |
lucastai | 4:6d3ddf74b49a | 217 | } |
lucastai | 4:6d3ddf74b49a | 218 | |
lucastai | 4:6d3ddf74b49a | 219 | } |
lucastai | 0:54ec65701097 | 220 | |
lucastai | 0:54ec65701097 | 221 | // interrupt function |
chadnach1 | 3:189e64d01258 | 222 | void interrupt_and_run_test() |
chadnach1 | 3:189e64d01258 | 223 | { |
lucastai | 0:54ec65701097 | 224 | // zero timer, set for 1ms interrupt |
chadnach1 | 3:189e64d01258 | 225 | |
lucastai | 0:54ec65701097 | 226 | // wait for atrial pulse |
chadnach1 | 3:189e64d01258 | 227 | |
lucastai | 0:54ec65701097 | 228 | // check if timer was within event |
chadnach1 | 3:189e64d01258 | 229 | |
chadnach1 | 3:189e64d01258 | 230 | |
lucastai | 0:54ec65701097 | 231 | // send vsense |
chadnach1 | 3:189e64d01258 | 232 | |
chadnach1 | 3:189e64d01258 | 233 | |
lucastai | 0:54ec65701097 | 234 | // send asense |
chadnach1 | 3:189e64d01258 | 235 | |
lucastai | 0:54ec65701097 | 236 | // check if timer was in event |
lucastai | 0:54ec65701097 | 237 | |
lucastai | 0:54ec65701097 | 238 | // wait for vpace |
chadnach1 | 3:189e64d01258 | 239 | |
lucastai | 0:54ec65701097 | 240 | // wait for atrial pulse |
chadnach1 | 3:189e64d01258 | 241 | |
lucastai | 0:54ec65701097 | 242 | // check if timer was within event |
chadnach1 | 3:189e64d01258 | 243 | } |
lucastai | 0:54ec65701097 | 244 | |
lucastai | 8:0f92ac2b9d0e | 245 | void update_display() { |
lucastai | 8:0f92ac2b9d0e | 246 | bpm = beats / (double) obs_int * 60; |
lucastai | 8:0f92ac2b9d0e | 247 | //reset count |
lucastai | 8:0f92ac2b9d0e | 248 | beats = 0; |
lucastai | 7:1c32e8f6bde8 | 249 | } |
lucastai | 7:1c32e8f6bde8 | 250 | |
chadnach1 | 3:189e64d01258 | 251 | int main(void) |
chadnach1 | 3:189e64d01258 | 252 | { |
lucastai | 5:8d9bcf25accb | 253 | |
lucastai | 5:8d9bcf25accb | 254 | |
lucastai | 8:0f92ac2b9d0e | 255 | |
chadnach1 | 3:189e64d01258 | 256 | |
lucastai | 2:4761ca8ba841 | 257 | Thread t3(random_heart, (void *)""); |
lucastai | 5:8d9bcf25accb | 258 | Thread t2(heart_response1, (void *)""); |
lucastai | 5:8d9bcf25accb | 259 | Thread t4(heart_response2, (void *)""); |
lucastai | 8:0f92ac2b9d0e | 260 | Thread t5(pm_beat_update, (void *)""); |
lucastai | 2:4761ca8ba841 | 261 | |
lucastai | 8:0f92ac2b9d0e | 262 | rate_monitor.attach(&update_display, obs_int); |
chadnach1 | 3:189e64d01258 | 263 | char a = 'Z'; |
chadnach1 | 3:189e64d01258 | 264 | |
lucastai | 8:0f92ac2b9d0e | 265 | |
chadnach1 | 3:189e64d01258 | 266 | while(1) { |
chadnach1 | 3:189e64d01258 | 267 | |
chadnach1 | 3:189e64d01258 | 268 | if(serial_in.readable()) { |
chadnach1 | 3:189e64d01258 | 269 | a = serial_in.getc(); |
lucastai | 5:8d9bcf25accb | 270 | serial_in.printf("GOT %c!!",a); |
lucastai | 8:0f92ac2b9d0e | 271 | |
lucastai | 8:0f92ac2b9d0e | 272 | if (needs_num_input) { |
lucastai | 8:0f92ac2b9d0e | 273 | if (a >= '0' && a <= '9') { |
lucastai | 8:0f92ac2b9d0e | 274 | // update observation interval |
lucastai | 8:0f92ac2b9d0e | 275 | obs_int = (a - '0' + 1) * 5; |
lucastai | 8:0f92ac2b9d0e | 276 | needs_num_input = 0; |
lucastai | 8:0f92ac2b9d0e | 277 | rate_monitor.attach(&update_display, obs_int); |
lucastai | 8:0f92ac2b9d0e | 278 | serial_in.printf("Set observation interval to %d seconds\n", obs_int); |
lucastai | 8:0f92ac2b9d0e | 279 | } else { |
lucastai | 8:0f92ac2b9d0e | 280 | serial_in.printf("Expected numeric key\n"); |
lucastai | 8:0f92ac2b9d0e | 281 | } |
chadnach1 | 3:189e64d01258 | 282 | } |
lucastai | 2:4761ca8ba841 | 283 | |
chadnach1 | 3:189e64d01258 | 284 | if(a == 'R') { |
lucastai | 5:8d9bcf25accb | 285 | serial_in.printf("GOT R!!"); |
chadnach1 | 3:189e64d01258 | 286 | test_curr_mode = RANDOM; |
chadnach1 | 3:189e64d01258 | 287 | } else if(a == 'T') { |
lucastai | 5:8d9bcf25accb | 288 | serial_in.printf("GOT T!!"); |
chadnach1 | 3:189e64d01258 | 289 | test_curr_mode = TEST; |
lucastai | 5:8d9bcf25accb | 290 | |
chadnach1 | 3:189e64d01258 | 291 | } else if(a == 'M') { |
lucastai | 5:8d9bcf25accb | 292 | serial_in.printf("GOT M!!"); |
chadnach1 | 3:189e64d01258 | 293 | test_curr_mode = MANUAL; |
chadnach1 | 3:189e64d01258 | 294 | } |
lucastai | 8:0f92ac2b9d0e | 295 | else if(a == 'O') { |
lucastai | 8:0f92ac2b9d0e | 296 | serial_in.printf("GOT obs!!"); |
lucastai | 8:0f92ac2b9d0e | 297 | needs_num_input = 1; |
lucastai | 8:0f92ac2b9d0e | 298 | } |
chadnach1 | 3:189e64d01258 | 299 | |
chadnach1 | 3:189e64d01258 | 300 | if(a == 'A' && test_curr_mode == MANUAL) { |
chadnach1 | 3:189e64d01258 | 301 | asense = 1; |
chadnach1 | 3:189e64d01258 | 302 | Thread::wait(10); |
chadnach1 | 3:189e64d01258 | 303 | asense = 0; |
chadnach1 | 3:189e64d01258 | 304 | } |
chadnach1 | 3:189e64d01258 | 305 | |
chadnach1 | 3:189e64d01258 | 306 | if(a == 'V' && test_curr_mode == MANUAL) { |
chadnach1 | 3:189e64d01258 | 307 | vsense = 1; |
chadnach1 | 3:189e64d01258 | 308 | Thread::wait(10); |
chadnach1 | 3:189e64d01258 | 309 | vsense = 0; |
chadnach1 | 3:189e64d01258 | 310 | } |
lucastai | 5:8d9bcf25accb | 311 | |
lucastai | 5:8d9bcf25accb | 312 | while(serial_in.readable()){ |
lucastai | 5:8d9bcf25accb | 313 | serial_in.printf("GOT TO CONSUME!!",a); |
lucastai | 5:8d9bcf25accb | 314 | serial_in.getc(); |
lucastai | 5:8d9bcf25accb | 315 | } |
chadnach1 | 3:189e64d01258 | 316 | |
chadnach1 | 3:189e64d01258 | 317 | |
chadnach1 | 3:189e64d01258 | 318 | } |
lucastai | 0:54ec65701097 | 319 | } |
lucastai | 8:0f92ac2b9d0e | 320 | |
lucastai | 5:8d9bcf25accb | 321 | |
lucastai | 0:54ec65701097 | 322 | } |