reeeeeeeeeeeeeee

Dependencies:   MotionSensor mbed

Fork of Assignment2_ver3 by weeb grammers

Revision:
7:6dc42e1a2a81
Parent:
6:9b8fee13549c
diff -r 9b8fee13549c -r 6dc42e1a2a81 PaceHeart.cpp
--- a/PaceHeart.cpp	Mon Nov 14 22:47:00 2016 +0000
+++ b/PaceHeart.cpp	Tue Nov 29 20:21:45 2016 +0000
@@ -9,41 +9,48 @@
     
     p_pacingState = 0;
     p_pacingMode = 0;
-    int p_hysteresis = 0;
-    int p_hysteresisInterval = 300;
-    double p_lowrateInterval = 1000.0;
-    double p_uprateInterval = 500.0; //upper rate limit
+    p_hysteresis = 0;
+    p_hysteresisInterval = 300;
+    p_lowrateInterval = 1000.0;
+    p_uprateInterval = 500.0; //upper rate limit
 //Ventricle
-    double p_vPaceAmp = 3500.0;
-    double p_vPaceWidth = 0.4;
-    int p_VRP = 320;
+    p_vPaceAmp = 3500.0;
+    p_vPaceWidth = 0.4;
+    p_VRP = 320;
 //Atrium (change defaults)
-    double p_aPaceAmp = 3500.0;
-    double p_aPaceWidth = 0.4;
-    int p_ARP = 320;
+    p_aPaceAmp = 3500.0;
+    p_aPaceWidth = 0.4;
+    p_ARP = 320;
 }
 
 PaceHeart::PaceHeart(int mode){
     p_pacingState = 0;
     p_pacingMode = mode;
-    double p_lowrateInterval = 1000.0; //30-50->5 50-90->1 90-175->5 ppm
-    double p_uprateInterval = 2000.0; //upper rate limit 50-175->5 ppm
-    double p_maxSensorRate = 2000.0; //50-175->5 ppm
+    p_lowrateInterval = 1000.0; //30-50->5 50-90->1 90-175->5 ppm
+    p_uprateInterval = 2000.0; //upper rate limit 50-175->5 ppm
+    p_maxSensorRate = 2000.0; //50-175->5 ppm
     
 //Ventricle
-    double p_vPaceAmp = 3750.0; //3750 can change to 0, 1250, 2500, 3750, 5000
-    double p_vPaceWidth = 0.4; //0.05->no change 0.1-1.9 0.1
+    p_vPaceAmp = 3500.0; //3500->0.1
+    p_vPaceWidth = 0.4; //0.05->no change 0.1-1.9 0.1
 
-    int p_activityThresh = 4; //1-7 print out string with level ie. Med
-    int p_reactionTime = 30; //10-50->10 seconds
-    int p_responseFactor = 8; //1-16->1
-    int p_recoveryTime = 5; //2-16->1 minutes
+    p_activityThresh = 4; //1-7 print out string with level ie. Med
+    p_reactionTime = 30000; //10-50->10 seconds
+    p_responseFactor = 8; //1-16->1
+    p_recoveryTime = 300000; //2-16->1 minutes
 }
 int PaceHeart::get_p_pacingState()
 {
     return p_pacingState;
 }
-int PaceHeart::get_p_pacingMode()
+
+void PaceHeart::set_p_pacingMode(int x)
+{
+    p_pacingMode = x;
+    return;
+}
+
+int PaceHeart::get_p_pacingMode()//lets make it string in future
 {
     return p_pacingMode;
 }
@@ -71,19 +78,37 @@
 }
 void PaceHeart::set_p_lowrateInterval(double x)
 {
-    if (p_pacingmode == 1) {
+    if (p_pacingMode == 1) {
             
-        if (x >= 500 && x < 833.33) {
-            p_lowrateInterval = x+83.33; 
+        if (dir ==1) // Change values to take into account for user inputs
+        {
+            if (p_lowrateInterval >=833.33 && p_lowrateInterval<=1483.33)
+            {
+                p_lowrateInterval += 16.67;
+            }
+            else if (p_lowrateInterval >2833.33)
+            {
+                return;
+            }
+            else
+            {
+                p_lowrateInterval += 83.33;
+            }
         }
-        else if (x >= 833.33 && x < 1000) {
-            p_lowrateInterval = x+16.67; 
-        }
-        else if (x >= 1000 && x < 1500) {
-            p_lowrateInterval = x-16.67; 
-        }
-        else if (x >= 1500 && x < 2916.67) {
-            p_lowrateInterval = x-83.33; 
+        else if (dir==0)
+        {
+            if (p_lowrateInterval >=850 && p_lowrateInterval<=1500)
+            {
+                p_lowrateInterval -= 16.67;
+            }
+            else if (p_lowrateInterval<583.33)
+            {
+                return;
+            }
+            else
+            {
+                p_lowrateInterval -= 83.33;
+            }
         }
     }
     else {
@@ -97,12 +122,28 @@
 }
 void PaceHeart::set_p_uprateInterval(double x)
 {
-    if (p_pacingmode == 1) {
-        if (x >= 833.33 && x < 2000) {
-            p_uprateInterval = x+83.33;
+    if (p_pacingMode == 1) {
+        if (dir ==1) // Change values to take into account for user inputs
+        {
+            if (p_uprateInterval >=833.33 && p_uprateInterval<=2833.33)
+            {
+                p_uprateInterval += 83.33;
+            }
+            else if (p_uprateInterval >2833.33)
+            {
+                return;
+            }
         }
-        else if (x >= 2000 && x <= 2916.67) {
-            p_uprateInterval = x-83.33;
+        else if (dir==0)
+        {
+            if (p_uprateInterval >=916.67 && p_uprateInterval<=2916.67)
+            {
+                p_uprateInterval -= 83.33;
+            }
+            else if (p_uprateInterval<916.67)
+            {
+                return;
+            }
         }
     }
     else {
@@ -111,16 +152,32 @@
     return;
 }
 double PaceHeart::get_p_maxSensorRate(){
-    return 
+    return p_maxSensorRate;
 }
 void PaceHeart::set_p_maxSensorRate(double x)
 {
-    if (p_pacingmode == 1) {
-        if (x >= 833.33 && x < 2000) {
-            p_maxSensorRate = x+83.33;
+    if (p_pacingMode == 1) {
+        if (dir ==1) // Change values to take into account for user inputs
+        {
+            if (p_maxSensorRate >=833.33 && p_maxSensorRate<=2833.33)
+            {
+                p_maxSensorRate += 83.33;
+            }
+            else if (p_maxSensorRate >2833.33)
+            {
+                return;
+            }
         }
-        else if (x >= 2000 && x <= 2916.67) {
-            p_maxSensorRate = x-83.33;
+        else if (dir==0)
+        {
+            if (p_maxSensorRate >=916.67 && p_maxSensorRate<=2916.67)
+            {
+                p_maxSensorRate -= 83.33;
+            }
+            else if (p_maxSensorRate<916.67)
+            {
+                return;
+            }
         }
     }
     else {
@@ -135,7 +192,42 @@
 }
 void PaceHeart::set_p_vPaceAmp(double x)
 {
+    if (p_pacingMode == 1) {
+            
+       if (dir ==1) // Change values to take into account for user inputs
+        {
+            if (p_vPaceAmp >=500 && p_vPaceAmp<=3100)
+            {
+                p_vPaceAmp += 100;
+            }
+            else if (p_vPaceAmp >= 3500 && p_vPaceAmp<=6500)
+            {
+                p_vPaceAmp += 500;
+            }
+            else
+            {
+                return;
+            }
+        }
+        else if (dir==0)
+        {
+            if (p_vPaceAmp >=600 && p_vPaceAmp<3200)
+            {
+                p_vPaceAmp -= 100;
+            }
+            else if (p_vPaceAmp >= 4000 && p_vPaceAmp<=7000)
+            {
+                p_vPaceAmp -= 500;
+            }
+            else
+            {
+                return;
+            }
+        }
+    }
+    else {
     p_vPaceAmp = x;
+    }
     return;
 }
  
@@ -145,7 +237,30 @@
 }
 void PaceHeart::set_p_vPaceWidth(double x)
 {
-    p_vPaceWidth = x;
+    if (p_pacingMode == 1) {
+        if (p_vPaceWidth == 0.05) {
+            p_vPaceWidth = 0.4;   
+        }
+        if (dir ==1){
+            if (p_vPaceWidth >= 0.1 && p_vPaceWidth <= 1.8){
+                p_vPaceWidth += 0.1;
+            }
+            else {
+                return;
+            }
+        }
+        else if (dir ==0) {
+            if (p_vPaceWidth >= 0.2 && p_vPaceWidth <= 1.9){
+                p_vPaceWidth -= 0.1;
+            }
+            else {
+                return;
+            }
+        }
+    }
+    else {
+        p_vPaceWidth = x;
+    }
     return;
 }
  
@@ -191,13 +306,9 @@
 
 
 
-void PaceHeart::pace_A(double amp, double wid,int pin)
+void PaceHeart::pace_A(double amp, double wid)
 {   
-    output_pin_A = !output_pin_A ;
-    wait(1);
-   
-    
-   
+    Output_A(amp,wid);
     return;
 }
 
@@ -205,17 +316,14 @@
 {
     double amplitude = get_p_aPaceAmp();
     double width = get_p_aPaceWidth();
-    // int output_pin = hardware.get_output_pin; //include the hardware module
-    pace_A(amplitude,width,output_pin_A);
+    pace_A(amplitude,width);
     return;
 }
 
 
-void PaceHeart::pace_V(double amp, double wid, int pin)
+void PaceHeart::pace_V(double amp, double wid)
 {
-    output_pin_V = !output_pin_V ;
-    wait(2);
-   
+    Output_V(amp,wid);
     return;
 }
 
@@ -223,8 +331,7 @@
 {
     double amplitude = get_p_vPaceAmp();
     double width = get_p_vPaceWidth();
-    // int output_pin = hardware.get_output_pin; //include the hardware module
-    pace_V(amplitude,width,output_pin_V);
+    pace_V(amplitude,width);
     return;
 }
 
@@ -232,9 +339,9 @@
 void PaceHeart::pace(int mode)
 {
     switch(mode){
-    case 1:  //AOO
-           pace_A();
-    case 2:  //VOO
+    case 1:  //VOOR
+           pace_V();
+    case 0:  //VOO
            pace_V();
     }
     return;
@@ -264,21 +371,106 @@
 }
 void PaceHeart::set_p_activityThresh(int x)
 {
-    p_activityThresh=x;
+    if (p_pacingMode == 1) {
+        p_activityThresh=x; //no increment set at beginning
+    }
+    else {
+        p_activityThresh=x;
+    }
     return;
 }
 void PaceHeart::set_p_reactionTime(int x)
 {
-    p_reactionTime=x;
+    if (p_pacingMode == 1) {
+        
+        if (dir ==1){
+            if (p_reactionTime >= 10000 && p_reactionTime <= 40000) {
+                p_reactionTime += 10000;
+        }  
+        else if (p_reactionTime >40000)
+            {
+                return;
+            }
+        }
+        else if (dir==0)
+        {
+            if (p_reactionTime >=20000 && p_reactionTime <=50000)
+            {
+                p_reactionTime -= 10000;
+            }
+            else if (p_reactionTime < 20000)
+            {
+                return;
+            }
+        }
+    }
+    else {
+        p_reactionTime = x;
+    }
     return;
 }
 void PaceHeart::set_p_responseFactor(int x)
 {
-    p_responseFactor=x;
+    if (p_pacingMode == 1) {
+            
+        if (dir ==1){
+            if (p_responseFactor >= 1 && p_responseFactor <= 15) {
+                p_responseFactor += 1;
+        }  
+        else if (p_responseFactor >15)
+            {
+                return;
+            }
+        }
+        else if (dir==0)
+        {
+            if (p_responseFactor >=2 && p_responseFactor <=16)
+            {
+                p_responseFactor -= 1;
+            }
+            else if (p_responseFactor < 2)
+            {
+                return;
+            }
+        }
+    }
+    else {
+        p_responseFactor=x;
+    }
     return;
 }
 void PaceHeart::set_p_recoveryTime(int x)
 {
-    p_recoveryTime=x;
+    if (p_pacingMode == 1) {
+            
+        if (dir ==1){
+            if (p_recoveryTime >= 120000 && p_recoveryTime <= 900000) {
+                p_recoveryTime += 60000;
+        }  
+        else if (p_recoveryTime >900000)
+            {
+                return;
+            }
+        }
+        else if (dir==0)
+        {
+            if (p_recoveryTime >=180000 && p_recoveryTime <=960000)
+            {
+                p_recoveryTime -= 60000;
+            }
+            else if (p_recoveryTime < 180000)
+            {
+                return;
+            }
+        }
+    }
+    else {
+        p_recoveryTime=x;
+    }
+    return;
+}
+void PaceHeart::set_dir(int x)
+{
+    dir=x;
     return;
 }
\ No newline at end of file