mbed heart

Dependencies:   TextLCD mbed-rtos mbed

Revision:
8:0f92ac2b9d0e
Parent:
7:1c32e8f6bde8
Child:
9:917f6d407d78
--- a/PMTest.cpp	Wed Dec 02 06:48:26 2015 +0000
+++ b/PMTest.cpp	Wed Dec 02 20:41:31 2015 +0000
@@ -9,6 +9,14 @@
 DigitalIn apace(p22);
 DigitalIn vpace(p21);
 
+Ticker rate_monitor;
+
+
+TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x4); // rs, e, d4-d7
+
+volatile int beats = 0;
+volatile double bpm = 0;
+
 DigitalOut led_apace(LED1);
 DigitalOut led_vpace(LED2);
 DigitalOut led_asense(LED3);
@@ -22,6 +30,9 @@
 int minwaitV = 200;
 int minwaitA = 400;
 
+int obs_int = 10;
+
+
 int needs_num_input = 0;
 
 enum mode {RANDOM,MANUAL,TEST};
@@ -115,6 +126,7 @@
                 serial_in.printf("| VSENSE FIRED | ");
                 Thread::wait(10);
                 vsense = 0;
+                beats++;
                 led_vsense = 0;
                 t.reset();
 
@@ -131,6 +143,13 @@
     }
 }
 
+void pm_beat_update(void const *args){
+    while(1){
+        lcd.locate(0,0);
+        lcd.printf("BPM: %.1f   ", bpm);
+    }
+}
+
 
 void kbd_intrp()
 {
@@ -223,40 +242,43 @@
     // check if timer was within event
 }
 
-void test_mode(){
-    
-    int lri_done = 0;
-    int avi_done = 0;
-    int vrp_done = 0;
-    int pvarp_done = 0;
-    
-    while(1){
-    while(test_curr_mode == TEST) {
-        
-    }   
-    
+void update_display() {
+    bpm = beats / (double) obs_int * 60;
+    //reset count
+    beats = 0;
 }
 
 int main(void)
 {
     
     
+    
 
     Thread t3(random_heart, (void *)"");
     Thread t2(heart_response1, (void *)"");
     Thread t4(heart_response2, (void *)"");
-
+    Thread t5(pm_beat_update, (void *)"");
 
+    rate_monitor.attach(&update_display, obs_int);
     char a = 'Z';
 
+
     while(1) {
 
         if(serial_in.readable()) {
             a = serial_in.getc();
              serial_in.printf("GOT %c!!",a);
-            if(needs_num_input){
-                // DO O handling
-                needs_num_input = 0;
+            
+            if (needs_num_input) {
+                if (a >= '0' && a <= '9') {
+                    // update observation interval
+                    obs_int = (a - '0' + 1) * 5;
+                    needs_num_input = 0;
+                    rate_monitor.attach(&update_display, obs_int);
+                    serial_in.printf("Set observation interval to %d seconds\n", obs_int);
+                } else {
+                    serial_in.printf("Expected numeric key\n");
+                }
             }
 
             if(a == 'R') {
@@ -270,6 +292,10 @@
                  serial_in.printf("GOT M!!");
                 test_curr_mode = MANUAL;
             }
+            else if(a == 'O') {
+                 serial_in.printf("GOT obs!!");
+                needs_num_input = 1;
+            }
 
             if(a == 'A' && test_curr_mode == MANUAL) {
                 asense = 1;
@@ -291,5 +317,6 @@
 
         }
     }
+    
 
 }
\ No newline at end of file