simpler func

Dependencies:   TextLCD mbed-rtos mbed

Fork of pacemaker_v7 by Pacemaker

Files at this revision

API Documentation at this revision

Comitter:
jfields
Date:
Thu Dec 04 01:02:18 2014 +0000
Parent:
2:3773afd2256c
Commit message:
AA

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 3773afd2256c -r c60266d9ce0b main.cpp
--- a/main.cpp	Wed Dec 03 23:57:02 2014 +0000
+++ b/main.cpp	Thu Dec 04 01:02:18 2014 +0000
@@ -30,7 +30,6 @@
 Mutex t_mutex;          // protect reading of ta, tv
 Mutex status_mutex;     // protect reading of
 Mutex input_mutex;      // protects reading input
-Mutex VP_helper;
 
 // input stuff
 char input;
@@ -40,6 +39,7 @@
 int beats = 0;
 int sampleRate = 10000; // default 10 seconds
 int firstSample = 1;
+int Omode = 0;
 
 // Normal Values
 const int N_PVARP = 325;    // ms
@@ -77,6 +77,7 @@
 int isVRP = 0;
 int isPVARP = 0;
 int waitingForV = 1;
+int inManual = 0;
 
 // functions
 void A_func(void const *args);
@@ -89,14 +90,14 @@
 void setVals(char c);
 void makeManual();
 void blind();
+void get_listener(void const *args);
 
 // threads
 Thread * A_thread;
 Thread * V_thread;
 Thread * input_thread;
 Thread * disp_thread;
-Thread * send_Vpace_thread;
-Thread * send_Apace_thread;
+Thread * listener;
 
 // rtos timers
 RtosTimer * VRP_timer;
@@ -115,6 +116,7 @@
     input_thread = new Thread(input_func);
     A_thread = new Thread(A_func);
     V_thread = new Thread(V_func);
+    listener = new Thread(get_listener);
     
     // init timers
     VRP_timer = new RtosTimer(manage_flags, osTimerOnce, (void *)1);
@@ -133,41 +135,49 @@
 
 void A_func(void const *args) {
     while (1) {
-        while (tv.read_ms() <= (LRI-AVI)) {
-            if (AGet==1 && !isPVARP && !waitingForV) {
-                tv.reset();
-                tv.stop();
-                ta.start();
-                waitingForV = 1;
-                flashLED(4);
-                while (AGet == 1);
+        if (!inManual) {
+            while (tv.read_ms() <= (LRI-AVI)) {
+                t_mutex.unlock();
+                if (AGet==1 && !isPVARP && !waitingForV) {
+                    tv.reset();
+                    tv.stop();
+                    ta.start();
+                    waitingForV = 1;
+                    flashLED(4);
+                    while (AGet == 1);
+                }
+                t_mutex.lock();
             }
+            APace = 1;
+            Thread::wait(2);
+            APace = 0;
+            tv.reset();
+            tv.stop();
+            ta.start();
+            waitingForV = 1;
+            flashLED(2);
         }
-        APace = 1;
-        Thread::wait(2);
-        APace = 0;
-        tv.reset();
-        tv.stop();
-        ta.start();
-        waitingForV = 1;
-        flashLED(2);
     }
 }
 
 void V_func(void const *args) {
     while (1) {
-        while (ta.read_ms() <= AVI) {
-            if (VGet==1 && !isVRP && waitingForV) {
-                blind();
-                flashLED(3);
-                while (VGet == 1);
+        if (!inManual) {
+            while (ta.read_ms() <= AVI) {
+                t_mutex.unlock();
+                if (VGet==1 && !isVRP && waitingForV) {
+                    blind();
+                    flashLED(3);
+                    while (VGet == 1);
+                }
+                t_mutex.lock();
             }
+            VPace = 1;
+            Thread::wait(2);
+            VPace = 0;
+            blind();
+            flashLED(1);
         }
-        VPace = 1;
-        Thread::wait(2);
-        VPace = 0;
-        blind();
-        flashLED(1);
     }
 }
 
@@ -179,6 +189,21 @@
         if (input == 's') setVals('s');
         if (input == 'e') setVals('e');
         if (input == 'm') makeManual();
+        if (input == 'o') {
+            lcd.printf("Enter\n\n");
+            Omode = 1;
+            input = pc.getc();
+            if (input == '1') sampleRate = 10000;
+            if (input == '2') sampleRate = 20000;
+            if (input == '3') sampleRate = 30000;
+            if (input == '4') sampleRate = 60000;
+            if (input == '5') sampleRate = 100000;
+            beats = 0;
+            HR = 0;
+            Omode = 0;
+            firstSample = 1;
+            disp_thread->signal_set(RUN);
+        }
         input_mutex.unlock();
     }
 }
@@ -192,12 +217,20 @@
         HR = (beats*60000/sampleRate+HR)/2;
     }
     disp_thread->signal_set(RUN);
+    
+    if (HR>=UB || HR<=LB) {
+        
+    }
+    
+    
 }
 
 void disp(void const *args) {
     while (1) {
         Thread::signal_wait(RUN,osWaitForever);
-        lcd.printf("HR = %d ppm\nCyle = %d s\n",HR,sampleRate/1000);
+        if (!Omode) {
+            lcd.printf("HR = %d ppm\nCycle = %d s\n",HR,sampleRate/1000);
+        }
         beats = 0;
     }
 }
@@ -228,28 +261,76 @@
 }
 
 void makeManual() {
-    t_mutex.lock();
+    inManual = 1;
     ta.reset();
-    tv.reset();
     ta.stop();
+    tv.reset();
     tv.stop();
-    t_mutex.unlock();
-    while (1) {
+    UB = 175;
+    LB = 30;
+    int done = 0;
+    while (!done) {
         input = pc.getc();
         if (input == 'v') {
-            send_Vpace_thread->signal_set(RUN);
+            VPace = 1;
+            Thread::wait(2);
+            VPace = 0;
             flashLED(1);
         }
         if (input == 'a') {
-            send_Apace_thread->signal_set(RUN);
+            APace = 1;
+            Thread::wait(2);
+            APace = 0;
             flashLED(2);
         }
-        t_mutex.lock();
-        ta.reset();
-        tv.reset();
-        ta.stop();
-        tv.stop();
-        t_mutex.unlock();
+        if (input == 's') {
+            setVals('s');
+            done = 1;
+        }
+        if (input == 'e') {
+            setVals('s');
+            done = 1;
+        }
+        if (input == 'n') {
+            setVals('s');
+            done = 1;
+        }
+        if (input == 'o') {
+            lcd.printf("Enter\n\n");
+            Omode = 1;
+            input = pc.getc();
+            if (input == '1') sampleRate = 10000;
+            if (input == '2') sampleRate = 20000;
+            if (input == '3') sampleRate = 30000;
+            if (input == '4') sampleRate = 60000;
+            if (input == '5') sampleRate = 100000;
+            beats = 0;
+            HR = 0;
+            Omode = 0;
+            firstSample = 1;
+            disp_thread->signal_set(RUN);
+
+        }
+    }
+    tv.start();
+    waitingForV = 1;
+    VRP_timer->stop();
+    PVARP_timer->stop();
+    inManual = 0;
+}
+
+void get_listener(void const *args) {
+    while (1) {
+        if (inManual) {
+            if (AGet == 1) {
+                flashLED(4);
+                while (AGet == 1);
+            }
+            if (VGet == 1) {
+                flashLED(3);
+                while (VGet == 1);
+            }
+        }
     }
 }