mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Committer:
chadnach1
Date:
Wed Dec 02 02:01:17 2015 +0000
Revision:
3:189e64d01258
Parent:
2:4761ca8ba841
Child:
4:6d3ddf74b49a
did small change

Who changed what in which revision?

UserRevisionLine numberNew 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
chadnach1 3:189e64d01258 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
chadnach1 3:189e64d01258 30 void random_heart(void const *args)
chadnach1 3:189e64d01258 31 {
lucastai 0:54ec65701097 32 t.reset();
lucastai 0:54ec65701097 33 t.start();
lucastai 0:54ec65701097 34
chadnach1 3:189e64d01258 35 while(test_curr_mode == RANDOM) {
lucastai 0:54ec65701097 36 int r = rand();
chadnach1 3:189e64d01258 37 if(r%2 == 0) {
lucastai 2:4761ca8ba841 38 serial_in.printf("timer was %i",t.read());
chadnach1 3:189e64d01258 39 if(1) {
lucastai 0:54ec65701097 40 asense = 1;
lucastai 2:4761ca8ba841 41 serial_in.printf("asense ");
lucastai 0:54ec65701097 42 Thread::wait(10);
lucastai 0:54ec65701097 43 asense = 0;
lucastai 2:4761ca8ba841 44 t.reset();
lucastai 2:4761ca8ba841 45
lucastai 0:54ec65701097 46 }
chadnach1 3:189e64d01258 47 } else {
chadnach1 3:189e64d01258 48 if(1) {
lucastai 0:54ec65701097 49 vsense = 1;
lucastai 2:4761ca8ba841 50 serial_in.printf("vsense ");
lucastai 0:54ec65701097 51 Thread::wait(10);
lucastai 0:54ec65701097 52 vsense = 0;
lucastai 2:4761ca8ba841 53 t.reset();
lucastai 2:4761ca8ba841 54
lucastai 0:54ec65701097 55 }
lucastai 0:54ec65701097 56 }
chadnach1 3:189e64d01258 57
lucastai 2:4761ca8ba841 58 Thread::wait(500);
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
chadnach1 3:189e64d01258 66 void kbd_intrp()
chadnach1 3:189e64d01258 67 {
lucastai 2:4761ca8ba841 68
lucastai 0:54ec65701097 69 char a = serial_in.getc();
lucastai 2:4761ca8ba841 70 serial_in.printf("char was " + a);
chadnach1 3:189e64d01258 71 if(needs_num_input) {
lucastai 0:54ec65701097 72 // DO O handling
lucastai 0:54ec65701097 73 needs_num_input = 0;
lucastai 0:54ec65701097 74 return;
lucastai 0:54ec65701097 75 }
lucastai 0:54ec65701097 76
chadnach1 3:189e64d01258 77 if(a == 'R') {
lucastai 0:54ec65701097 78 test_curr_mode = RANDOM;
chadnach1 3:189e64d01258 79 } else if(a == 'T') {
lucastai 0:54ec65701097 80 test_curr_mode = TEST;
chadnach1 3:189e64d01258 81 } else if(a == 'M') {
lucastai 0:54ec65701097 82 test_curr_mode = MANUAL;
lucastai 0:54ec65701097 83 }
chadnach1 3:189e64d01258 84
chadnach1 3:189e64d01258 85 if(a == 'A' && test_curr_mode == MANUAL) {
lucastai 0:54ec65701097 86 asense = 1;
lucastai 0:54ec65701097 87 Thread::wait(10);
lucastai 0:54ec65701097 88 asense = 0;
lucastai 0:54ec65701097 89 }
chadnach1 3:189e64d01258 90
chadnach1 3:189e64d01258 91 if(a == 'V' && test_curr_mode == MANUAL) {
lucastai 0:54ec65701097 92 vsense = 1;
lucastai 0:54ec65701097 93 Thread::wait(10);
lucastai 0:54ec65701097 94 vsense = 0;
lucastai 0:54ec65701097 95 }
chadnach1 3:189e64d01258 96
lucastai 0:54ec65701097 97 }
lucastai 0:54ec65701097 98
lucastai 0:54ec65701097 99
lucastai 0:54ec65701097 100
lucastai 0:54ec65701097 101 // interrupt function
chadnach1 3:189e64d01258 102 void interrupt_and_run_test()
chadnach1 3:189e64d01258 103 {
lucastai 0:54ec65701097 104 // zero timer, set for 1ms interrupt
chadnach1 3:189e64d01258 105
lucastai 0:54ec65701097 106 // wait for atrial pulse
chadnach1 3:189e64d01258 107
lucastai 0:54ec65701097 108 // check if timer was within event
chadnach1 3:189e64d01258 109
chadnach1 3:189e64d01258 110
lucastai 0:54ec65701097 111 // send vsense
chadnach1 3:189e64d01258 112
chadnach1 3:189e64d01258 113
lucastai 0:54ec65701097 114 // send asense
chadnach1 3:189e64d01258 115
lucastai 0:54ec65701097 116 // check if timer was in event
lucastai 0:54ec65701097 117
lucastai 0:54ec65701097 118 // wait for vpace
chadnach1 3:189e64d01258 119
lucastai 0:54ec65701097 120 // wait for atrial pulse
chadnach1 3:189e64d01258 121
lucastai 0:54ec65701097 122 // check if timer was within event
chadnach1 3:189e64d01258 123 }
lucastai 0:54ec65701097 124
chadnach1 3:189e64d01258 125 int main(void)
chadnach1 3:189e64d01258 126 {
chadnach1 3:189e64d01258 127
lucastai 2:4761ca8ba841 128 Thread t3(random_heart, (void *)"");
lucastai 2:4761ca8ba841 129
chadnach1 3:189e64d01258 130 char a = 'Z';
chadnach1 3:189e64d01258 131
chadnach1 3:189e64d01258 132 while(1) {
chadnach1 3:189e64d01258 133
chadnach1 3:189e64d01258 134 if(serial_in.readable()) {
chadnach1 3:189e64d01258 135 a = serial_in.getc();
chadnach1 3:189e64d01258 136 serial_in.printf("char was " + a);
chadnach1 3:189e64d01258 137 if(needs_num_input) {
chadnach1 3:189e64d01258 138 // DO O handling
chadnach1 3:189e64d01258 139 needs_num_input = 0;
chadnach1 3:189e64d01258 140 }
lucastai 2:4761ca8ba841 141
chadnach1 3:189e64d01258 142 if(a == 'R') {
chadnach1 3:189e64d01258 143 test_curr_mode = RANDOM;
chadnach1 3:189e64d01258 144 } else if(a == 'T') {
chadnach1 3:189e64d01258 145 test_curr_mode = TEST;
chadnach1 3:189e64d01258 146 } else if(a == 'M') {
chadnach1 3:189e64d01258 147 test_curr_mode = MANUAL;
chadnach1 3:189e64d01258 148 }
chadnach1 3:189e64d01258 149
chadnach1 3:189e64d01258 150 if(a == 'A' && test_curr_mode == MANUAL) {
chadnach1 3:189e64d01258 151 asense = 1;
chadnach1 3:189e64d01258 152 Thread::wait(10);
chadnach1 3:189e64d01258 153 asense = 0;
chadnach1 3:189e64d01258 154 }
chadnach1 3:189e64d01258 155
chadnach1 3:189e64d01258 156 if(a == 'V' && test_curr_mode == MANUAL) {
chadnach1 3:189e64d01258 157 vsense = 1;
chadnach1 3:189e64d01258 158 Thread::wait(10);
chadnach1 3:189e64d01258 159 vsense = 0;
chadnach1 3:189e64d01258 160 }
chadnach1 3:189e64d01258 161
chadnach1 3:189e64d01258 162
chadnach1 3:189e64d01258 163 }
lucastai 0:54ec65701097 164 }
lucastai 0:54ec65701097 165 }