Encapsulate dual Z endstop handling

This commit is contained in:
Scott Lahteine 2016-04-28 02:15:53 -07:00
parent 462a8a951e
commit 24a15332b3
2 changed files with 25 additions and 16 deletions

View file

@ -193,6 +193,21 @@ void Endstops::M119() {
#endif #endif
} // Endstops::M119 } // Endstops::M119
#if ENABLED(Z_DUAL_ENDSTOPS)
// Pass the result of the endstop test
void Endstops::test_dual_z_endstops(EndstopEnum es1, EndstopEnum es2) {
byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
if (stepper.current_block->steps[Z_AXIS] > 0) {
stepper.endstop_triggered(Z_AXIS);
SBI(endstop_hit_bits, Z_MIN);
if (!stepper.performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
stepper.kill_current_block();
}
}
#endif
// Check endstops - Called from ISR! // Check endstops - Called from ISR!
void Endstops::update() { void Endstops::update() {
@ -290,14 +305,7 @@ void Endstops::update() {
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN); COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
#endif #endif
byte z_test = TEST_ENDSTOP(Z_MIN) | (TEST_ENDSTOP(Z2_MIN) << 1); // bit 0 for Z, bit 1 for Z2 test_dual_z_endstops(Z_MIN, Z2_MIN);
if (z_test && stepper.current_block->steps[Z_AXIS] > 0) { // z_test = Z_MIN || Z2_MIN
stepper.endstop_triggered(Z_AXIS);
SBI(endstop_hit_bits, Z_MIN);
if (!performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
stepper.kill_current_block();
}
#else // !Z_DUAL_ENDSTOPS #else // !Z_DUAL_ENDSTOPS
@ -330,14 +338,7 @@ void Endstops::update() {
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX); COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
#endif #endif
byte z_test = TEST_ENDSTOP(Z_MAX) | (TEST_ENDSTOP(Z2_MAX) << 1); // bit 0 for Z, bit 1 for Z2 test_dual_z_endstops(Z_MAX, Z2_MAX);
if (z_test && stepper.current_block->steps[Z_AXIS] > 0) { // t_test = Z_MAX || Z2_MAX
stepper.endstop_triggered(Z_AXIS);
SBI(endstop_hit_bits, Z_MIN);
if (!performing_homing || (z_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
stepper.kill_current_block();
}
#else // !Z_DUAL_ENDSTOPS #else // !Z_DUAL_ENDSTOPS
@ -349,5 +350,7 @@ void Endstops::update() {
#if ENABLED(COREXZ) #if ENABLED(COREXZ)
} }
#endif #endif
old_endstop_bits = current_endstop_bits; old_endstop_bits = current_endstop_bits;
} // Endstops::update() } // Endstops::update()

View file

@ -92,6 +92,12 @@ class Endstops {
volatile bool z_probe_enabled = false; volatile bool z_probe_enabled = false;
FORCE_INLINE void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; } FORCE_INLINE void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
#endif #endif
private:
#if ENABLED(Z_DUAL_ENDSTOPS)
void test_dual_z_endstops(EndstopEnum es1, EndstopEnum es2);
#endif
}; };
extern Endstops endstops; extern Endstops endstops;