瀏覽代碼

Fix probe with multi-endstops (#16793)

Robert Stein 4 年之前
父節點
當前提交
3a3429b1ef
沒有連結到貢獻者的電子郵件帳戶。
共有 1 個檔案被更改,包括 50 行新增61 行删除
  1. 50
    61
      Marlin/src/module/endstops.cpp

+ 50
- 61
Marlin/src/module/endstops.cpp 查看文件

@@ -529,11 +529,11 @@ void Endstops::update() {
529 529
   // With Dual X, endstops are only checked in the homing direction for the active extruder
530 530
   #if ENABLED(DUAL_X_CARRIAGE)
531 531
     #define E0_ACTIVE stepper.movement_extruder() == 0
532
-    #define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
533
-    #define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
532
+    #define X_MIN_TEST() ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
533
+    #define X_MAX_TEST() ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
534 534
   #else
535
-    #define X_MIN_TEST true
536
-    #define X_MAX_TEST true
535
+    #define X_MIN_TEST() true
536
+    #define X_MAX_TEST() true
537 537
   #endif
538 538
 
539 539
   // Use HEAD for core axes, AXIS for others
@@ -690,7 +690,7 @@ void Endstops::update() {
690 690
   #define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
691 691
 
692 692
   // Call the endstop triggered routine for single endstops
693
-  #define PROCESS_ENDSTOP(AXIS,MINMAX) do { \
693
+  #define PROCESS_ENDSTOP(AXIS, MINMAX) do { \
694 694
     if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
695 695
       _ENDSTOP_HIT(AXIS, MINMAX); \
696 696
       planner.endstop_triggered(_AXIS(AXIS)); \
@@ -698,36 +698,58 @@ void Endstops::update() {
698 698
   }while(0)
699 699
 
700 700
   // Call the endstop triggered routine for dual endstops
701
-  #define PROCESS_DUAL_ENDSTOP(AXIS1, AXIS2, MINMAX) do { \
702
-    const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1); \
701
+  #define PROCESS_DUAL_ENDSTOP(A, MINMAX) do { \
702
+    const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1); \
703 703
     if (dual_hit) { \
704
-      _ENDSTOP_HIT(AXIS1, MINMAX); \
704
+      _ENDSTOP_HIT(A, MINMAX); \
705 705
       /* if not performing home or if both endstops were trigged during homing... */ \
706 706
       if (!stepper.separate_multi_axis || dual_hit == 0b11) \
707
-        planner.endstop_triggered(_AXIS(AXIS1)); \
707
+        planner.endstop_triggered(_AXIS(A)); \
708 708
     } \
709 709
   }while(0)
710 710
 
711
-  #define PROCESS_TRIPLE_ENDSTOP(AXIS1, AXIS2, AXIS3, MINMAX) do { \
712
-    const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(AXIS3, MINMAX)) << 2); \
711
+  #define PROCESS_TRIPLE_ENDSTOP(A, MINMAX) do { \
712
+    const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2); \
713 713
     if (triple_hit) { \
714
-      _ENDSTOP_HIT(AXIS1, MINMAX); \
714
+      _ENDSTOP_HIT(A, MINMAX); \
715 715
       /* if not performing home or if both endstops were trigged during homing... */ \
716 716
       if (!stepper.separate_multi_axis || triple_hit == 0b111) \
717
-        planner.endstop_triggered(_AXIS(AXIS1)); \
717
+        planner.endstop_triggered(_AXIS(A)); \
718 718
     } \
719 719
   }while(0)
720 720
 
721
-  #define PROCESS_QUAD_ENDSTOP(AXIS1, AXIS2, AXIS3, AXIS4, MINMAX) do { \
722
-    const byte quad_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(AXIS3, MINMAX)) << 2) | (TEST_ENDSTOP(_ENDSTOP(AXIS4, MINMAX)) << 3); \
721
+  #define PROCESS_QUAD_ENDSTOP(A, MINMAX) do { \
722
+    const byte quad_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2) | (TEST_ENDSTOP(_ENDSTOP(A##4, MINMAX)) << 3); \
723 723
     if (quad_hit) { \
724
-      _ENDSTOP_HIT(AXIS1, MINMAX); \
724
+      _ENDSTOP_HIT(A, MINMAX); \
725 725
       /* if not performing home or if both endstops were trigged during homing... */ \
726 726
       if (!stepper.separate_multi_axis || quad_hit == 0b1111) \
727
-        planner.endstop_triggered(_AXIS(AXIS1)); \
727
+        planner.endstop_triggered(_AXIS(A)); \
728 728
     } \
729 729
   }while(0)
730 730
 
731
+  #if ENABLED(X_DUAL_ENDSTOPS)
732
+    #define PROCESS_ENDSTOP_X(MINMAX) PROCESS_DUAL_ENDSTOP(X, MINMAX)
733
+  #else
734
+    #define PROCESS_ENDSTOP_X(MINMAX) if (X_##MINMAX##_TEST()) PROCESS_ENDSTOP(X, MINMAX)
735
+  #endif
736
+
737
+  #if ENABLED(Y_DUAL_ENDSTOPS)
738
+    #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_DUAL_ENDSTOP(Y, MINMAX)
739
+  #else
740
+    #define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_ENDSTOP(Y, MINMAX)
741
+  #endif
742
+
743
+  #if DISABLED(Z_MULTI_ENDSTOPS)
744
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_ENDSTOP(Z, MINMAX)
745
+  #elif NUM_Z_STEPPER_DRIVERS == 4
746
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_QUAD_ENDSTOP(Z, MINMAX)
747
+  #elif NUM_Z_STEPPER_DRIVERS == 3
748
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_TRIPLE_ENDSTOP(Z, MINMAX)
749
+  #else
750
+    #define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_DUAL_ENDSTOP(Z, MINMAX)
751
+  #endif
752
+
731 753
   #if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
732 754
     #if ENABLED(G38_PROBE_AWAY)
733 755
       #define _G38_OPEN_STATE (G38_move >= 4)
@@ -747,20 +769,12 @@ void Endstops::update() {
747 769
   if (stepper.axis_is_moving(X_AXIS)) {
748 770
     if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
749 771
       #if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_DIR < 0)
750
-        #if ENABLED(X_DUAL_ENDSTOPS)
751
-          PROCESS_DUAL_ENDSTOP(X, X2, MIN);
752
-        #else
753
-          if (X_MIN_TEST) PROCESS_ENDSTOP(X, MIN);
754
-        #endif
772
+        PROCESS_ENDSTOP_X(MIN);
755 773
       #endif
756 774
     }
757 775
     else { // +direction
758 776
       #if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_DIR > 0)
759
-        #if ENABLED(X_DUAL_ENDSTOPS)
760
-          PROCESS_DUAL_ENDSTOP(X, X2, MAX);
761
-        #else
762
-          if (X_MAX_TEST) PROCESS_ENDSTOP(X, MAX);
763
-        #endif
777
+        PROCESS_ENDSTOP_X(MAX);
764 778
       #endif
765 779
     }
766 780
   }
@@ -768,44 +782,27 @@ void Endstops::update() {
768 782
   if (stepper.axis_is_moving(Y_AXIS)) {
769 783
     if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
770 784
       #if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_DIR < 0)
771
-        #if ENABLED(Y_DUAL_ENDSTOPS)
772
-          PROCESS_DUAL_ENDSTOP(Y, Y2, MIN);
773
-        #else
774
-          PROCESS_ENDSTOP(Y, MIN);
775
-        #endif
785
+        PROCESS_ENDSTOP_Y(MIN);
776 786
       #endif
777 787
     }
778 788
     else { // +direction
779 789
       #if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_DIR > 0)
780
-        #if ENABLED(Y_DUAL_ENDSTOPS)
781
-          PROCESS_DUAL_ENDSTOP(Y, Y2, MAX);
782
-        #else
783
-          PROCESS_ENDSTOP(Y, MAX);
784
-        #endif
790
+        PROCESS_ENDSTOP_Y(MAX);
785 791
       #endif
786 792
     }
787 793
   }
788 794
 
789 795
   if (stepper.axis_is_moving(Z_AXIS)) {
790 796
     if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
797
+
791 798
       #if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
792
-        #if ENABLED(Z_MULTI_ENDSTOPS)
793
-          #if NUM_Z_STEPPER_DRIVERS == 4
794
-            PROCESS_QUAD_ENDSTOP(Z, Z2, Z3, Z4, MIN);
795
-          #elif NUM_Z_STEPPER_DRIVERS == 3
796
-            PROCESS_TRIPLE_ENDSTOP(Z, Z2, Z3, MIN);
797
-          #else
798
-            PROCESS_DUAL_ENDSTOP(Z, Z2, MIN);
799
-          #endif
800
-        #else
799
+        if (true
801 800
           #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
802
-            if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
801
+            && z_probe_enabled
803 802
           #elif HAS_CUSTOM_PROBE_PIN
804
-            if (!z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
805
-          #else
806
-            PROCESS_ENDSTOP(Z, MIN);
803
+            && !z_probe_enabled
807 804
           #endif
808
-        #endif
805
+        ) PROCESS_ENDSTOP_Z(MIN);
809 806
       #endif
810 807
 
811 808
       // When closing the gap check the enabled probe
@@ -816,16 +813,8 @@ void Endstops::update() {
816 813
     else { // Z +direction. Gantry up, bed down.
817 814
       #if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_DIR > 0)
818 815
         #if ENABLED(Z_MULTI_ENDSTOPS)
819
-          #if NUM_Z_STEPPER_DRIVERS == 4
820
-            PROCESS_QUAD_ENDSTOP(Z, Z2, Z3, Z4, MAX);
821
-          #elif NUM_Z_STEPPER_DRIVERS == 3
822
-            PROCESS_TRIPLE_ENDSTOP(Z, Z2, Z3, MAX);
823
-          #else
824
-            PROCESS_DUAL_ENDSTOP(Z, Z2, MAX);
825
-          #endif
826
-        #elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN
827
-          // If this pin is not hijacked for the bed probe
828
-          // then it belongs to the Z endstop
816
+          PROCESS_ENDSTOP_Z(MAX);
817
+        #elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN  // No probe or probe is Z_MIN || Probe is not Z_MAX
829 818
           PROCESS_ENDSTOP(Z, MAX);
830 819
         #endif
831 820
       #endif

Loading…
取消
儲存