mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Revision:
5:8d9bcf25accb
Parent:
4:6d3ddf74b49a
Child:
6:315e6d6b1174
--- a/PMTest.cpp	Wed Dec 02 03:50:45 2015 +0000
+++ b/PMTest.cpp	Wed Dec 02 05:24:01 2015 +0000
@@ -19,8 +19,8 @@
 
 int test_time_count;
 int curr_test;
-int minwaitV = 100000;
-int minwaitA = 200000;
+int minwaitV = 200;
+int minwaitA = 400;
 
 int needs_num_input = 0;
 
@@ -29,6 +29,38 @@
 Timer t;
 
 
+void test_LRI(){
+    Timer test_timer;
+    
+    test_timer.start();
+    // wait for next vpace
+    while(vpace != 1 && vsense != 1){}
+    serial_in.printf("LRI: The separation between Ventricle events was %i ", test_timer.read_ms());
+    
+}
+
+void test_VRP(){
+    Timer test_timer;
+    
+    test_timer.start();
+    
+    while(vpace != 1 || vsense != 1){}
+    serial_in.printf("VRP: The separation between Ventricle events was %i ", test_timer.read_ms());
+    
+    
+}
+
+void test_AVI(){
+    Timer test_timer;
+    
+    test_timer.start();
+    
+    while(vpace != 1){}
+    serial_in.printf("AVI: The separation between Atrial and Ventricle events was %i ", test_timer.read_ms());
+    
+    
+}
+    
 
 
 
@@ -40,31 +72,35 @@
     while(test_curr_mode == RANDOM) {
         int r = rand();
         if(r%2 == 0) {
-            serial_in.printf("timer was %i",t.read());
+            serial_in.printf("timer was %i",t.read_ms());
             if(1) {
                 led_asense = 1;
                 asense = 1;
-                serial_in.printf("asense ");
+                serial_in.printf("| ASENSE FIRED |");
                 Thread::wait(10);
                 asense = 0;
                 led_asense = 0;
                 t.reset();
 
+            }else{
+                Thread::wait(100);
             }
         } else {
             if(1) {
                 led_vsense = 1;
                 vsense = 1;
-                serial_in.printf("vsense ");
+                serial_in.printf("| VSENSE FIRED | ");
                 Thread::wait(10);
                 vsense = 0;
                 led_vsense = 0;
                 t.reset();
 
+            }else{
+                Thread::wait(100);
             }
         }
-
-        Thread::wait(500);
+        
+        Thread::wait(150);
 
 
 
@@ -108,23 +144,32 @@
 
 void rec_apace(){
     led_apace = 1;
-    serial_in.printf("vssense fired\n");
+    serial_in.printf("| A FIRED |");
     Thread::wait(10);
+    test_AVI();
     led_apace = 0;   
 }
 
 void rec_vpace(){
     led_vpace = 1;
-    serial_in.printf("vssense fired\n");
+    serial_in.printf("| V FIRED |");
     Thread::wait(10);
+    test_LRI();
     led_vpace = 0;   
 }
 
-void heart_response(void const *args){
+void heart_response1(void const *args){
     while(1){
         if(apace == 1){
             rec_apace();
         }
+
+    }
+    
+}
+
+void heart_response2(void const *args){
+    while(1){
         
         if(vpace == 1){
             rec_vpace();
@@ -159,9 +204,13 @@
 
 int main(void)
 {
+    
+    
 
     Thread t3(random_heart, (void *)"");
-    Thread t2(heart_response, (void *)"");
+    Thread t2(heart_response1, (void *)"");
+    Thread t4(heart_response2, (void *)"");
+
 
     char a = 'Z';
 
@@ -169,17 +218,21 @@
 
         if(serial_in.readable()) {
             a = serial_in.getc();
-            serial_in.printf("char was " + a);
-            if(needs_num_input) {
+             serial_in.printf("GOT %c!!",a);
+            if(needs_num_input){
                 // DO O handling
                 needs_num_input = 0;
             }
 
             if(a == 'R') {
+                serial_in.printf("GOT R!!");
                 test_curr_mode = RANDOM;
             } else if(a == 'T') {
+                 serial_in.printf("GOT T!!");
                 test_curr_mode = TEST;
+            
             } else if(a == 'M') {
+                 serial_in.printf("GOT M!!");
                 test_curr_mode = MANUAL;
             }
 
@@ -194,8 +247,14 @@
                 Thread::wait(10);
                 vsense = 0;
             }
+            
+            while(serial_in.readable()){
+                serial_in.printf("GOT TO CONSUME!!",a);
+                serial_in.getc();
+            }
 
 
         }
     }
+
 }
\ No newline at end of file