![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Part of the Pacemaker Project; this models the Pacemaker.
Dependencies: mbed TextLCD mbed-rtos
PMTest.cpp@22:365d51eb3783, 2015-11-30 (annotated)
- Committer:
- lucastai
- Date:
- Mon Nov 30 21:36:01 2015 +0000
- Revision:
- 22:365d51eb3783
- Parent:
- 8:5924b2048a27
added to pm test;
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); |
lucastai | 8:5924b2048a27 | 9 | DigitalIn apace(p22): |
lucastai | 8:5924b2048a27 | 10 | DigitalIn vpace(p21): |
lucastai | 8:5924b2048a27 | 11 | |
lucastai | 8:5924b2048a27 | 12 | int timer_count; |
lucastai | 8:5924b2048a27 | 13 | int curr_test; |
lucastai | 22:365d51eb3783 | 14 | int obs_int; |
lucastai | 22:365d51eb3783 | 15 | |
lucastai | 22:365d51eb3783 | 16 | Timer t; |
lucastai | 22:365d51eb3783 | 17 | |
lucastai | 22:365d51eb3783 | 18 | struct mode{RANDOM,MANUAL,TEST}; |
lucastai | 22:365d51eb3783 | 19 | |
lucastai | 22:365d51eb3783 | 20 | // state variables |
lucastai | 22:365d51eb3783 | 21 | mode current_mode = RANDOM; |
lucastai | 8:5924b2048a27 | 22 | |
lucastai | 8:5924b2048a27 | 23 | int[][] testfunc; |
lucastai | 8:5924b2048a27 | 24 | |
lucastai | 22:365d51eb3783 | 25 | void random_heart(){ |
lucastai | 22:365d51eb3783 | 26 | t.reset(); |
lucastai | 22:365d51eb3783 | 27 | t.start(); |
lucastai | 22:365d51eb3783 | 28 | |
lucastai | 22:365d51eb3783 | 29 | while(curr_mode == NORMAL){ |
lucastai | 22:365d51eb3783 | 30 | if(rand()% 2 == 1){ |
lucastai | 22:365d51eb3783 | 31 | if(t.read() < minwaitA){ |
lucastai | 22:365d51eb3783 | 32 | asense = 1; |
lucastai | 22:365d51eb3783 | 33 | Thread::wait(10); |
lucastai | 22:365d51eb3783 | 34 | asense = 0; |
lucastai | 22:365d51eb3783 | 35 | } |
lucastai | 22:365d51eb3783 | 36 | }else{ |
lucastai | 22:365d51eb3783 | 37 | if(t.read() < minwaitV){ |
lucastai | 22:365d51eb3783 | 38 | vsense = 1; |
lucastai | 22:365d51eb3783 | 39 | Thread::wait(10); |
lucastai | 22:365d51eb3783 | 40 | vsense = 0; |
lucastai | 22:365d51eb3783 | 41 | } |
lucastai | 22:365d51eb3783 | 42 | |
lucastai | 22:365d51eb3783 | 43 | } |
lucastai | 8:5924b2048a27 | 44 | } |
lucastai | 8:5924b2048a27 | 45 | } |
lucastai | 22:365d51eb3783 | 46 | |
lucastai | 22:365d51eb3783 | 47 | |
lucastai | 22:365d51eb3783 | 48 | void man_interrupt(){ |
lucastai | 22:365d51eb3783 | 49 | char a = pc.getc(); |
lucastai | 22:365d51eb3783 | 50 | |
lucastai | 22:365d51eb3783 | 51 | if (keyboard_needs_numeric) { |
lucastai | 22:365d51eb3783 | 52 | if (a >= '0' && a <= '9') { |
lucastai | 22:365d51eb3783 | 53 | // update observation interval |
lucastai | 22:365d51eb3783 | 54 | obs_int = (a - '0' + 1) * 5; |
lucastai | 22:365d51eb3783 | 55 | } else { |
lucastai | 22:365d51eb3783 | 56 | pc.printf("Expected numeric key\n"); |
lucastai | 22:365d51eb3783 | 57 | } |
lucastai | 22:365d51eb3783 | 58 | keyboard_needs_numeric = 0; |
lucastai | 22:365d51eb3783 | 59 | }else if(a == 'N'){ |
lucastai | 22:365d51eb3783 | 60 | curr_mode = NORMAL; |
lucastai | 22:365d51eb3783 | 61 | }else if (a == 'M'){ |
lucastai | 22:365d51eb3783 | 62 | curr_mode = MANUAL; |
lucastai | 22:365d51eb3783 | 63 | }else if (a == 'T'){ |
lucastai | 22:365d51eb3783 | 64 | curr_mode = TEST; |
lucastai | 22:365d51eb3783 | 65 | }else if (a == 'O'){ |
lucastai | 22:365d51eb3783 | 66 | keyboard_needs_number = 1; |
lucastai | 22:365d51eb3783 | 67 | } |
lucastai | 22:365d51eb3783 | 68 | |
lucastai | 22:365d51eb3783 | 69 | if(curr_mode == MANUAL){ |
lucastai | 22:365d51eb3783 | 70 | if(a == 'A'){ |
lucastai | 22:365d51eb3783 | 71 | asense = 1; |
lucastai | 22:365d51eb3783 | 72 | Thread::wait(10); |
lucastai | 22:365d51eb3783 | 73 | asense = 0; |
lucastai | 22:365d51eb3783 | 74 | }else if(a == "V"){ |
lucastai | 22:365d51eb3783 | 75 | vsense = 1; |
lucastai | 22:365d51eb3783 | 76 | Thread::wait(10); |
lucastai | 22:365d51eb3783 | 77 | vsense = 0; |
lucastai | 22:365d51eb3783 | 78 | } |
lucastai | 22:365d51eb3783 | 79 | } |
lucastai | 22:365d51eb3783 | 80 | |
lucastai | 22:365d51eb3783 | 81 | keyboard_needs_number = 0; |
lucastai | 22:365d51eb3783 | 82 | |
lucastai | 8:5924b2048a27 | 83 | } |
lucastai | 8:5924b2048a27 | 84 | |
lucastai | 8:5924b2048a27 | 85 | // interrupt function |
lucastai | 8:5924b2048a27 | 86 | void interrupt_and_run_test(){ |
lucastai | 8:5924b2048a27 | 87 | // zero timer, set for 1ms interrupt |
lucastai | 8:5924b2048a27 | 88 | timer0_init(100000) |
lucastai | 8:5924b2048a27 | 89 | |
lucastai | 8:5924b2048a27 | 90 | // wait for atrial pulse |
lucastai | 8:5924b2048a27 | 91 | while(apace != 1}{} |
lucastai | 8:5924b2048a27 | 92 | |
lucastai | 8:5924b2048a27 | 93 | // check if timer was within event |
lucastai | 8:5924b2048a27 | 94 | |
lucastai | 8:5924b2048a27 | 95 | if(timer_count < testfunc[curr_test][0]){ |
lucastai | 8:5924b2048a27 | 96 | printf("ATRIAL PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n"); |
lucastai | 8:5924b2048a27 | 97 | } |
lucastai | 8:5924b2048a27 | 98 | |
lucastai | 8:5924b2048a27 | 99 | // send vsense |
lucastai | 8:5924b2048a27 | 100 | |
lucastai | 8:5924b2048a27 | 101 | while(timer_count < testfunc[curr_test][1]){}; |
lucastai | 8:5924b2048a27 | 102 | vpace = 1; |
lucastai | 8:5924b2048a27 | 103 | |
lucastai | 8:5924b2048a27 | 104 | // send asense |
lucastai | 8:5924b2048a27 | 105 | while(timer_count < testfunc[curr_test][2]){}; |
lucastai | 8:5924b2048a27 | 106 | apace = 1; |
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 | while(vpace != 1}{} |
lucastai | 8:5924b2048a27 | 114 | |
lucastai | 8:5924b2048a27 | 115 | // check if timer was within event |
lucastai | 8:5924b2048a27 | 116 | |
lucastai | 8:5924b2048a27 | 117 | if(timer_count < testfunc[curr_test][0]){ |
lucastai | 8:5924b2048a27 | 118 | printf("VENT PULSE FOR TEST " + curr_test + " WAS WITHIN BOUNDS\n"); |
lucastai | 8:5924b2048a27 | 119 | } |
lucastai | 8:5924b2048a27 | 120 | |
lucastai | 8:5924b2048a27 | 121 | |
lucastai | 8:5924b2048a27 | 122 | |
lucastai | 8:5924b2048a27 | 123 | |
lucastai | 8:5924b2048a27 | 124 |