mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Committer:
chadnach1
Date:
Wed Dec 02 00:56:35 2015 +0000
Revision:
1:c0fdd901d5d5
Parent:
0:54ec65701097
Test commit to PMTest

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 0:54ec65701097 17 int minwaitV;
lucastai 0:54ec65701097 18 int minwaitA;
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 void random_heart(){
lucastai 0:54ec65701097 27 t.reset();
lucastai 0:54ec65701097 28 t.start();
lucastai 0:54ec65701097 29
lucastai 0:54ec65701097 30 while(test_curr_mode == RANDOM){
lucastai 0:54ec65701097 31 int r = rand();
lucastai 0:54ec65701097 32
lucastai 0:54ec65701097 33 if(r%2 == 0){
lucastai 0:54ec65701097 34 if(t.read() > minwaitA){
lucastai 0:54ec65701097 35 asense = 1;
lucastai 0:54ec65701097 36 Thread::wait(10);
lucastai 0:54ec65701097 37 asense = 0;
lucastai 0:54ec65701097 38 }
chadnach1 1:c0fdd901d5d5 39 } else {
chadnach1 1:c0fdd901d5d5 40
lucastai 0:54ec65701097 41 if(t.read() > minwaitV){
lucastai 0:54ec65701097 42 vsense = 1;
lucastai 0:54ec65701097 43 Thread::wait(10);
lucastai 0:54ec65701097 44 vsense = 0;
lucastai 0:54ec65701097 45 }
lucastai 0:54ec65701097 46 }
chadnach1 1:c0fdd901d5d5 47
lucastai 0:54ec65701097 48 t.reset();
lucastai 0:54ec65701097 49 }
lucastai 0:54ec65701097 50 }
lucastai 0:54ec65701097 51
lucastai 0:54ec65701097 52 void kbd_intrp(){
lucastai 0:54ec65701097 53 char a = serial_in.getc();
lucastai 0:54ec65701097 54
lucastai 0:54ec65701097 55 if(needs_num_input){
lucastai 0:54ec65701097 56 // DO O handling
lucastai 0:54ec65701097 57 needs_num_input = 0;
lucastai 0:54ec65701097 58 return;
lucastai 0:54ec65701097 59 }
lucastai 0:54ec65701097 60
lucastai 0:54ec65701097 61 if(a == 'R'){
lucastai 0:54ec65701097 62 test_curr_mode = RANDOM;
lucastai 0:54ec65701097 63 }else if(a == 'T'){
lucastai 0:54ec65701097 64 test_curr_mode = TEST;
lucastai 0:54ec65701097 65 }else if(a == 'M'){
lucastai 0:54ec65701097 66 test_curr_mode = MANUAL;
lucastai 0:54ec65701097 67 }
lucastai 0:54ec65701097 68
lucastai 0:54ec65701097 69 if(a == 'A' && test_curr_mode == MANUAL){
lucastai 0:54ec65701097 70 asense = 1;
lucastai 0:54ec65701097 71 Thread::wait(10);
lucastai 0:54ec65701097 72 asense = 0;
lucastai 0:54ec65701097 73 }
lucastai 0:54ec65701097 74
lucastai 0:54ec65701097 75 if(a == 'V' && test_curr_mode == MANUAL){
lucastai 0:54ec65701097 76 vsense = 1;
lucastai 0:54ec65701097 77 Thread::wait(10);
lucastai 0:54ec65701097 78 vsense = 0;
lucastai 0:54ec65701097 79 }
lucastai 0:54ec65701097 80
lucastai 0:54ec65701097 81 }
lucastai 0:54ec65701097 82
lucastai 0:54ec65701097 83 // interrupt function
lucastai 0:54ec65701097 84 void interrupt_and_run_test(){
lucastai 0:54ec65701097 85 // zero timer, set for 1ms interrupt
lucastai 0:54ec65701097 86
lucastai 0:54ec65701097 87 // wait for atrial pulse
lucastai 0:54ec65701097 88
lucastai 0:54ec65701097 89 // check if timer was within event
lucastai 0:54ec65701097 90
lucastai 0:54ec65701097 91
lucastai 0:54ec65701097 92 // send vsense
lucastai 0:54ec65701097 93
lucastai 0:54ec65701097 94
lucastai 0:54ec65701097 95 // send asense
lucastai 0:54ec65701097 96
lucastai 0:54ec65701097 97 // check if timer was in event
lucastai 0:54ec65701097 98
lucastai 0:54ec65701097 99 // wait for vpace
lucastai 0:54ec65701097 100
lucastai 0:54ec65701097 101 // wait for atrial pulse
lucastai 0:54ec65701097 102
lucastai 0:54ec65701097 103 // check if timer was within event
lucastai 0:54ec65701097 104 }
lucastai 0:54ec65701097 105
lucastai 0:54ec65701097 106 int main(void){
lucastai 0:54ec65701097 107 while(1){
lucastai 0:54ec65701097 108 random_heart();
lucastai 0:54ec65701097 109 }
lucastai 0:54ec65701097 110 }