Browse Source

Cleanup and consolidate probe conditionals for clarity

Scott Lahteine 8 years ago
parent
commit
15fc93d742
6 changed files with 83 additions and 53 deletions
  1. 6
    11
      Marlin/Conditionals.h
  2. 4
    4
      Marlin/Marlin_main.cpp
  3. 66
    31
      Marlin/SanityCheck.h
  4. 5
    5
      Marlin/endstops.cpp
  5. 1
    1
      Marlin/endstops.h
  6. 1
    1
      Marlin/stepper.cpp

+ 6
- 11
Marlin/Conditionals.h View File

@@ -628,7 +628,7 @@
628 628
   #define HAS_Z_MAX (PIN_EXISTS(Z_MAX))
629 629
   #define HAS_Z2_MIN (PIN_EXISTS(Z2_MIN))
630 630
   #define HAS_Z2_MAX (PIN_EXISTS(Z2_MAX))
631
-  #define HAS_Z_PROBE (PIN_EXISTS(Z_MIN_PROBE))
631
+  #define HAS_Z_MIN_PROBE_PIN (PIN_EXISTS(Z_MIN_PROBE))
632 632
   #define HAS_SOLENOID_1 (PIN_EXISTS(SOL1))
633 633
   #define HAS_SOLENOID_2 (PIN_EXISTS(SOL2))
634 634
   #define HAS_SOLENOID_3 (PIN_EXISTS(SOL3))
@@ -742,16 +742,11 @@
742 742
     #endif
743 743
   #endif
744 744
 
745
-  #if  ( (HAS_Z_MIN && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)) || HAS_Z_PROBE ) \
746
-    && ( \
747
-         ENABLED(FIX_MOUNTED_PROBE) \
748
-      || ENABLED(MECHANICAL_PROBE) \
749
-      || HAS_Z_ENDSTOP_SERVO \
750
-      || ENABLED(Z_PROBE_ALLEN_KEY) \
751
-      || ENABLED(Z_PROBE_SLED) \
752
-    )
753
-    #define HAS_Z_MIN_PROBE
754
-  #endif
745
+  #define PROBE_SELECTED (ENABLED(FIX_MOUNTED_PROBE) || ENABLED(MECHANICAL_PROBE) || HAS_Z_ENDSTOP_SERVO || ENABLED(Z_PROBE_SLED))
746
+
747
+  #define PROBE_PIN_CONFIGURED (HAS_Z_MIN_PROBE_PIN || (HAS_Z_MIN && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)))
748
+
749
+  #define HAS_BED_PROBE (PROBE_SELECTED && PROBE_PIN_CONFIGURED)
755 750
 
756 751
   /**
757 752
    * Delta radius/rod trimmers

+ 4
- 4
Marlin/Marlin_main.cpp View File

@@ -1681,7 +1681,7 @@ static void setup_for_endstop_move() {
1681 1681
     refresh_cmd_timeout();
1682 1682
   }
1683 1683
 
1684
-  #if ENABLED(HAS_Z_MIN_PROBE)
1684
+  #if HAS_BED_PROBE
1685 1685
 
1686 1686
   static void deploy_z_probe() {
1687 1687
 
@@ -1878,7 +1878,7 @@ static void setup_for_endstop_move() {
1878 1878
 
1879 1879
     endstops.enable_z_probe(false);
1880 1880
   }
1881
-  #endif // HAS_Z_MIN_PROBE
1881
+  #endif // HAS_BED_PROBE
1882 1882
 
1883 1883
   enum ProbeAction {
1884 1884
     ProbeStay          = 0,
@@ -3579,7 +3579,7 @@ inline void gcode_G28() {
3579 3579
         }
3580 3580
       #endif
3581 3581
       enqueue_and_echo_commands_P(PSTR(Z_PROBE_END_SCRIPT));
3582
-      #if ENABLED(HAS_Z_MIN_PROBE)
3582
+      #if HAS_BED_PROBE
3583 3583
         endstops.enable_z_probe(false);
3584 3584
       #endif
3585 3585
       stepper.synchronize();
@@ -3942,7 +3942,7 @@ inline void gcode_M42() {
3942 3942
    *  Z_MIN_PROBE_PIN, but here for clarity.
3943 3943
    */
3944 3944
   #if ENABLED(Z_MIN_PROBE_ENDSTOP)
3945
-    #if !HAS_Z_PROBE
3945
+    #if !HAS_Z_MIN_PROBE_PIN
3946 3946
       #error You must define Z_MIN_PROBE_PIN to enable Z probe repeatability calculation.
3947 3947
     #endif
3948 3948
   #elif !HAS_Z_MIN

+ 66
- 31
Marlin/SanityCheck.h View File

@@ -204,50 +204,55 @@
204 204
  * Probes
205 205
  */
206 206
 
207
-/**
208
- * A probe needs a pin
209
- */
210
-#if (!((HAS_Z_MIN && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)) || HAS_Z_PROBE )) && ( ENABLED(FIX_MOUNTED_PROBE) || defined(Z_ENDSTOP_SERVO_NR) || ENABLED(MECHANICAL_PROBE) || ENABLED(Z_PROBE_SLED))
211
-  #error A probe needs a pin! [Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN || HAS_Z_PROBE]
212
-#endif
207
+#if PROBE_SELECTED
213 208
 
214
-#if ((HAS_Z_MIN && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)) && HAS_Z_PROBE) && ( ENABLED(FIX_MOUNTED_PROBE) || defined(Z_ENDSTOP_SERVO_NR) || ENABLED(MECHANICAL_PROBE) || ENABLED(Z_PROBE_SLED))
215
-  #error A probe should not be connected to more than one pin! [Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN || HAS_Z_PROBE]
216
-#endif
209
+  /**
210
+   * A probe needs a pin
211
+   */
212
+  #if !PROBE_PIN_CONFIGURED
213
+    #error A probe needs a pin! Use Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN or Z_MIN_PROBE_PIN.
214
+  #endif
217 215
 
218
-/**
219
-  * Require one kind of probe
220
-  */
221
-#if ENABLED(AUTO_BED_LEVELING_FEATURE) && !( ENABLED(FIX_MOUNTED_PROBE) || defined(Z_ENDSTOP_SERVO_NR) || ENABLED(MECHANICAL_PROBE) || ENABLED(Z_PROBE_SLED))
222
-  #error For AUTO_BED_LEVELING_FEATURE define one kind of probe! [Servo | MECHANICAL_PROBE | Z_PROBE_SLED | FIX_MOUNTED_PROBE]
223
-#endif
216
+  /**
217
+   * Z_MIN_PIN and Z_MIN_PROBE_PIN can't co-exist when Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
218
+   */
219
+  #if HAS_Z_MIN && HAS_Z_MIN_PROBE_PIN && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
220
+    #error A probe cannot have more than one pin! Use Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN or Z_MIN_PROBE_PIN.
221
+  #endif
224 222
 
225
-// To do: Fail with more than one probe defined
223
+  /**
224
+   * Make sure the plug is enabled if it's used
225
+   */
226
+  #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && DISABLED(USE_ZMIN_PLUG)
227
+    #error You must enable USE_ZMIN_PLUG if any probe or endstop is connected to the ZMIN plug.
228
+  #endif
226 229
 
227
-/**
228
- * Auto Bed Leveling
229
- */
230
-#if ENABLED(AUTO_BED_LEVELING_FEATURE)
230
+  /**
231
+   * Only allow one probe option to be defined
232
+   */
233
+  #if (ENABLED(FIX_MOUNTED_PROBE) && (ENABLED(MECHANICAL_PROBE) || HAS_Z_ENDSTOP_SERVO || ENABLED(Z_PROBE_SLED))) \
234
+       || (ENABLED(MECHANICAL_PROBE) && (HAS_Z_ENDSTOP_SERVO || ENABLED(Z_PROBE_SLED))) \
235
+       || (HAS_Z_ENDSTOP_SERVO && ENABLED(Z_PROBE_SLED))
236
+    #error Please define only one type of probe: Z Servo, MECHANICAL_PROBE, Z_PROBE_SLED, or FIX_MOUNTED_PROBE.
237
+  #endif
231 238
 
232 239
   /**
233
-   * Require a Z min pin
240
+   * Don't allow nonsense probe-pin settings
234 241
    */
235
-  #if !PIN_EXISTS(Z_MIN)
236
-    #if !PIN_EXISTS(Z_MIN_PROBE) || (DISABLED(Z_MIN_PROBE_ENDSTOP) || ENABLED(DISABLE_Z_MIN_PROBE_ENDSTOP)) // It's possible for someone to set a pin for the Z probe, but not enable it.
237
-      #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
238
-        #error You must have a Z_MIN or Z_PROBE endstop to enable Z_MIN_PROBE_REPEATABILITY_TEST.
239
-      #else
240
-        #error AUTO_BED_LEVELING_FEATURE requires a Z_MIN or Z_PROBE endstop. Z_MIN_PIN or Z_MIN_PROBE_PIN must point to a valid hardware pin.
241
-      #endif
242
-    #endif
242
+  #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && ENABLED(Z_MIN_PROBE_ENDSTOP)
243
+    #error You can't enable both Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN and Z_MIN_PROBE_ENDSTOP.
244
+  #elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && ENABLED(DISABLE_Z_MIN_PROBE_ENDSTOP)
245
+    #error Don't enable DISABLE_Z_MIN_PROBE_ENDSTOP with Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN.
246
+  #elif ENABLED(DISABLE_Z_MIN_PROBE_ENDSTOP) && DISABLED(Z_MIN_PROBE_ENDSTOP)
247
+    #error DISABLE_Z_MIN_PROBE_ENDSTOP requires Z_MIN_PROBE_ENDSTOP to be set.
243 248
   #endif
244 249
 
245 250
   /**
246 251
    * Require a Z probe pin if Z_MIN_PROBE_ENDSTOP is enabled.
247 252
    */
248 253
   #if ENABLED(Z_MIN_PROBE_ENDSTOP)
249
-    #if !PIN_EXISTS(Z_MIN_PROBE)
250
-      #error You must have a Z_MIN_PROBE_PIN defined in your pins_XXXX.h file if you enable Z_MIN_PROBE_ENDSTOP.
254
+    #if !HAS_Z_MIN_PROBE_PIN
255
+      #error Z_MIN_PROBE_ENDSTOP requires a Z_MIN_PROBE_PIN in your board's pins_XXXX.h file.
251 256
     #endif
252 257
     // Forcing Servo definitions can break some hall effect sensor setups. Leaving these here for further comment.
253 258
     //#ifndef NUM_SERVOS
@@ -263,6 +268,36 @@
263 268
     //  #error You must have SERVO_ENDSTOP_ANGLES defined for Z Extend and Retract to use Z_MIN_PROBE_ENDSTOP.
264 269
     //#endif
265 270
   #endif
271
+
272
+#else
273
+
274
+  /**
275
+   * Require some kind of probe for bed leveling
276
+   */
277
+  #if ENABLED(AUTO_BED_LEVELING_FEATURE)
278
+    #error AUTO_BED_LEVELING_FEATURE requires a probe! Define a Z Servo, MECHANICAL_PROBE, Z_PROBE_SLED, or FIX_MOUNTED_PROBE.
279
+  #endif
280
+
281
+#endif
282
+
283
+/**
284
+ * Auto Bed Leveling
285
+ */
286
+#if ENABLED(AUTO_BED_LEVELING_FEATURE)
287
+
288
+  /**
289
+   * Require a Z min pin
290
+   */
291
+  #if !PIN_EXISTS(Z_MIN)
292
+    #if !PIN_EXISTS(Z_MIN_PROBE) || (DISABLED(Z_MIN_PROBE_ENDSTOP) || ENABLED(DISABLE_Z_MIN_PROBE_ENDSTOP)) // It's possible for someone to set a pin for the Z probe, but not enable it.
293
+      #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
294
+        #error You must have a Z_MIN or Z_PROBE endstop to enable Z_MIN_PROBE_REPEATABILITY_TEST.
295
+      #else
296
+        #error AUTO_BED_LEVELING_FEATURE requires a Z_MIN or Z_PROBE endstop. Z_MIN_PIN or Z_MIN_PROBE_PIN must point to a valid hardware pin.
297
+      #endif
298
+    #endif
299
+  #endif
300
+
266 301
   /**
267 302
    * Check if Probe_Offset * Grid Points is greater than Probing Range
268 303
    */

+ 5
- 5
Marlin/endstops.cpp View File

@@ -45,7 +45,7 @@ Endstops::Endstops() {
45 45
     #endif
46 46
   );
47 47
   enable(true);
48
-  #if ENABLED(HAS_Z_MIN_PROBE)
48
+  #if HAS_BED_PROBE
49 49
     enable_z_probe(false);
50 50
   #endif
51 51
 } // Endstops::Endstops
@@ -108,7 +108,7 @@ void Endstops::init() {
108 108
     #endif
109 109
   #endif
110 110
 
111
-  #if HAS_Z_PROBE && ENABLED(Z_MIN_PROBE_ENDSTOP) // Check for Z_MIN_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
111
+  #if HAS_Z_MIN_PROBE_PIN && ENABLED(Z_MIN_PROBE_ENDSTOP) // Check for Z_MIN_PROBE_ENDSTOP so we don't pull a pin high unless it's to be used.
112 112
     SET_INPUT(Z_MIN_PROBE_PIN);
113 113
     #if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
114 114
       WRITE(Z_MIN_PROBE_PIN,HIGH);
@@ -195,7 +195,7 @@ void Endstops::M119() {
195 195
     SERIAL_PROTOCOLPGM(MSG_Z2_MAX);
196 196
     SERIAL_PROTOCOLLN(((READ(Z2_MAX_PIN)^Z2_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
197 197
   #endif
198
-  #if HAS_Z_PROBE
198
+  #if HAS_Z_MIN_PROBE_PIN
199 199
     SERIAL_PROTOCOLPGM(MSG_Z_PROBE);
200 200
     SERIAL_PROTOCOLLN(((READ(Z_MIN_PROBE_PIN)^Z_MIN_PROBE_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
201 201
   #endif
@@ -317,7 +317,7 @@ void Endstops::update() {
317 317
 
318 318
           #else // !Z_DUAL_ENDSTOPS
319 319
 
320
-            #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && ENABLED(HAS_Z_MIN_PROBE)
320
+            #if HAS_BED_PROBE && ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
321 321
               if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
322 322
             #else
323 323
               UPDATE_ENDSTOP(Z, MIN);
@@ -327,7 +327,7 @@ void Endstops::update() {
327 327
 
328 328
         #endif // HAS_Z_MIN
329 329
 
330
-        #if ENABLED(Z_MIN_PROBE_ENDSTOP) && DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) && ENABLED(HAS_Z_MIN_PROBE)
330
+        #if HAS_BED_PROBE && ENABLED(Z_MIN_PROBE_ENDSTOP) && DISABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
331 331
           if (z_probe_enabled) {
332 332
             UPDATE_ENDSTOP(Z, MIN_PROBE);
333 333
             if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);

+ 1
- 1
Marlin/endstops.h View File

@@ -88,7 +88,7 @@ class Endstops {
88 88
     FORCE_INLINE void hit_on_purpose() { endstop_hit_bits = 0; }
89 89
 
90 90
     // Enable / disable endstop z-probe checking
91
-    #if ENABLED(HAS_Z_MIN_PROBE)
91
+    #if HAS_BED_PROBE
92 92
       volatile bool z_probe_enabled = false;
93 93
       FORCE_INLINE void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
94 94
     #endif

+ 1
- 1
Marlin/stepper.cpp View File

@@ -282,7 +282,7 @@ void Stepper::isr() {
282 282
   if (current_block != NULL) {
283 283
 
284 284
     // Update endstops state, if enabled
285
-    #if ENABLED(HAS_Z_MIN_PROBE)
285
+    #if HAS_BED_PROBE
286 286
       if (endstops.enabled || endstops.z_probe_enabled) endstops.update();
287 287
     #else
288 288
       if (endstops.enabled) endstops.update();

Loading…
Cancel
Save