mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Revision:
0:54ec65701097
Child:
1:c0fdd901d5d5
Child:
2:4761ca8ba841
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PMTest.cpp	Wed Dec 02 00:50:28 2015 +0000
@@ -0,0 +1,121 @@
+#include "mbed.h"
+#include "LPC17xx.h"
+#include "TextLCD.h"
+#include "rtos.h"
+#include "Thread.h"
+
+DigitalOut vsense(p23);
+DigitalOut asense(p24);
+DigitalIn apace(p22);
+DigitalIn vpace(p21);
+
+Serial serial_in(USBTX, USBRX);
+
+
+int test_time_count;
+int curr_test;
+int minwaitV;
+int minwaitA;
+
+int needs_num_input = 0;
+
+enum mode{RANDOM,MANUAL,TEST};
+mode test_curr_mode = RANDOM;
+Timer t;
+
+
+
+
+
+void random_heart(){
+    t.reset();
+    t.start();
+
+    while(test_curr_mode == RANDOM){
+        int r = rand();
+
+        if(r%2 == 0){
+            if(t.read() > minwaitA){
+                asense = 1;
+                Thread::wait(10);
+                asense = 0;
+            }
+        }else{
+            if(t.read() > minwaitV){
+                vsense = 1;
+                Thread::wait(10);
+                vsense = 0;
+            }
+        }
+
+
+        t.reset();
+
+    }
+}
+
+
+void kbd_intrp(){
+    char a = serial_in.getc();
+
+    if(needs_num_input){
+        // DO O handling
+        needs_num_input = 0;
+        return;
+    }
+
+    if(a == 'R'){
+        test_curr_mode = RANDOM;
+    }else if(a == 'T'){
+        test_curr_mode = TEST;
+    }else if(a == 'M'){
+        test_curr_mode = MANUAL;
+    }
+    
+    if(a == 'A' && test_curr_mode == MANUAL){
+        asense = 1;
+        Thread::wait(10);
+        asense = 0;
+    }
+    
+    if(a == 'V' && test_curr_mode == MANUAL){
+        vsense = 1;
+        Thread::wait(10);
+        vsense = 0;
+    }
+        
+
+
+
+}
+
+
+
+// interrupt function
+void interrupt_and_run_test(){
+    // zero timer, set for 1ms interrupt
+    
+    // wait for atrial pulse
+    
+    // check if timer was within event
+    
+    
+    // send vsense
+    
+    
+    // send asense
+    
+    // check if timer was in event
+
+    // wait for vpace
+    
+    // wait for atrial pulse
+    
+    // check if timer was within event
+}    
+
+int main(void){
+    while(1){
+        random_heart();
+    }
+}
\ No newline at end of file