|
|
@ -36,9 +36,6 @@ |
|
|
|
#include HAL_PATH(../HAL, endstop_interrupts.h) |
|
|
|
#endif |
|
|
|
|
|
|
|
// TEST_ENDSTOP: test the current status of an endstop
|
|
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(current_endstop_bits, ENDSTOP)) |
|
|
|
|
|
|
|
#if HAS_BED_PROBE |
|
|
|
#define ENDSTOPS_ENABLED (endstops.enabled || endstops.z_probe_enabled) |
|
|
|
#else |
|
|
@ -50,9 +47,14 @@ Endstops endstops; |
|
|
|
// public:
|
|
|
|
|
|
|
|
bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
|
|
|
|
volatile uint8_t Endstops::endstop_hit_bits; // use X_MIN, Y_MIN, Z_MIN and Z_MIN_PROBE as BIT value
|
|
|
|
volatile uint8_t Endstops::hit_state; |
|
|
|
|
|
|
|
Endstops::esbits_t Endstops::current_endstop_bits = 0; |
|
|
|
Endstops::esbits_t Endstops::live_state = 0; |
|
|
|
#if ENABLED(ENDSTOP_NOISE_FILTER) |
|
|
|
Endstops::esbits_t Endstops::old_live_state, |
|
|
|
Endstops::validated_live_state; |
|
|
|
uint8_t Endstops::endstop_poll_count; |
|
|
|
#endif |
|
|
|
|
|
|
|
#if HAS_BED_PROBE |
|
|
|
volatile bool Endstops::z_probe_enabled = false; |
|
|
@ -230,7 +232,7 @@ void Endstops::poll() { |
|
|
|
endstops.run_monitor(); // report changes in endstop status
|
|
|
|
#endif |
|
|
|
|
|
|
|
#if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) |
|
|
|
#if DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER) |
|
|
|
if (ENDSTOPS_ENABLED) endstops.update(); |
|
|
|
#endif |
|
|
|
} |
|
|
@ -264,7 +266,7 @@ void Endstops::not_homing() { |
|
|
|
|
|
|
|
// Clear endstops (i.e., they were hit intentionally) to suppress the report
|
|
|
|
void Endstops::hit_on_purpose() { |
|
|
|
endstop_hit_bits = 0; |
|
|
|
hit_state = 0; |
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) |
|
|
|
if (enabled) endstops.update(); // If enabling, update state now
|
|
|
@ -293,7 +295,7 @@ void Endstops::hit_on_purpose() { |
|
|
|
#endif |
|
|
|
|
|
|
|
void Endstops::report_state() { |
|
|
|
if (endstop_hit_bits) { |
|
|
|
if (hit_state) { |
|
|
|
#if ENABLED(ULTRA_LCD) |
|
|
|
char chrX = ' ', chrY = ' ', chrZ = ' ', chrP = ' '; |
|
|
|
#define _SET_STOP_CHAR(A,C) (chr## A = C) |
|
|
@ -306,7 +308,7 @@ void Endstops::report_state() { |
|
|
|
_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)) \ |
|
|
|
if (TEST(hit_state, A ##_MIN) || TEST(hit_state, A ##_MAX)) \ |
|
|
|
_ENDSTOP_HIT_ECHO(A,C) |
|
|
|
|
|
|
|
#define ENDSTOP_HIT_TEST_X() _ENDSTOP_HIT_TEST(X,'X') |
|
|
@ -321,7 +323,7 @@ void Endstops::report_state() { |
|
|
|
|
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP) |
|
|
|
#define P_AXIS Z_AXIS |
|
|
|
if (TEST(endstop_hit_bits, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P'); |
|
|
|
if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P'); |
|
|
|
#endif |
|
|
|
SERIAL_EOL(); |
|
|
|
|
|
|
@ -397,69 +399,23 @@ void Endstops::M119() { |
|
|
|
// The following routines are called from an ISR context. It could be the temperature ISR, the
|
|
|
|
// endstop ISR or the Stepper ISR.
|
|
|
|
|
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS) |
|
|
|
void Endstops::test_dual_x_endstops(const EndstopEnum es1, const EndstopEnum es2) { |
|
|
|
const byte x_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for X, bit 1 for X2
|
|
|
|
if (x_test && stepper.movement_non_null(X_AXIS)) { |
|
|
|
SBI(endstop_hit_bits, X_MIN); |
|
|
|
if (!stepper.performing_homing || (x_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
|
|
|
|
stepper.quick_stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS) |
|
|
|
void Endstops::test_dual_y_endstops(const EndstopEnum es1, const EndstopEnum es2) { |
|
|
|
const byte y_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Y, bit 1 for Y2
|
|
|
|
if (y_test && stepper.movement_non_null(Y_AXIS)) { |
|
|
|
SBI(endstop_hit_bits, Y_MIN); |
|
|
|
if (!stepper.performing_homing || (y_test == 0x3)) //if not performing home or if both endstops were trigged during homing...
|
|
|
|
stepper.quick_stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
|
void Endstops::test_dual_z_endstops(const EndstopEnum es1, const EndstopEnum es2) { |
|
|
|
const byte z_test = TEST_ENDSTOP(es1) | (TEST_ENDSTOP(es2) << 1); // bit 0 for Z, bit 1 for Z2
|
|
|
|
if (z_test && stepper.movement_non_null(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.quick_stop(); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX |
|
|
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN |
|
|
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING |
|
|
|
|
|
|
|
// Check endstops - Could be called from ISR!
|
|
|
|
void Endstops::update() { |
|
|
|
|
|
|
|
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX |
|
|
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN |
|
|
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING |
|
|
|
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(endstop_hit_bits, _ENDSTOP(AXIS, MINMAX)) |
|
|
|
|
|
|
|
#define SET_BIT(N,B,TF) do{ if (TF) SBI(N,B); else CBI(N,B); }while(0) |
|
|
|
// 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))) |
|
|
|
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX))) |
|
|
|
// 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)) |
|
|
|
|
|
|
|
#define UPDATE_ENDSTOP(AXIS,MINMAX) do { \ |
|
|
|
UPDATE_ENDSTOP_BIT(AXIS, MINMAX); \ |
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \ |
|
|
|
_ENDSTOP_HIT(AXIS, MINMAX); \ |
|
|
|
planner.endstop_triggered(_AXIS(AXIS)); \ |
|
|
|
} \ |
|
|
|
}while(0) |
|
|
|
|
|
|
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ) |
|
|
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
|
|
|
if (G38_move) { |
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE); |
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) { |
|
|
|
if (stepper.movement_non_null(_AXIS(X))) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(_AXIS(X)); } |
|
|
|
else if (stepper.movement_non_null(_AXIS(Y))) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(_AXIS(Y)); } |
|
|
|
else if (stepper.movement_non_null(_AXIS(Z))) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(_AXIS(Z)); } |
|
|
|
G38_endstop_hit = true; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
@ -553,11 +509,10 @@ void Endstops::update() { |
|
|
|
#if HAS_X2_MIN |
|
|
|
UPDATE_ENDSTOP_BIT(X2, MIN); |
|
|
|
#else |
|
|
|
COPY_BIT(current_endstop_bits, X_MIN, X2_MIN); |
|
|
|
COPY_BIT(live_state, X_MIN, X2_MIN); |
|
|
|
#endif |
|
|
|
test_dual_x_endstops(X_MIN, X2_MIN); |
|
|
|
#else |
|
|
|
if (X_MIN_TEST) UPDATE_ENDSTOP(X, MIN); |
|
|
|
if (X_MIN_TEST) UPDATE_ENDSTOP_BIT(X, MIN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
@ -568,11 +523,10 @@ void Endstops::update() { |
|
|
|
#if HAS_X2_MAX |
|
|
|
UPDATE_ENDSTOP_BIT(X2, MAX); |
|
|
|
#else |
|
|
|
COPY_BIT(current_endstop_bits, X_MAX, X2_MAX); |
|
|
|
COPY_BIT(live_state, X_MAX, X2_MAX); |
|
|
|
#endif |
|
|
|
test_dual_x_endstops(X_MAX, X2_MAX); |
|
|
|
#else |
|
|
|
if (X_MAX_TEST) UPDATE_ENDSTOP(X, MAX); |
|
|
|
if (X_MAX_TEST) UPDATE_ENDSTOP_BIT(X, MAX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
@ -586,11 +540,10 @@ void Endstops::update() { |
|
|
|
#if HAS_Y2_MIN |
|
|
|
UPDATE_ENDSTOP_BIT(Y2, MIN); |
|
|
|
#else |
|
|
|
COPY_BIT(current_endstop_bits, Y_MIN, Y2_MIN); |
|
|
|
COPY_BIT(live_state, Y_MIN, Y2_MIN); |
|
|
|
#endif |
|
|
|
test_dual_y_endstops(Y_MIN, Y2_MIN); |
|
|
|
#else |
|
|
|
UPDATE_ENDSTOP(Y, MIN); |
|
|
|
UPDATE_ENDSTOP_BIT(Y, MIN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
@ -601,11 +554,10 @@ void Endstops::update() { |
|
|
|
#if HAS_Y2_MAX |
|
|
|
UPDATE_ENDSTOP_BIT(Y2, MAX); |
|
|
|
#else |
|
|
|
COPY_BIT(current_endstop_bits, Y_MAX, Y2_MAX); |
|
|
|
COPY_BIT(live_state, Y_MAX, Y2_MAX); |
|
|
|
#endif |
|
|
|
test_dual_y_endstops(Y_MAX, Y2_MAX); |
|
|
|
#else |
|
|
|
UPDATE_ENDSTOP(Y, MAX); |
|
|
|
UPDATE_ENDSTOP_BIT(Y, MAX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
@ -619,14 +571,13 @@ void Endstops::update() { |
|
|
|
#if HAS_Z2_MIN |
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MIN); |
|
|
|
#else |
|
|
|
COPY_BIT(current_endstop_bits, Z_MIN, Z2_MIN); |
|
|
|
COPY_BIT(live_state, Z_MIN, Z2_MIN); |
|
|
|
#endif |
|
|
|
test_dual_z_endstops(Z_MIN, Z2_MIN); |
|
|
|
#else |
|
|
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) |
|
|
|
if (z_probe_enabled) UPDATE_ENDSTOP(Z, MIN); |
|
|
|
if (z_probe_enabled) UPDATE_ENDSTOP_BIT(Z, MIN); |
|
|
|
#else |
|
|
|
UPDATE_ENDSTOP(Z, MIN); |
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -634,8 +585,7 @@ void Endstops::update() { |
|
|
|
// 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); |
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE); |
|
|
|
} |
|
|
|
#endif |
|
|
|
} |
|
|
@ -647,13 +597,149 @@ void Endstops::update() { |
|
|
|
#if HAS_Z2_MAX |
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MAX); |
|
|
|
#else |
|
|
|
COPY_BIT(current_endstop_bits, Z_MAX, Z2_MAX); |
|
|
|
COPY_BIT(live_state, 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); |
|
|
|
UPDATE_ENDSTOP_BIT(Z, MAX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// All endstops were updated.
|
|
|
|
#if ENABLED(ENDSTOP_NOISE_FILTER) |
|
|
|
if (old_live_state != live_state) { // We detected a change. Reinit the timeout
|
|
|
|
/**
|
|
|
|
* Filtering out noise on endstops requires a delayed decision. Let's assume, due to noise, |
|
|
|
* that 50% of endstop signal samples are good and 50% are bad (assuming normal distribution |
|
|
|
* of random noise). Then the first sample has a 50% chance to be good or bad. The 2nd sample |
|
|
|
* also has a 50% chance to be good or bad. The chances of 2 samples both being bad becomes |
|
|
|
* 50% of 50%, or 25%. That was the previous implementation of Marlin endstop handling. It |
|
|
|
* reduces chances of bad readings in half, at the cost of 1 extra sample period, but chances |
|
|
|
* still exist. The only way to reduce them further is to increase the number of samples. |
|
|
|
* To reduce the chance to 1% (1/128th) requires 7 samples (adding 7ms of delay). |
|
|
|
*/ |
|
|
|
endstop_poll_count = 7; |
|
|
|
old_live_state = live_state; |
|
|
|
} |
|
|
|
else if (endstop_poll_count && !--endstop_poll_count) |
|
|
|
validated_live_state = live_state; |
|
|
|
|
|
|
|
#else |
|
|
|
|
|
|
|
// Lets accept the new endstop values as valid - We assume hardware filtering of lines
|
|
|
|
esbits_t validated_live_state = live_state; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
// Endstop readings are validated in validated_live_state
|
|
|
|
|
|
|
|
// Test the current status of an endstop
|
|
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(validated_live_state, ENDSTOP)) |
|
|
|
|
|
|
|
// Record endstop was hit
|
|
|
|
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX)) |
|
|
|
|
|
|
|
// Call the endstop triggered routine for single endstops
|
|
|
|
#define PROCESS_ENDSTOP(AXIS,MINMAX) do { \ |
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \ |
|
|
|
_ENDSTOP_HIT(AXIS, MINMAX); \ |
|
|
|
planner.endstop_triggered(_AXIS(AXIS)); \ |
|
|
|
} \ |
|
|
|
}while(0) |
|
|
|
|
|
|
|
// Call the endstop triggered routine for single endstops
|
|
|
|
#define PROCESS_DUAL_ENDSTOP(AXIS1, AXIS2, MINMAX) do { \ |
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) || TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX))) { \ |
|
|
|
_ENDSTOP_HIT(AXIS1, MINMAX); \ |
|
|
|
planner.endstop_triggered(_AXIS(AXIS1)); \ |
|
|
|
} \ |
|
|
|
}while(0) |
|
|
|
|
|
|
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && !(CORE_IS_XY || CORE_IS_XZ) |
|
|
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
|
|
|
if (G38_move) { |
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE))) { |
|
|
|
if (stepper.movement_non_null(_AXIS(X))) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(_AXIS(X)); } |
|
|
|
else if (stepper.movement_non_null(_AXIS(Y))) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(_AXIS(Y)); } |
|
|
|
else if (stepper.movement_non_null(_AXIS(Z))) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(_AXIS(Z)); } |
|
|
|
G38_endstop_hit = true; |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
|
|
|
|
// Now, we must signal, after validation, if an endstop limit is pressed or not
|
|
|
|
if (X_MOVE_TEST) { |
|
|
|
if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
|
|
|
|
#if HAS_X_MIN |
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS) |
|
|
|
PROCESS_DUAL_ENDSTOP(X, X2, MIN); |
|
|
|
#else |
|
|
|
if (X_MIN_TEST) PROCESS_ENDSTOP(X, MIN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
else { // +direction
|
|
|
|
#if HAS_X_MAX |
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS) |
|
|
|
PROCESS_DUAL_ENDSTOP(X, X2, MAX); |
|
|
|
#else |
|
|
|
if (X_MAX_TEST) PROCESS_ENDSTOP(X, MAX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (Y_MOVE_TEST) { |
|
|
|
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
|
|
|
|
#if HAS_Y_MIN |
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS) |
|
|
|
PROCESS_DUAL_ENDSTOP(Y, Y2, MIN); |
|
|
|
#else |
|
|
|
PROCESS_ENDSTOP(Y, MIN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
else { // +direction
|
|
|
|
#if HAS_Y_MAX |
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS) |
|
|
|
PROCESS_DUAL_ENDSTOP(Y, Y2, MAX); |
|
|
|
#else |
|
|
|
PROCESS_ENDSTOP(Y, MAX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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) |
|
|
|
PROCESS_DUAL_ENDSTOP(Z, Z2, MIN); |
|
|
|
#else |
|
|
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) |
|
|
|
if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN); |
|
|
|
#else |
|
|
|
PROCESS_ENDSTOP(Z, MIN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
// When closing the gap check the enabled probe
|
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP) |
|
|
|
if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN_PROBE); |
|
|
|
#endif |
|
|
|
} |
|
|
|
else { // Z +direction. Gantry up, bed down.
|
|
|
|
#if HAS_Z_MAX |
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS) |
|
|
|
PROCESS_DUAL_ENDSTOP(Z, Z2, MAX); |
|
|
|
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN |
|
|
|
// If this pin is not hijacked for the bed probe
|
|
|
|
// then it belongs to the Z endstop
|
|
|
|
PROCESS_ENDSTOP(Z, MAX); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
@ -676,96 +762,96 @@ void Endstops::update() { |
|
|
|
*/ |
|
|
|
void Endstops::monitor() { |
|
|
|
|
|
|
|
static uint16_t old_endstop_bits_local = 0; |
|
|
|
static uint16_t old_live_state_local = 0; |
|
|
|
static uint8_t local_LED_status = 0; |
|
|
|
uint16_t current_endstop_bits_local = 0; |
|
|
|
uint16_t live_state_local = 0; |
|
|
|
|
|
|
|
#if HAS_X_MIN |
|
|
|
if (READ(X_MIN_PIN)) SBI(current_endstop_bits_local, X_MIN); |
|
|
|
if (READ(X_MIN_PIN)) SBI(live_state_local, X_MIN); |
|
|
|
#endif |
|
|
|
#if HAS_X_MAX |
|
|
|
if (READ(X_MAX_PIN)) SBI(current_endstop_bits_local, X_MAX); |
|
|
|
if (READ(X_MAX_PIN)) SBI(live_state_local, X_MAX); |
|
|
|
#endif |
|
|
|
#if HAS_Y_MIN |
|
|
|
if (READ(Y_MIN_PIN)) SBI(current_endstop_bits_local, Y_MIN); |
|
|
|
if (READ(Y_MIN_PIN)) SBI(live_state_local, Y_MIN); |
|
|
|
#endif |
|
|
|
#if HAS_Y_MAX |
|
|
|
if (READ(Y_MAX_PIN)) SBI(current_endstop_bits_local, Y_MAX); |
|
|
|
if (READ(Y_MAX_PIN)) SBI(live_state_local, Y_MAX); |
|
|
|
#endif |
|
|
|
#if HAS_Z_MIN |
|
|
|
if (READ(Z_MIN_PIN)) SBI(current_endstop_bits_local, Z_MIN); |
|
|
|
if (READ(Z_MIN_PIN)) SBI(live_state_local, Z_MIN); |
|
|
|
#endif |
|
|
|
#if HAS_Z_MAX |
|
|
|
if (READ(Z_MAX_PIN)) SBI(current_endstop_bits_local, Z_MAX); |
|
|
|
if (READ(Z_MAX_PIN)) SBI(live_state_local, Z_MAX); |
|
|
|
#endif |
|
|
|
#if HAS_Z_MIN_PROBE_PIN |
|
|
|
if (READ(Z_MIN_PROBE_PIN)) SBI(current_endstop_bits_local, Z_MIN_PROBE); |
|
|
|
if (READ(Z_MIN_PROBE_PIN)) SBI(live_state_local, Z_MIN_PROBE); |
|
|
|
#endif |
|
|
|
#if HAS_X2_MIN |
|
|
|
if (READ(X2_MIN_PIN)) SBI(current_endstop_bits_local, X2_MIN); |
|
|
|
if (READ(X2_MIN_PIN)) SBI(live_state_local, X2_MIN); |
|
|
|
#endif |
|
|
|
#if HAS_X2_MAX |
|
|
|
if (READ(X2_MAX_PIN)) SBI(current_endstop_bits_local, X2_MAX); |
|
|
|
if (READ(X2_MAX_PIN)) SBI(live_state_local, X2_MAX); |
|
|
|
#endif |
|
|
|
#if HAS_Y2_MIN |
|
|
|
if (READ(Y2_MIN_PIN)) SBI(current_endstop_bits_local, Y2_MIN); |
|
|
|
if (READ(Y2_MIN_PIN)) SBI(live_state_local, Y2_MIN); |
|
|
|
#endif |
|
|
|
#if HAS_Y2_MAX |
|
|
|
if (READ(Y2_MAX_PIN)) SBI(current_endstop_bits_local, Y2_MAX); |
|
|
|
if (READ(Y2_MAX_PIN)) SBI(live_state_local, Y2_MAX); |
|
|
|
#endif |
|
|
|
#if HAS_Z2_MIN |
|
|
|
if (READ(Z2_MIN_PIN)) SBI(current_endstop_bits_local, Z2_MIN); |
|
|
|
if (READ(Z2_MIN_PIN)) SBI(live_state_local, Z2_MIN); |
|
|
|
#endif |
|
|
|
#if HAS_Z2_MAX |
|
|
|
if (READ(Z2_MAX_PIN)) SBI(current_endstop_bits_local, Z2_MAX); |
|
|
|
if (READ(Z2_MAX_PIN)) SBI(live_state_local, Z2_MAX); |
|
|
|
#endif |
|
|
|
|
|
|
|
uint16_t endstop_change = current_endstop_bits_local ^ old_endstop_bits_local; |
|
|
|
uint16_t endstop_change = live_state_local ^ old_live_state_local; |
|
|
|
|
|
|
|
if (endstop_change) { |
|
|
|
#if HAS_X_MIN |
|
|
|
if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", TEST(current_endstop_bits_local, X_MIN)); |
|
|
|
if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", TEST(live_state_local, X_MIN)); |
|
|
|
#endif |
|
|
|
#if HAS_X_MAX |
|
|
|
if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", TEST(current_endstop_bits_local, X_MAX)); |
|
|
|
if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", TEST(live_state_local, X_MAX)); |
|
|
|
#endif |
|
|
|
#if HAS_Y_MIN |
|
|
|
if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", TEST(current_endstop_bits_local, Y_MIN)); |
|
|
|
if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", TEST(live_state_local, Y_MIN)); |
|
|
|
#endif |
|
|
|
#if HAS_Y_MAX |
|
|
|
if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", TEST(current_endstop_bits_local, Y_MAX)); |
|
|
|
if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", TEST(live_state_local, Y_MAX)); |
|
|
|
#endif |
|
|
|
#if HAS_Z_MIN |
|
|
|
if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", TEST(current_endstop_bits_local, Z_MIN)); |
|
|
|
if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", TEST(live_state_local, Z_MIN)); |
|
|
|
#endif |
|
|
|
#if HAS_Z_MAX |
|
|
|
if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", TEST(current_endstop_bits_local, Z_MAX)); |
|
|
|
if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", TEST(live_state_local, Z_MAX)); |
|
|
|
#endif |
|
|
|
#if HAS_Z_MIN_PROBE_PIN |
|
|
|
if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", TEST(current_endstop_bits_local, Z_MIN_PROBE)); |
|
|
|
if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", TEST(live_state_local, Z_MIN_PROBE)); |
|
|
|
#endif |
|
|
|
#if HAS_X2_MIN |
|
|
|
if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR(" X2_MIN:", TEST(current_endstop_bits_local, X2_MIN)); |
|
|
|
if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR(" X2_MIN:", TEST(live_state_local, X2_MIN)); |
|
|
|
#endif |
|
|
|
#if HAS_X2_MAX |
|
|
|
if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR(" X2_MAX:", TEST(current_endstop_bits_local, X2_MAX)); |
|
|
|
if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR(" X2_MAX:", TEST(live_state_local, X2_MAX)); |
|
|
|
#endif |
|
|
|
#if HAS_Y2_MIN |
|
|
|
if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR(" Y2_MIN:", TEST(current_endstop_bits_local, Y2_MIN)); |
|
|
|
if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR(" Y2_MIN:", TEST(live_state_local, Y2_MIN)); |
|
|
|
#endif |
|
|
|
#if HAS_Y2_MAX |
|
|
|
if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR(" Y2_MAX:", TEST(current_endstop_bits_local, Y2_MAX)); |
|
|
|
if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR(" Y2_MAX:", TEST(live_state_local, Y2_MAX)); |
|
|
|
#endif |
|
|
|
#if HAS_Z2_MIN |
|
|
|
if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", TEST(current_endstop_bits_local, Z2_MIN)); |
|
|
|
if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", TEST(live_state_local, Z2_MIN)); |
|
|
|
#endif |
|
|
|
#if HAS_Z2_MAX |
|
|
|
if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", TEST(current_endstop_bits_local, Z2_MAX)); |
|
|
|
if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", TEST(live_state_local, Z2_MAX)); |
|
|
|
#endif |
|
|
|
SERIAL_PROTOCOLPGM("\n\n"); |
|
|
|
analogWrite(LED_PIN, local_LED_status); |
|
|
|
local_LED_status ^= 255; |
|
|
|
old_endstop_bits_local = current_endstop_bits_local; |
|
|
|
old_live_state_local = live_state_local; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|