Skip to content

Commit

Permalink
Encapsulate dual Z endstop handling
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 1, 2016
1 parent 462a8a9 commit 24a1533
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
35 changes: 19 additions & 16 deletions Marlin/endstops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ void Endstops::M119() {
#endif
} // 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!
void Endstops::update() {

Expand Down Expand Up @@ -290,14 +305,7 @@ void Endstops::update() {
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
#endif

byte z_test = TEST_ENDSTOP(Z_MIN) | (TEST_ENDSTOP(Z2_MIN) << 1); // bit 0 for Z, bit 1 for Z2

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();
}
test_dual_z_endstops(Z_MIN, Z2_MIN);

#else // !Z_DUAL_ENDSTOPS

Expand Down Expand Up @@ -330,14 +338,7 @@ void Endstops::update() {
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
#endif

byte z_test = TEST_ENDSTOP(Z_MAX) | (TEST_ENDSTOP(Z2_MAX) << 1); // bit 0 for Z, bit 1 for Z2

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();
}
test_dual_z_endstops(Z_MAX, Z2_MAX);

#else // !Z_DUAL_ENDSTOPS

Expand All @@ -349,5 +350,7 @@ void Endstops::update() {
#if ENABLED(COREXZ)
}
#endif

old_endstop_bits = current_endstop_bits;

} // Endstops::update()
6 changes: 6 additions & 0 deletions Marlin/endstops.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ class Endstops {
volatile bool z_probe_enabled = false;
FORCE_INLINE void enable_z_probe(bool onoff=true) { z_probe_enabled = onoff; }
#endif

private:

#if ENABLED(Z_DUAL_ENDSTOPS)
void test_dual_z_endstops(EndstopEnum es1, EndstopEnum es2);
#endif
};

extern Endstops endstops;
Expand Down

0 comments on commit 24a1533

Please sign in to comment.