mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Committer:
lucastai
Date:
Wed Dec 02 00:50:28 2015 +0000
Revision:
0:54ec65701097
Child:
1:c0fdd901d5d5
Child:
2:4761ca8ba841
First heart commit;

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