2016-04-27 14:15:20 +00:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
|
|
|
* Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
|
|
|
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* endstops.cpp - A singleton object to manage endstops
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Marlin.h"
|
2016-05-03 09:23:27 +00:00
|
|
|
#include "cardreader.h"
|
2016-04-27 14:15:20 +00:00
|
|
|
#include "endstops.h"
|
2016-05-03 09:23:27 +00:00
|
|
|
#include "temperature.h"
|
2016-04-27 14:15:20 +00:00
|
|
|
#include "stepper.h"
|
|
|
|
#include "ultralcd.h"
|
|
|
|
|
|
|
|
// TEST_ENDSTOP: test the old and the current status of an endstop
|
|
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits & old_endstop_bits, ENDSTOP))
|
|
|
|
|
|
|
|
Endstops endstops;
|
|
|
|
|
2016-05-26 18:01:20 +00:00
|
|
|
// public:
|
|
|
|
|
2017-07-18 08:17:50 +00:00
|
|
|
bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
|
2016-05-26 18:01:20 +00:00
|
|
|
volatile char Endstops::endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
|
|
|
|
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
|
|
uint16_t
|
|
|
|
#else
|
|
|
|
byte
|
|
|
|
#endif
|
|
|
|
Endstops::current_endstop_bits = 0,
|
|
|
|
Endstops::old_endstop_bits = 0;
|
|
|
|
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
volatile bool Endstops::z_probe_enabled = false;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class and Instance Methods
|
|
|
|
*/
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
void Endstops::init() {
|
|
|
|
|
|
|
|
#if HAS_X_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMIN)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(X_MIN_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(X_MIN_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Y_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMIN)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Y_MIN_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Y_MIN_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z_MIN_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MIN_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z2_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z2_MIN_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z2_MIN_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_X_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMAX)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(X_MAX_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(X_MAX_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Y_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMAX)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Y_MAX_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Y_MAX_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z_MAX_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MAX_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z2_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z2_MAX_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z2_MAX_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-09-19 04:28:11 +00:00
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
2016-04-27 14:15:20 +00:00
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z_MIN_PROBE_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MIN_PROBE_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
} // Endstops::init
|
|
|
|
|
|
|
|
void Endstops::report_state() {
|
|
|
|
if (endstop_hit_bits) {
|
|
|
|
#if ENABLED(ULTRA_LCD)
|
|
|
|
char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' ';
|
|
|
|
#define _SET_STOP_CHAR(A,C) (chr## A = C)
|
|
|
|
#else
|
|
|
|
#define _SET_STOP_CHAR(A,C) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define _ENDSTOP_HIT_ECHO(A,C) do{ \
|
|
|
|
SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", stepper.triggered_position_mm(A ##_AXIS)); \
|
|
|
|
_SET_STOP_CHAR(A,C); }while(0)
|
|
|
|
|
|
|
|
#define _ENDSTOP_HIT_TEST(A,C) \
|
|
|
|
if (TEST(endstop_hit_bits, A ##_MIN) || TEST(endstop_hit_bits, A ##_MAX)) \
|
|
|
|
_ENDSTOP_HIT_ECHO(A,C)
|
|
|
|
|
2017-05-02 19:29:18 +00:00
|
|
|
#define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X')
|
|
|
|
#define ENDSTOP_HIT_TEST_Y() _ENDSTOP_HIT_TEST(Y,'Y')
|
|
|
|
#define ENDSTOP_HIT_TEST_Z() _ENDSTOP_HIT_TEST(Z,'Z')
|
|
|
|
|
2017-06-09 15:51:23 +00:00
|
|
|
SERIAL_ECHO_START();
|
2016-04-27 14:15:20 +00:00
|
|
|
SERIAL_ECHOPGM(MSG_ENDSTOPS_HIT);
|
2017-05-02 19:29:18 +00:00
|
|
|
ENDSTOP_HIT_TEST_X();
|
|
|
|
ENDSTOP_HIT_TEST_Y();
|
|
|
|
ENDSTOP_HIT_TEST_Z();
|
2016-04-27 14:15:20 +00:00
|
|
|
|
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
|
|
|
#define P_AXIS Z_AXIS
|
|
|
|
if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
|
|
|
|
#endif
|
2017-06-09 15:51:23 +00:00
|
|
|
SERIAL_EOL();
|
2016-04-27 14:15:20 +00:00
|
|
|
|
|
|
|
#if ENABLED(ULTRA_LCD)
|
2017-04-02 05:46:37 +00:00
|
|
|
lcd_status_printf_P(0, PSTR(MSG_LCD_ENDSTOPS " %c %c %c %c"), chrX, chrY, chrZ, chrP);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
hit_on_purpose();
|
|
|
|
|
|
|
|
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
|
2016-05-03 09:23:27 +00:00
|
|
|
if (stepper.abort_on_endstop_hit) {
|
2016-04-27 14:15:20 +00:00
|
|
|
card.sdprinting = false;
|
|
|
|
card.closefile();
|
2016-07-06 19:00:28 +00:00
|
|
|
quickstop_stepper();
|
2016-04-29 01:18:13 +00:00
|
|
|
thermalManager.disable_all_heaters(); // switch off all heaters.
|
2016-04-27 14:15:20 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
} // Endstops::report_state
|
|
|
|
|
2016-04-27 21:46:24 +00:00
|
|
|
void Endstops::M119() {
|
2016-06-27 23:29:35 +00:00
|
|
|
SERIAL_PROTOCOLLNPGM(MSG_M119_REPORT);
|
2016-04-27 21:46:24 +00:00
|
|
|
#if HAS_X_MIN
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_X_MIN);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(X_MIN_PIN)^X_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_X_MAX);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(X_MAX_PIN)^X_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_Y_MIN);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Y_MIN_PIN)^Y_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_Y_MAX);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Y_MAX_PIN)^Y_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_Z_MIN);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Z_MIN_PIN)^Z_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
2016-10-29 06:54:02 +00:00
|
|
|
#if HAS_Z2_MIN
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_Z2_MIN);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Z2_MIN_PIN)^Z2_MIN_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
2016-04-27 21:46:24 +00:00
|
|
|
#if HAS_Z_MAX
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_Z_MAX);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Z_MAX_PIN)^Z_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_Z2_MAX);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Z2_MAX_PIN)^Z2_MAX_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
2016-09-19 04:28:11 +00:00
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
2016-04-27 21:46:24 +00:00
|
|
|
SERIAL_PROTOCOLPGM(MSG_Z_PROBE);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(Z_MIN_PROBE_PIN)^Z_MIN_PROBE_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
2017-01-21 23:10:57 +00:00
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_FILAMENT_RUNOUT_SENSOR);
|
|
|
|
SERIAL_PROTOCOLLN(((READ(FIL_RUNOUT_PIN)^FIL_RUNOUT_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN));
|
|
|
|
#endif
|
2016-04-27 21:46:24 +00:00
|
|
|
} // Endstops::M119
|
|
|
|
|
2016-04-28 09:15:53 +00:00
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
|
|
|
|
|
|
// Pass the result of the endstop test
|
2016-10-29 21:01:27 +00:00
|
|
|
void Endstops::test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2) {
|
2016-04-28 09:15:53 +00:00
|
|
|
byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
|
2016-10-27 12:41:39 +00:00
|
|
|
if (z_test && stepper.current_block->steps[Z_AXIS] > 0) {
|
2016-04-28 09:15:53 +00:00
|
|
|
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
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
// Check endstops - Called from ISR!
|
|
|
|
void Endstops::update() {
|
|
|
|
|
2016-08-22 14:58:48 +00:00
|
|
|
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
|
2016-04-27 14:15:20 +00:00
|
|
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
|
|
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
2017-08-03 03:52:40 +00:00
|
|
|
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(endstop_hit_bits, _ENDSTOP(AXIS, MINMAX))
|
2016-04-27 14:15:20 +00:00
|
|
|
|
|
|
|
// UPDATE_ENDSTOP_BIT: set the current endstop bits for an endstop to its status
|
|
|
|
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(current_endstop_bits, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
2016-08-22 14:58:48 +00:00
|
|
|
// COPY_BIT: copy the value of SRC_BIT to DST_BIT in DST
|
|
|
|
#define COPY_BIT(DST, SRC_BIT, DST_BIT) SET_BIT(DST, DST_BIT, TEST(DST, SRC_BIT))
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-01-12 01:06:03 +00:00
|
|
|
#define UPDATE_ENDSTOP(AXIS,MINMAX) do { \
|
2016-04-27 14:15:20 +00:00
|
|
|
UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \
|
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX)) && stepper.current_block->steps[_AXIS(AXIS)] > 0) { \
|
2017-08-03 03:52:40 +00:00
|
|
|
_ENDSTOP_HIT(AXIS, MINMAX); \
|
2016-04-27 14:15:20 +00:00
|
|
|
stepper.endstop_triggered(_AXIS(AXIS)); \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2016-09-26 06:30:34 +00:00
|
|
|
|
2017-01-12 01:06:03 +00:00
|
|
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ)
|
2017-04-14 00:32:37 +00:00
|
|
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
2017-01-12 01:06:03 +00:00
|
|
|
if (G38_move) {
|
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) {
|
2017-08-03 03:52:40 +00:00
|
|
|
if (stepper.current_block->steps[_AXIS(X)] > 0) { _ENDSTOP_HIT(X, MIN); stepper.endstop_triggered(_AXIS(X)); }
|
|
|
|
else if (stepper.current_block->steps[_AXIS(Y)] > 0) { _ENDSTOP_HIT(Y, MIN); stepper.endstop_triggered(_AXIS(Y)); }
|
|
|
|
else if (stepper.current_block->steps[_AXIS(Z)] > 0) { _ENDSTOP_HIT(Z, MIN); stepper.endstop_triggered(_AXIS(Z)); }
|
2017-01-12 01:06:03 +00:00
|
|
|
G38_endstop_hit = true;
|
|
|
|
}
|
|
|
|
}
|
2016-09-26 06:30:34 +00:00
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
/**
|
|
|
|
* Define conditions for checking endstops
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if IS_CORE
|
|
|
|
#define S_(N) stepper.current_block->steps[CORE_AXIS_##N]
|
|
|
|
#define D_(N) stepper.motor_direction(CORE_AXIS_##N)
|
|
|
|
#endif
|
2017-04-14 00:32:37 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
#if CORE_IS_XY || CORE_IS_XZ
|
2017-04-14 00:32:37 +00:00
|
|
|
/**
|
|
|
|
* Head direction in -X axis for CoreXY and CoreXZ bots.
|
|
|
|
*
|
|
|
|
* If steps differ, both axes are moving.
|
|
|
|
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z, handled below)
|
|
|
|
* If DeltaA == DeltaB, the movement is only in the 1st axis (X)
|
|
|
|
*/
|
2017-04-15 09:23:20 +00:00
|
|
|
#if ENABLED(COREXY) || ENABLED(COREXZ)
|
|
|
|
#define X_CMP ==
|
2017-02-22 03:42:52 +00:00
|
|
|
#else
|
2017-04-15 09:23:20 +00:00
|
|
|
#define X_CMP !=
|
2017-02-22 03:42:52 +00:00
|
|
|
#endif
|
2017-04-15 09:23:20 +00:00
|
|
|
#define X_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) X_CMP D_(2)) )
|
|
|
|
#define X_AXIS_HEAD X_HEAD
|
|
|
|
#else
|
|
|
|
#define X_MOVE_TEST stepper.current_block->steps[X_AXIS] > 0
|
|
|
|
#define X_AXIS_HEAD X_AXIS
|
2017-02-22 03:42:52 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-06 04:47:38 +00:00
|
|
|
#if CORE_IS_XY || CORE_IS_YZ
|
2017-04-14 00:32:37 +00:00
|
|
|
/**
|
|
|
|
* Head direction in -Y axis for CoreXY / CoreYZ bots.
|
|
|
|
*
|
|
|
|
* If steps differ, both axes are moving
|
|
|
|
* If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y)
|
|
|
|
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Y or Z)
|
|
|
|
*/
|
2017-04-15 09:23:20 +00:00
|
|
|
#if ENABLED(COREYX) || ENABLED(COREYZ)
|
|
|
|
#define Y_CMP ==
|
|
|
|
#else
|
|
|
|
#define Y_CMP !=
|
|
|
|
#endif
|
|
|
|
#define Y_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Y_CMP D_(2)) )
|
|
|
|
#define Y_AXIS_HEAD Y_HEAD
|
2016-04-27 14:15:20 +00:00
|
|
|
#else
|
2017-04-15 09:23:20 +00:00
|
|
|
#define Y_MOVE_TEST stepper.current_block->steps[Y_AXIS] > 0
|
|
|
|
#define Y_AXIS_HEAD Y_AXIS
|
2017-04-14 00:32:37 +00:00
|
|
|
#endif
|
|
|
|
|
2016-11-06 04:47:38 +00:00
|
|
|
#if CORE_IS_XZ || CORE_IS_YZ
|
2017-04-14 00:32:37 +00:00
|
|
|
/**
|
|
|
|
* Head direction in -Z axis for CoreXZ or CoreYZ bots.
|
|
|
|
*
|
|
|
|
* If steps differ, both axes are moving
|
|
|
|
* If DeltaA == DeltaB, the movement is only in the 1st axis (X or Y, already handled above)
|
|
|
|
* If DeltaA == -DeltaB, the movement is only in the 2nd axis (Z)
|
|
|
|
*/
|
2017-04-15 09:23:20 +00:00
|
|
|
#if ENABLED(COREZX) || ENABLED(COREZY)
|
|
|
|
#define Z_CMP ==
|
|
|
|
#else
|
|
|
|
#define Z_CMP !=
|
|
|
|
#endif
|
|
|
|
#define Z_MOVE_TEST ( S_(1) != S_(2) || (S_(1) > 0 && D_(1) Z_CMP D_(2)) )
|
|
|
|
#define Z_AXIS_HEAD Z_HEAD
|
2016-04-27 14:15:20 +00:00
|
|
|
#else
|
2017-04-15 09:23:20 +00:00
|
|
|
#define Z_MOVE_TEST stepper.current_block->steps[Z_AXIS] > 0
|
|
|
|
#define Z_AXIS_HEAD Z_AXIS
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
// With Dual X, endstops are only checked in the homing direction for the active extruder
|
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
|
|
|
#define E0_ACTIVE stepper.current_block->active_extruder == 0
|
|
|
|
#define X_MIN_TEST ((X_HOME_DIR < 0 && E0_ACTIVE) || (X2_HOME_DIR < 0 && !E0_ACTIVE))
|
|
|
|
#define X_MAX_TEST ((X_HOME_DIR > 0 && E0_ACTIVE) || (X2_HOME_DIR > 0 && !E0_ACTIVE))
|
|
|
|
#else
|
|
|
|
#define X_MIN_TEST true
|
|
|
|
#define X_MAX_TEST true
|
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
/**
|
|
|
|
* Check and update endstops according to conditions
|
|
|
|
*/
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
if (X_MOVE_TEST) {
|
|
|
|
if (stepper.motor_direction(X_AXIS_HEAD)) {
|
|
|
|
if (X_MIN_TEST) { // -direction
|
|
|
|
#if HAS_X_MIN
|
|
|
|
UPDATE_ENDSTOP(X, MIN);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (X_MAX_TEST) { // +direction
|
|
|
|
#if HAS_X_MAX
|
|
|
|
UPDATE_ENDSTOP(X, MAX);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
if (Y_MOVE_TEST) {
|
|
|
|
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
|
|
|
|
#if HAS_Y_MIN
|
|
|
|
UPDATE_ENDSTOP(Y, MIN);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else { // +direction
|
|
|
|
#if HAS_Y_MAX
|
|
|
|
UPDATE_ENDSTOP(Y, MAX);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
if (Z_MOVE_TEST) {
|
|
|
|
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
|
|
|
|
#if HAS_Z_MIN
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN);
|
|
|
|
#if HAS_Z2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN);
|
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
test_dual_z_endstops(Z_MIN, Z2_MIN);
|
|
|
|
|
|
|
|
#else // !Z_DUAL_ENDSTOPS
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
|
|
|
if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN);
|
|
|
|
#else
|
|
|
|
UPDATE_ENDSTOP(Z, MIN);
|
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
#endif // !Z_DUAL_ENDSTOPS
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
#endif // HAS_Z_MIN
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
// When closing the gap check the enabled probe
|
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
|
|
|
if (z_probe_enabled) {
|
|
|
|
UPDATE_ENDSTOP(Z, MIN_PROBE);
|
|
|
|
if (TEST_ENDSTOP(Z_MIN_PROBE)) SBI(endstop_hit_bits, Z_MIN_PROBE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else { // Z +direction. Gantry up, bed down.
|
|
|
|
#if HAS_Z_MAX
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
// Check both Z dual endstops
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
UPDATE_ENDSTOP_BIT(Z, MAX);
|
|
|
|
#if HAS_Z2_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MAX);
|
|
|
|
#else
|
|
|
|
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
test_dual_z_endstops(Z_MAX, Z2_MAX);
|
|
|
|
|
|
|
|
// If this pin is not hijacked for the bed probe
|
|
|
|
// then it belongs to the Z endstop
|
|
|
|
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
|
|
|
|
|
|
|
UPDATE_ENDSTOP(Z, MAX);
|
|
|
|
|
|
|
|
#endif // !Z_MIN_PROBE_PIN...
|
|
|
|
#endif // Z_MAX_PIN
|
2016-04-27 14:15:20 +00:00
|
|
|
}
|
2017-04-15 09:23:20 +00:00
|
|
|
}
|
2016-04-28 09:15:53 +00:00
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
old_endstop_bits = current_endstop_bits;
|
2016-04-28 09:15:53 +00:00
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
} // Endstops::update()
|