Browse Source

don't process compensatePlay if no play

eLandon 4 years ago
parent
commit
c3386b1617
1 changed files with 18 additions and 16 deletions
  1. 18 16
      Atm_AccelStepper.cpp

+ 18 - 16
Atm_AccelStepper.cpp

@@ -426,23 +426,24 @@ Atm_AccelStepper& Atm_AccelStepper::setPlayCompensation(long int steps){
 
 bool Atm_AccelStepper::compensatePlay(int speed){ //check if there is a change in direction,
 //use just after _targetStep update and before moving
-  bool newDirection ;
-  switch (runMode) {
-    case 0: //positional modae
-      newDirection = _targetStep > _currentStep;
-      break;
-    case 1: // speed mode
-      newDirection = speed>0;
-      break;
-  }
-  if (direction != newDirection){
-    long int compensation = newDirection ? -playSteps : playSteps ;
-    setPosition(_currentStep + compensation);
-    Serial.print("play compensation ");
-    Serial.println(compensation);
-    return 1;
+if(playSteps)
+  {  bool newDirection ;
+    switch (runMode) {
+      case 0: //positional modae
+        newDirection = _targetStep > _currentStep;
+        break;
+      case 1: // speed mode
+        newDirection = speed>0;
+        break;
     }
-  else{return 0;}
+    if (direction != newDirection){
+      long int compensation = newDirection ? -playSteps : playSteps ;
+      setPosition(_currentStep + compensation);
+      Serial.print("play compensation ");
+      Serial.println(compensation);
+      return 1;
+      }
+    else{return 0;}}
 }
 
 long int Atm_AccelStepper::getPosition(){
@@ -471,6 +472,7 @@ Atm_AccelStepper& Atm_AccelStepper::move( long int stepRel) {
   _targetStep   = _currentStep + stepRel;
   runMode = 0;
   stepper->moveTo(_targetStep);
+  // stepper_update();
   _currentSpeed = stepper->speed();
   enable();
   trigger( EVT_MOVE );