Browse Source

Encapsulate dual Z endstop handling

Scott Lahteine 8 years ago
parent
commit
24a15332b3
2 changed files with 25 additions and 16 deletions
  1. 19
    16
      Marlin/endstops.cpp
  2. 6
    0
      Marlin/endstops.h

+ 19
- 16
Marlin/endstops.cpp View File

193
   #endif
193
   #endif
194
 } // Endstops::M119
194
 } // Endstops::M119
195
 
195
 
196
+#if ENABLED(Z_DUAL_ENDSTOPS)
197
+
198
+  // Pass the result of the endstop test
199
+  void Endstops::test_dual_z_endstops(EndstopEnum es1, EndstopEnum es2) {
200
+    byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
201
+    if (stepper.current_block->steps[Z_AXIS] > 0) {
202
+      stepper.endstop_triggered(Z_AXIS);
203
+      SBI(endstop_hit_bits, Z_MIN);
204
+      if (!stepper.performing_homing || (z_test == 0x3))  //if not performing home or if both endstops were trigged during homing...
205
+        stepper.kill_current_block();
206
+    }
207
+  }
208
+
209
+#endif
210
+
196
 // Check endstops - Called from ISR!
211
 // Check endstops - Called from ISR!
197
 void Endstops::update() {
212
 void Endstops::update() {
198
 
213
 
290
               COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
305
               COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
291
             #endif
306
             #endif
292
 
307
 
293
-            byte z_test = TEST_ENDSTOP(Z_MIN) | (TEST_ENDSTOP(Z2_MIN) << 1); // bit 0 for Z, bit 1 for Z2
294
-
295
-            if (z_test && stepper.current_block->steps[Z_AXIS] > 0) { // z_test = Z_MIN || Z2_MIN
296
-              stepper.endstop_triggered(Z_AXIS);
297
-              SBI(endstop_hit_bits, Z_MIN);
298
-              if (!performing_homing || (z_test == 0x3))  //if not performing home or if both endstops were trigged during homing...
299
-                stepper.kill_current_block();
300
-            }
308
+            test_dual_z_endstops(Z_MIN, Z2_MIN);
301
 
309
 
302
           #else // !Z_DUAL_ENDSTOPS
310
           #else // !Z_DUAL_ENDSTOPS
303
 
311
 
330
               COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
338
               COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
331
             #endif
339
             #endif
332
 
340
 
333
-            byte z_test = TEST_ENDSTOP(Z_MAX) | (TEST_ENDSTOP(Z2_MAX) << 1); // bit 0 for Z, bit 1 for Z2
334
-
335
-            if (z_test && stepper.current_block->steps[Z_AXIS] > 0) {  // t_test = Z_MAX || Z2_MAX
336
-              stepper.endstop_triggered(Z_AXIS);
337
-              SBI(endstop_hit_bits, Z_MIN);
338
-              if (!performing_homing || (z_test == 0x3))  //if not performing home or if both endstops were trigged during homing...
339
-                stepper.kill_current_block();
340
-            }
341
+            test_dual_z_endstops(Z_MAX, Z2_MAX);
341
 
342
 
342
           #else // !Z_DUAL_ENDSTOPS
343
           #else // !Z_DUAL_ENDSTOPS
343
 
344
 
349
   #if ENABLED(COREXZ)
350
   #if ENABLED(COREXZ)
350
     }
351
     }
351
   #endif
352
   #endif
353
+
352
   old_endstop_bits = current_endstop_bits;
354
   old_endstop_bits = current_endstop_bits;
355
+
353
 } // Endstops::update()
356
 } // Endstops::update()

+ 6
- 0
Marlin/endstops.h View File

92
       volatile bool z_probe_enabled = false;
92
       volatile bool z_probe_enabled = false;
93
       FORCE_INLINE void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
93
       FORCE_INLINE void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
94
     #endif
94
     #endif
95
+
96
+  private:
97
+
98
+    #if ENABLED(Z_DUAL_ENDSTOPS)
99
+      void test_dual_z_endstops(EndstopEnum es1, EndstopEnum es2);
100
+    #endif
95
 };
101
 };
96
 
102
 
97
 extern Endstops endstops;
103
 extern Endstops endstops;

Loading…
Cancel
Save