2016-04-27 16:15:20 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2016-04-27 16:15:20 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2016-04-27 16:15:20 +02:00
|
|
|
*
|
|
|
|
* 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
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2016-04-27 16:15:20 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* endstops.cpp - A singleton object to manage endstops
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "endstops.h"
|
|
|
|
#include "stepper.h"
|
2017-09-06 13:28:32 +02:00
|
|
|
|
2020-01-03 02:01:38 +01:00
|
|
|
#include "../MarlinCore.h"
|
2017-09-06 13:28:32 +02:00
|
|
|
#include "../sd/cardreader.h"
|
2019-02-04 10:41:55 +01:00
|
|
|
#include "temperature.h"
|
2020-10-17 02:36:25 +02:00
|
|
|
#include "../lcd/marlinui.h"
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2018-05-16 09:08:43 +02:00
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
|
|
|
#include HAL_PATH(../HAL, endstop_interrupts.h)
|
|
|
|
#endif
|
|
|
|
|
2019-06-11 00:25:43 +02:00
|
|
|
#if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
|
2019-02-04 10:41:55 +01:00
|
|
|
#include "printcounter.h" // for print_job_timer
|
2018-10-19 04:20:56 +02:00
|
|
|
#endif
|
|
|
|
|
2019-05-08 04:25:54 +02:00
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
#include "../feature/bltouch.h"
|
|
|
|
#endif
|
|
|
|
|
2019-09-08 07:55:34 +02:00
|
|
|
#if ENABLED(JOYSTICK)
|
|
|
|
#include "../feature/joystick.h"
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
Endstops endstops;
|
|
|
|
|
2018-11-13 11:31:58 +01:00
|
|
|
// private:
|
2016-05-26 20:01:20 +02:00
|
|
|
|
2017-07-18 10:17:50 +02:00
|
|
|
bool Endstops::enabled, Endstops::enabled_globally; // Initialized by settings.load()
|
2018-05-21 22:51:38 +02:00
|
|
|
volatile uint8_t Endstops::hit_state;
|
2016-05-26 20:01:20 +02:00
|
|
|
|
2018-05-21 22:51:38 +02:00
|
|
|
Endstops::esbits_t Endstops::live_state = 0;
|
2018-06-22 03:14:16 +02:00
|
|
|
|
2018-09-25 03:59:12 +02:00
|
|
|
#if ENDSTOP_NOISE_THRESHOLD
|
2018-06-22 03:14:16 +02:00
|
|
|
Endstops::esbits_t Endstops::validated_live_state;
|
2018-05-21 22:51:38 +02:00
|
|
|
uint8_t Endstops::endstop_poll_count;
|
|
|
|
#endif
|
2016-05-26 20:01:20 +02:00
|
|
|
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
volatile bool Endstops::z_probe_enabled = false;
|
|
|
|
#endif
|
|
|
|
|
2018-03-10 12:56:04 +01:00
|
|
|
// Initialized by settings.load()
|
2017-10-29 09:43:44 +01:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
2018-06-19 18:55:49 +02:00
|
|
|
float Endstops::x2_endstop_adj;
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
2018-06-19 18:55:49 +02:00
|
|
|
float Endstops::y2_endstop_adj;
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if ENABLED(Z_MULTI_ENDSTOPS)
|
2018-06-19 18:55:49 +02:00
|
|
|
float Endstops::z2_endstop_adj;
|
2020-01-20 06:35:07 +01:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 3
|
|
|
|
float Endstops::z3_endstop_adj;
|
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
float Endstops::z4_endstop_adj;
|
|
|
|
#endif
|
|
|
|
#endif
|
2017-09-18 12:56:10 +02:00
|
|
|
#endif
|
|
|
|
|
2019-08-05 05:22:58 +02:00
|
|
|
#if ENABLED(SPI_ENDSTOPS)
|
|
|
|
Endstops::tmc_spi_homing_t Endstops::tmc_spi_homing; // = 0
|
|
|
|
#endif
|
|
|
|
#if ENABLED(IMPROVE_HOMING_RELIABILITY)
|
|
|
|
millis_t sg_guard_period; // = 0
|
|
|
|
#endif
|
|
|
|
|
2016-05-26 20:01:20 +02:00
|
|
|
/**
|
|
|
|
* Class and Instance Methods
|
|
|
|
*/
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
void Endstops::init() {
|
|
|
|
|
|
|
|
#if HAS_X_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMIN)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(X_MIN_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMIN)
|
|
|
|
SET_INPUT_PULLDOWN(X_MIN_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(X_MIN_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 09:43:44 +01:00
|
|
|
#if HAS_X2_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMIN)
|
|
|
|
SET_INPUT_PULLUP(X2_MIN_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMIN)
|
|
|
|
SET_INPUT_PULLDOWN(X2_MIN_PIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(X2_MIN_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
#if HAS_Y_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMIN)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Y_MIN_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Y_MIN_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y_MIN_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 09:43:44 +01:00
|
|
|
#if HAS_Y2_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMIN)
|
|
|
|
SET_INPUT_PULLUP(Y2_MIN_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Y2_MIN_PIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y2_MIN_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
#if HAS_Z_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Z_MIN_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Z_MIN_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MIN_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z2_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Z2_MIN_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Z2_MIN_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Z2_MIN_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
|
|
|
SET_INPUT_PULLUP(Z3_MIN_PIN);
|
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Z3_MIN_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z3_MIN_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-01-20 06:35:07 +01:00
|
|
|
#if HAS_Z4_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
|
|
|
SET_INPUT_PULLUP(Z4_MIN_PIN);
|
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Z4_MIN_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z4_MIN_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
#if HAS_X_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMAX)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(X_MAX_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMAX)
|
|
|
|
SET_INPUT_PULLDOWN(X_MAX_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(X_MAX_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 09:43:44 +01:00
|
|
|
#if HAS_X2_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMAX)
|
|
|
|
SET_INPUT_PULLUP(X2_MAX_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMAX)
|
|
|
|
SET_INPUT_PULLDOWN(X2_MAX_PIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(X2_MAX_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
#if HAS_Y_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMAX)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Y_MAX_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Y_MAX_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y_MAX_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 09:43:44 +01:00
|
|
|
#if HAS_Y2_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMAX)
|
|
|
|
SET_INPUT_PULLUP(Y2_MAX_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Y2_MAX_PIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y2_MAX_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
#if HAS_Z_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Z_MAX_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Z_MAX_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MAX_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_Z2_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Z2_MAX_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Z2_MAX_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Z2_MAX_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
|
|
|
SET_INPUT_PULLUP(Z3_MAX_PIN);
|
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Z3_MAX_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z3_MAX_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-01-20 06:35:07 +01:00
|
|
|
#if HAS_Z4_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
|
|
|
SET_INPUT_PULLUP(Z4_MAX_PIN);
|
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Z4_MAX_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(Z4_MAX_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-02-04 15:32:43 +01:00
|
|
|
#if PIN_EXISTS(CALIBRATION)
|
2019-02-07 00:20:17 +01:00
|
|
|
#if ENABLED(CALIBRATION_PIN_PULLUP)
|
|
|
|
SET_INPUT_PULLUP(CALIBRATION_PIN);
|
|
|
|
#elif ENABLED(CALIBRATION_PIN_PULLDOWN)
|
|
|
|
SET_INPUT_PULLDOWN(CALIBRATION_PIN);
|
|
|
|
#else
|
|
|
|
SET_INPUT(CALIBRATION_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-10-15 20:28:04 +02:00
|
|
|
#if HAS_CUSTOM_PROBE_PIN
|
2016-04-27 16:15:20 +02:00
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN_PROBE)
|
2017-03-08 06:43:33 +01:00
|
|
|
SET_INPUT_PULLUP(Z_MIN_PROBE_PIN);
|
2018-02-19 02:26:23 +01:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN_PROBE)
|
|
|
|
SET_INPUT_PULLDOWN(Z_MIN_PROBE_PIN);
|
2017-03-08 06:43:33 +01:00
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MIN_PROBE_PIN);
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(ENDSTOP_INTERRUPTS_FEATURE, setup_endstop_interrupts());
|
2018-05-16 09:08:43 +02:00
|
|
|
|
|
|
|
// Enable endstops
|
2020-04-22 23:35:03 +02:00
|
|
|
enable_globally(ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT));
|
2018-05-16 09:08:43 +02:00
|
|
|
|
2016-04-27 16:15:20 +02:00
|
|
|
} // Endstops::init
|
|
|
|
|
2018-07-12 00:33:26 +02:00
|
|
|
// Called at ~1KHz from Temperature ISR: Poll endstop state if required
|
2018-05-16 09:08:43 +02:00
|
|
|
void Endstops::poll() {
|
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(PINS_DEBUGGING, run_monitor()); // Report changes in endstop status
|
2018-05-16 09:08:43 +02:00
|
|
|
|
2018-09-24 22:56:01 +02:00
|
|
|
#if DISABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2018-06-22 03:14:16 +02:00
|
|
|
update();
|
2018-09-25 19:50:49 +02:00
|
|
|
#elif ENDSTOP_NOISE_THRESHOLD
|
2018-09-24 22:56:01 +02:00
|
|
|
if (endstop_poll_count) update();
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Endstops::enable_globally(const bool onoff) {
|
|
|
|
enabled_globally = enabled = onoff;
|
2018-11-13 11:31:58 +01:00
|
|
|
resync();
|
2018-05-16 09:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Enable / disable endstop checking
|
|
|
|
void Endstops::enable(const bool onoff) {
|
|
|
|
enabled = onoff;
|
2018-11-13 11:31:58 +01:00
|
|
|
resync();
|
2018-05-16 09:08:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
|
|
|
|
void Endstops::not_homing() {
|
|
|
|
enabled = enabled_globally;
|
|
|
|
}
|
|
|
|
|
2018-08-07 06:11:37 +02:00
|
|
|
#if ENABLED(VALIDATE_HOMING_ENDSTOPS)
|
|
|
|
// If the last move failed to trigger an endstop, call kill
|
|
|
|
void Endstops::validate_homing_move() {
|
|
|
|
if (trigger_state()) hit_on_purpose();
|
2020-04-13 21:53:21 +02:00
|
|
|
else kill(GET_TEXT(MSG_KILL_HOMING_FAILED));
|
2018-08-07 06:11:37 +02:00
|
|
|
}
|
|
|
|
#endif
|
2018-07-01 04:54:07 +02:00
|
|
|
|
2018-05-16 09:08:43 +02:00
|
|
|
// Enable / disable endstop z-probe checking
|
|
|
|
#if HAS_BED_PROBE
|
2018-06-13 08:22:02 +02:00
|
|
|
void Endstops::enable_z_probe(const bool onoff) {
|
2018-05-16 09:08:43 +02:00
|
|
|
z_probe_enabled = onoff;
|
2018-11-13 11:31:58 +01:00
|
|
|
resync();
|
2018-05-16 09:08:43 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-11-13 11:31:58 +01:00
|
|
|
// Get the stable endstop states when enabled
|
|
|
|
void Endstops::resync() {
|
|
|
|
if (!abort_enabled()) return; // If endstops/probes are disabled the loop below can hang
|
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
// Wait for Temperature ISR to run at least once (runs at 1KHz)
|
|
|
|
TERN(ENDSTOP_INTERRUPTS_FEATURE, update(), safe_delay(2));
|
|
|
|
while (TERN0(ENDSTOP_NOISE_THRESHOLD, endstop_poll_count)) safe_delay(1);
|
2018-11-13 11:31:58 +01:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:08:43 +02:00
|
|
|
#if ENABLED(PINS_DEBUGGING)
|
|
|
|
void Endstops::run_monitor() {
|
|
|
|
if (!monitor_flag) return;
|
|
|
|
static uint8_t monitor_count = 16; // offset this check from the others
|
|
|
|
monitor_count += _BV(1); // 15 Hz
|
|
|
|
monitor_count &= 0x7F;
|
|
|
|
if (!monitor_count) monitor(); // report changes in endstop status
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-07-12 00:33:26 +02:00
|
|
|
void Endstops::event_handler() {
|
|
|
|
static uint8_t prev_hit_state; // = 0
|
2019-10-29 21:58:00 +01:00
|
|
|
if (hit_state == prev_hit_state) return;
|
|
|
|
prev_hit_state = hit_state;
|
|
|
|
if (hit_state) {
|
2020-09-28 08:13:27 +02:00
|
|
|
#if HAS_WIRED_LCD
|
2016-04-27 16:15:20 +02:00
|
|
|
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{ \
|
2018-05-09 07:17:53 +02:00
|
|
|
SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", planner.triggered_position_mm(_AXIS(A))); \
|
2016-04-27 16:15:20 +02:00
|
|
|
_SET_STOP_CHAR(A,C); }while(0)
|
|
|
|
|
|
|
|
#define _ENDSTOP_HIT_TEST(A,C) \
|
2018-05-21 22:51:38 +02:00
|
|
|
if (TEST(hit_state, A ##_MIN) || TEST(hit_state, A ##_MAX)) \
|
2016-04-27 16:15:20 +02:00
|
|
|
_ENDSTOP_HIT_ECHO(A,C)
|
|
|
|
|
2017-05-02 21:29:18 +02: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 17:51:23 +02:00
|
|
|
SERIAL_ECHO_START();
|
2020-02-26 10:02:03 +01:00
|
|
|
SERIAL_ECHOPGM(STR_ENDSTOPS_HIT);
|
2017-05-02 21:29:18 +02:00
|
|
|
ENDSTOP_HIT_TEST_X();
|
|
|
|
ENDSTOP_HIT_TEST_Y();
|
|
|
|
ENDSTOP_HIT_TEST_Z();
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2019-10-15 20:28:04 +02:00
|
|
|
#if HAS_CUSTOM_PROBE_PIN
|
2016-04-27 16:15:20 +02:00
|
|
|
#define P_AXIS Z_AXIS
|
2018-05-21 22:51:38 +02:00
|
|
|
if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_EOL();
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2020-09-28 08:13:27 +02:00
|
|
|
TERN_(HAS_WIRED_LCD, ui.status_printf_P(0, PSTR(S_FMT " %c %c %c %c"), GET_TEXT(MSG_LCD_ENDSTOPS), chrX, chrY, chrZ, chrP));
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2019-06-11 00:25:43 +02:00
|
|
|
#if BOTH(SD_ABORT_ON_ENDSTOP_HIT, SDSUPPORT)
|
2018-05-09 07:17:53 +02:00
|
|
|
if (planner.abort_on_endstop_hit) {
|
2020-02-26 05:18:14 +01:00
|
|
|
card.endFilePrint();
|
2016-07-06 21:00:28 +02:00
|
|
|
quickstop_stepper();
|
2018-10-19 04:20:56 +02:00
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
print_job_timer.stop();
|
2016-04-27 16:15:20 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2018-11-04 13:07:17 +01:00
|
|
|
}
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2019-05-09 18:45:55 +02:00
|
|
|
static void print_es_state(const bool is_hit, PGM_P const label=nullptr) {
|
2018-09-17 10:27:13 +02:00
|
|
|
if (label) serialprintPGM(label);
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOPGM(": ");
|
2020-02-26 10:02:03 +01:00
|
|
|
serialprintPGM(is_hit ? PSTR(STR_ENDSTOP_HIT) : PSTR(STR_ENDSTOP_OPEN));
|
2018-09-17 10:27:13 +02:00
|
|
|
SERIAL_EOL();
|
|
|
|
}
|
|
|
|
|
2019-10-30 21:07:24 +01:00
|
|
|
void _O2 Endstops::report_states() {
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(BLTOUCH, bltouch._set_SW_mode());
|
2020-02-26 10:02:03 +01:00
|
|
|
SERIAL_ECHOLNPGM(STR_M119_REPORT);
|
2020-02-26 11:11:03 +01:00
|
|
|
#define ES_REPORT(S) print_es_state(READ(S##_PIN) != S##_ENDSTOP_INVERTING, PSTR(STR_##S))
|
2016-04-27 23:46:24 +02:00
|
|
|
#if HAS_X_MIN
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(X_MIN);
|
|
|
|
#endif
|
|
|
|
#if HAS_X2_MIN
|
|
|
|
ES_REPORT(X2_MIN);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(X_MAX);
|
|
|
|
#endif
|
|
|
|
#if HAS_X2_MAX
|
|
|
|
ES_REPORT(X2_MAX);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(Y_MIN);
|
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MIN
|
|
|
|
ES_REPORT(Y2_MIN);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(Y_MAX);
|
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MAX
|
|
|
|
ES_REPORT(Y2_MAX);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(Z_MIN);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
2016-10-29 08:54:02 +02:00
|
|
|
#if HAS_Z2_MIN
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(Z2_MIN);
|
2016-10-29 08:54:02 +02:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MIN
|
|
|
|
ES_REPORT(Z3_MIN);
|
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if HAS_Z4_MIN
|
|
|
|
ES_REPORT(Z4_MIN);
|
|
|
|
#endif
|
2016-04-27 23:46:24 +02:00
|
|
|
#if HAS_Z_MAX
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(Z_MAX);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
2017-10-29 09:43:44 +01:00
|
|
|
ES_REPORT(Z2_MAX);
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MAX
|
|
|
|
ES_REPORT(Z3_MAX);
|
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if HAS_Z4_MAX
|
|
|
|
ES_REPORT(Z4_MAX);
|
|
|
|
#endif
|
2019-10-15 20:28:04 +02:00
|
|
|
#if HAS_CUSTOM_PROBE_PIN
|
2020-02-26 10:02:03 +01:00
|
|
|
print_es_state(READ(Z_MIN_PROBE_PIN) != Z_MIN_PROBE_ENDSTOP_INVERTING, PSTR(STR_Z_PROBE));
|
2016-04-27 23:46:24 +02:00
|
|
|
#endif
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2018-09-29 02:00:11 +02:00
|
|
|
#if NUM_RUNOUT_SENSORS == 1
|
2020-07-06 00:42:19 +02:00
|
|
|
print_es_state(READ(FIL_RUNOUT_PIN) != FIL_RUNOUT_STATE, PSTR(STR_FILAMENT_RUNOUT_SENSOR));
|
2018-09-17 10:27:13 +02:00
|
|
|
#else
|
2020-02-02 04:00:53 +01:00
|
|
|
#define _CASE_RUNOUT(N) case N: pin = FIL_RUNOUT##N##_PIN; break;
|
2020-03-14 05:18:16 +01:00
|
|
|
LOOP_S_LE_N(i, 1, NUM_RUNOUT_SENSORS) {
|
2018-09-17 10:27:13 +02:00
|
|
|
pin_t pin;
|
|
|
|
switch (i) {
|
|
|
|
default: continue;
|
2020-02-02 04:00:53 +01:00
|
|
|
REPEAT_S(1, INCREMENT(NUM_RUNOUT_SENSORS), _CASE_RUNOUT)
|
2018-09-17 10:27:13 +02:00
|
|
|
}
|
2020-02-26 10:02:03 +01:00
|
|
|
SERIAL_ECHOPGM(STR_FILAMENT_RUNOUT_SENSOR);
|
2020-01-09 01:31:57 +01:00
|
|
|
if (i > 1) SERIAL_CHAR(' ', '0' + i);
|
2020-07-06 00:42:19 +02:00
|
|
|
print_es_state(extDigitalRead(pin) != FIL_RUNOUT_STATE);
|
2018-09-17 10:27:13 +02:00
|
|
|
}
|
2020-02-02 04:00:53 +01:00
|
|
|
#undef _CASE_RUNOUT
|
2018-09-17 10:27:13 +02:00
|
|
|
#endif
|
2017-01-22 00:10:57 +01:00
|
|
|
#endif
|
2019-09-08 07:55:34 +02:00
|
|
|
|
2020-04-22 23:35:03 +02:00
|
|
|
TERN_(BLTOUCH, bltouch._reset_SW_mode());
|
|
|
|
TERN_(JOYSTICK_DEBUG, joystick.report());
|
2019-09-08 07:55:34 +02:00
|
|
|
|
2019-10-30 21:07:24 +01:00
|
|
|
} // Endstops::report_states
|
2016-04-27 23:46:24 +02:00
|
|
|
|
2018-05-16 09:08:43 +02:00
|
|
|
// The following routines are called from an ISR context. It could be the temperature ISR, the
|
|
|
|
// endstop ISR or the Stepper ISR.
|
|
|
|
|
2018-05-21 22:51:38 +02:00
|
|
|
#define _ENDSTOP(AXIS, MINMAX) AXIS ##_## MINMAX
|
|
|
|
#define _ENDSTOP_PIN(AXIS, MINMAX) AXIS ##_## MINMAX ##_PIN
|
|
|
|
#define _ENDSTOP_INVERTING(AXIS, MINMAX) AXIS ##_## MINMAX ##_ENDSTOP_INVERTING
|
2016-04-28 11:15:53 +02:00
|
|
|
|
2018-07-12 00:33:26 +02:00
|
|
|
// Check endstops - Could be called from Temperature ISR!
|
2016-04-27 16:15:20 +02:00
|
|
|
void Endstops::update() {
|
|
|
|
|
2018-09-25 03:59:12 +02:00
|
|
|
#if !ENDSTOP_NOISE_THRESHOLD
|
2018-06-22 03:14:16 +02:00
|
|
|
if (!abort_enabled()) return;
|
|
|
|
#endif
|
|
|
|
|
2018-05-24 07:04:47 +02:00
|
|
|
#define UPDATE_ENDSTOP_BIT(AXIS, MINMAX) SET_BIT_TO(live_state, _ENDSTOP(AXIS, MINMAX), (READ(_ENDSTOP_PIN(AXIS, MINMAX)) != _ENDSTOP_INVERTING(AXIS, MINMAX)))
|
2018-06-22 03:14:16 +02:00
|
|
|
#define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2020-09-04 03:12:53 +02:00
|
|
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY)
|
2017-04-14 02:32:37 +02:00
|
|
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
2018-05-22 08:56:03 +02:00
|
|
|
if (G38_move) UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
2016-09-26 08:30:34 +02:00
|
|
|
#endif
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2018-05-23 10:45:25 +02:00
|
|
|
// With Dual X, endstops are only checked in the homing direction for the active extruder
|
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
2020-09-21 01:29:08 +02:00
|
|
|
#define E0_ACTIVE stepper.last_moved_extruder == 0
|
2020-02-06 22:28:46 +01:00
|
|
|
#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))
|
2018-05-23 10:45:25 +02:00
|
|
|
#else
|
2020-02-06 22:28:46 +01:00
|
|
|
#define X_MIN_TEST() true
|
|
|
|
#define X_MAX_TEST() true
|
2017-04-15 11:23:20 +02:00
|
|
|
#endif
|
2017-04-14 02:32:37 +02:00
|
|
|
|
2018-05-23 10:45:25 +02:00
|
|
|
// Use HEAD for core axes, AXIS for others
|
2020-09-04 03:12:53 +02:00
|
|
|
#if ANY(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY)
|
2017-04-15 11:23:20 +02:00
|
|
|
#define X_AXIS_HEAD X_HEAD
|
|
|
|
#else
|
|
|
|
#define X_AXIS_HEAD X_AXIS
|
2017-02-22 04:42:52 +01:00
|
|
|
#endif
|
2020-09-04 03:12:53 +02:00
|
|
|
#if ANY(CORE_IS_XY, CORE_IS_YZ, MARKFORGED_XY)
|
2017-04-15 11:23:20 +02:00
|
|
|
#define Y_AXIS_HEAD Y_HEAD
|
2016-04-27 16:15:20 +02:00
|
|
|
#else
|
2017-04-15 11:23:20 +02:00
|
|
|
#define Y_AXIS_HEAD Y_AXIS
|
2017-04-14 02:32:37 +02:00
|
|
|
#endif
|
2016-11-06 05:47:38 +01:00
|
|
|
#if CORE_IS_XZ || CORE_IS_YZ
|
2017-04-15 11:23:20 +02:00
|
|
|
#define Z_AXIS_HEAD Z_HEAD
|
2016-04-27 16:15:20 +02:00
|
|
|
#else
|
2017-04-15 11:23:20 +02:00
|
|
|
#define Z_AXIS_HEAD Z_AXIS
|
2016-04-27 16:15:20 +02:00
|
|
|
#endif
|
|
|
|
|
2017-04-15 11:23:20 +02:00
|
|
|
/**
|
2018-06-27 10:18:57 +02:00
|
|
|
* Check and update endstops
|
2017-04-15 11:23:20 +02:00
|
|
|
*/
|
2019-10-15 18:34:45 +02:00
|
|
|
#if HAS_X_MIN && !X_SPI_SENSORLESS
|
2019-10-15 20:28:04 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(X, MIN);
|
2018-07-01 00:27:37 +02:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
2018-06-27 10:18:57 +02:00
|
|
|
#if HAS_X2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(X2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(X_MIN, X2_MIN);
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
2018-06-27 10:18:57 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
#if HAS_X_MAX && !X_SPI_SENSORLESS
|
2019-10-15 20:28:04 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(X, MAX);
|
2018-07-01 00:27:37 +02:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
2018-06-27 10:18:57 +02:00
|
|
|
#if HAS_X2_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(X2, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(X_MAX, X2_MAX);
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
2018-06-27 10:18:57 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
#if HAS_Y_MIN && !Y_SPI_SENSORLESS
|
2019-10-15 20:28:04 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(Y, MIN);
|
2018-06-27 10:18:57 +02:00
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
#if HAS_Y2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Y2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Y_MIN, Y2_MIN);
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
2018-06-27 10:18:57 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2016-04-27 16:15:20 +02:00
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
#if HAS_Y_MAX && !Y_SPI_SENSORLESS
|
2019-10-15 20:28:04 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(Y, MAX);
|
2018-06-27 10:18:57 +02:00
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
#if HAS_Y2_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(Y2, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Y_MAX, Y2_MAX);
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
2018-06-27 10:18:57 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2018-05-16 09:08:43 +02:00
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
#if HAS_Z_MIN && !Z_SPI_SENSORLESS
|
2019-10-15 20:28:04 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN);
|
2020-01-20 06:35:07 +01:00
|
|
|
#if ENABLED(Z_MULTI_ENDSTOPS)
|
2018-06-27 10:18:57 +02:00
|
|
|
#if HAS_Z2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MIN, Z2_MIN);
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 3
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Z3, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MIN, Z3_MIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
#if HAS_Z4_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Z4, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MIN, Z4_MIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-06-27 10:18:57 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// When closing the gap check the enabled probe
|
2019-10-15 20:28:04 +02:00
|
|
|
#if HAS_CUSTOM_PROBE_PIN
|
2018-06-27 10:18:57 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
|
|
|
#endif
|
|
|
|
|
2019-10-15 18:34:45 +02:00
|
|
|
#if HAS_Z_MAX && !Z_SPI_SENSORLESS
|
2018-06-27 10:18:57 +02:00
|
|
|
// Check both Z dual endstops
|
2020-01-20 06:35:07 +01:00
|
|
|
#if ENABLED(Z_MULTI_ENDSTOPS)
|
2018-06-27 10:18:57 +02:00
|
|
|
UPDATE_ENDSTOP_BIT(Z, MAX);
|
|
|
|
#if HAS_Z2_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MAX, Z2_MAX);
|
2018-05-21 22:51:38 +02:00
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 3
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(Z3, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MAX, Z3_MAX);
|
|
|
|
#endif
|
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if NUM_Z_STEPPER_DRIVERS >= 4
|
|
|
|
#if HAS_Z4_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(Z4, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MAX, Z4_MAX);
|
|
|
|
#endif
|
|
|
|
#endif
|
2019-10-15 20:28:04 +02:00
|
|
|
#elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
2018-06-27 10:18:57 +02:00
|
|
|
// If this pin isn't the bed probe it's the Z endstop
|
|
|
|
UPDATE_ENDSTOP_BIT(Z, MAX);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
|
2018-09-25 03:59:12 +02:00
|
|
|
#if ENDSTOP_NOISE_THRESHOLD
|
|
|
|
|
2018-06-22 03:14:16 +02:00
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
static esbits_t old_live_state;
|
|
|
|
if (old_live_state != live_state) {
|
2018-09-25 03:59:12 +02:00
|
|
|
endstop_poll_count = ENDSTOP_NOISE_THRESHOLD;
|
2018-05-21 22:51:38 +02:00
|
|
|
old_live_state = live_state;
|
|
|
|
}
|
|
|
|
else if (endstop_poll_count && !--endstop_poll_count)
|
|
|
|
validated_live_state = live_state;
|
|
|
|
|
2018-06-22 03:14:16 +02:00
|
|
|
if (!abort_enabled()) return;
|
2018-05-21 22:51:38 +02:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Test the current status of an endstop
|
2018-06-22 03:14:16 +02:00
|
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(state(), ENDSTOP))
|
2018-05-21 22:51:38 +02:00
|
|
|
|
|
|
|
// Record endstop was hit
|
|
|
|
#define _ENDSTOP_HIT(AXIS, MINMAX) SBI(hit_state, _ENDSTOP(AXIS, MINMAX))
|
|
|
|
|
|
|
|
// Call the endstop triggered routine for single endstops
|
2020-02-06 22:28:46 +01:00
|
|
|
#define PROCESS_ENDSTOP(AXIS, MINMAX) do { \
|
2018-06-02 02:02:22 +02:00
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
|
|
|
|
_ENDSTOP_HIT(AXIS, MINMAX); \
|
|
|
|
planner.endstop_triggered(_AXIS(AXIS)); \
|
|
|
|
} \
|
|
|
|
}while(0)
|
2018-05-21 22:51:38 +02:00
|
|
|
|
2020-05-16 08:06:18 +02:00
|
|
|
// Core Sensorless Homing needs to test an Extra Pin
|
|
|
|
#define CORE_DIAG(QQ,A,MM) (CORE_IS_##QQ && A##_SENSORLESS && !A##_SPI_SENSORLESS && HAS_##A##_##MM)
|
|
|
|
#define PROCESS_CORE_ENDSTOP(A1,M1,A2,M2) do { \
|
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(A1,M1))) { \
|
|
|
|
_ENDSTOP_HIT(A2,M2); \
|
|
|
|
planner.endstop_triggered(_AXIS(A2)); \
|
|
|
|
} \
|
|
|
|
}while(0)
|
|
|
|
|
2018-06-02 02:02:22 +02:00
|
|
|
// Call the endstop triggered routine for dual endstops
|
2020-02-06 22:28:46 +01:00
|
|
|
#define PROCESS_DUAL_ENDSTOP(A, MINMAX) do { \
|
|
|
|
const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1); \
|
2018-06-02 02:02:22 +02:00
|
|
|
if (dual_hit) { \
|
2020-02-06 22:28:46 +01:00
|
|
|
_ENDSTOP_HIT(A, MINMAX); \
|
2018-06-02 02:02:22 +02:00
|
|
|
/* if not performing home or if both endstops were trigged during homing... */ \
|
2018-06-19 18:55:49 +02:00
|
|
|
if (!stepper.separate_multi_axis || dual_hit == 0b11) \
|
2020-02-06 22:28:46 +01:00
|
|
|
planner.endstop_triggered(_AXIS(A)); \
|
2018-06-19 18:55:49 +02:00
|
|
|
} \
|
|
|
|
}while(0)
|
|
|
|
|
2020-02-06 22:28:46 +01:00
|
|
|
#define PROCESS_TRIPLE_ENDSTOP(A, MINMAX) do { \
|
|
|
|
const byte triple_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2); \
|
2018-06-19 18:55:49 +02:00
|
|
|
if (triple_hit) { \
|
2020-02-06 22:28:46 +01:00
|
|
|
_ENDSTOP_HIT(A, MINMAX); \
|
2018-06-19 18:55:49 +02:00
|
|
|
/* if not performing home or if both endstops were trigged during homing... */ \
|
2018-09-24 22:56:01 +02:00
|
|
|
if (!stepper.separate_multi_axis || triple_hit == 0b111) \
|
2020-02-06 22:28:46 +01:00
|
|
|
planner.endstop_triggered(_AXIS(A)); \
|
2018-06-02 02:02:22 +02:00
|
|
|
} \
|
|
|
|
}while(0)
|
2018-05-21 22:51:38 +02:00
|
|
|
|
2020-02-06 22:28:46 +01:00
|
|
|
#define PROCESS_QUAD_ENDSTOP(A, MINMAX) do { \
|
|
|
|
const byte quad_hit = TEST_ENDSTOP(_ENDSTOP(A, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(A##2, MINMAX)) << 1) | (TEST_ENDSTOP(_ENDSTOP(A##3, MINMAX)) << 2) | (TEST_ENDSTOP(_ENDSTOP(A##4, MINMAX)) << 3); \
|
2020-01-20 06:35:07 +01:00
|
|
|
if (quad_hit) { \
|
2020-02-06 22:28:46 +01:00
|
|
|
_ENDSTOP_HIT(A, MINMAX); \
|
2020-01-20 06:35:07 +01:00
|
|
|
/* if not performing home or if both endstops were trigged during homing... */ \
|
|
|
|
if (!stepper.separate_multi_axis || quad_hit == 0b1111) \
|
2020-02-06 22:28:46 +01:00
|
|
|
planner.endstop_triggered(_AXIS(A)); \
|
2020-01-20 06:35:07 +01:00
|
|
|
} \
|
|
|
|
}while(0)
|
|
|
|
|
2020-02-06 22:28:46 +01:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
|
|
|
#define PROCESS_ENDSTOP_X(MINMAX) PROCESS_DUAL_ENDSTOP(X, MINMAX)
|
|
|
|
#else
|
|
|
|
#define PROCESS_ENDSTOP_X(MINMAX) if (X_##MINMAX##_TEST()) PROCESS_ENDSTOP(X, MINMAX)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
#define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_DUAL_ENDSTOP(Y, MINMAX)
|
|
|
|
#else
|
|
|
|
#define PROCESS_ENDSTOP_Y(MINMAX) PROCESS_ENDSTOP(Y, MINMAX)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if DISABLED(Z_MULTI_ENDSTOPS)
|
|
|
|
#define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_ENDSTOP(Z, MINMAX)
|
|
|
|
#elif NUM_Z_STEPPER_DRIVERS == 4
|
|
|
|
#define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_QUAD_ENDSTOP(Z, MINMAX)
|
|
|
|
#elif NUM_Z_STEPPER_DRIVERS == 3
|
|
|
|
#define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_TRIPLE_ENDSTOP(Z, MINMAX)
|
|
|
|
#else
|
|
|
|
#define PROCESS_ENDSTOP_Z(MINMAX) PROCESS_DUAL_ENDSTOP(Z, MINMAX)
|
|
|
|
#endif
|
|
|
|
|
2020-09-04 03:12:53 +02:00
|
|
|
#if ENABLED(G38_PROBE_TARGET) && PIN_EXISTS(Z_MIN_PROBE) && NONE(CORE_IS_XY, CORE_IS_XZ, MARKFORGED_XY)
|
2019-03-10 23:22:09 +01:00
|
|
|
#if ENABLED(G38_PROBE_AWAY)
|
|
|
|
#define _G38_OPEN_STATE (G38_move >= 4)
|
|
|
|
#else
|
|
|
|
#define _G38_OPEN_STATE LOW
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
// If G38 command is active check Z_MIN_PROBE for ALL movement
|
2019-03-10 23:22:09 +01:00
|
|
|
if (G38_move && TEST_ENDSTOP(_ENDSTOP(Z, MIN_PROBE)) != _G38_OPEN_STATE) {
|
|
|
|
if (stepper.axis_is_moving(X_AXIS)) { _ENDSTOP_HIT(X, MIN); planner.endstop_triggered(X_AXIS); }
|
|
|
|
else if (stepper.axis_is_moving(Y_AXIS)) { _ENDSTOP_HIT(Y, MIN); planner.endstop_triggered(Y_AXIS); }
|
|
|
|
else if (stepper.axis_is_moving(Z_AXIS)) { _ENDSTOP_HIT(Z, MIN); planner.endstop_triggered(Z_AXIS); }
|
|
|
|
G38_did_trigger = true;
|
2018-05-21 22:51:38 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-14 20:00:47 +02:00
|
|
|
// Signal, after validation, if an endstop limit is pressed or not
|
|
|
|
|
2018-05-23 10:45:25 +02:00
|
|
|
if (stepper.axis_is_moving(X_AXIS)) {
|
2018-05-21 22:51:38 +02:00
|
|
|
if (stepper.motor_direction(X_AXIS_HEAD)) { // -direction
|
2019-08-05 05:22:58 +02:00
|
|
|
#if HAS_X_MIN || (X_SPI_SENSORLESS && X_HOME_DIR < 0)
|
2020-02-06 22:28:46 +01:00
|
|
|
PROCESS_ENDSTOP_X(MIN);
|
2020-05-16 08:06:18 +02:00
|
|
|
#if CORE_DIAG(XY, Y, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MIN,X,MIN);
|
|
|
|
#elif CORE_DIAG(XY, Y, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MAX,X,MIN);
|
|
|
|
#elif CORE_DIAG(XZ, Z, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MIN,X,MIN);
|
|
|
|
#elif CORE_DIAG(XZ, Z, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MAX,X,MIN);
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else { // +direction
|
2019-08-05 05:22:58 +02:00
|
|
|
#if HAS_X_MAX || (X_SPI_SENSORLESS && X_HOME_DIR > 0)
|
2020-02-06 22:28:46 +01:00
|
|
|
PROCESS_ENDSTOP_X(MAX);
|
2020-05-16 08:06:18 +02:00
|
|
|
#if CORE_DIAG(XY, Y, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MIN,X,MAX);
|
|
|
|
#elif CORE_DIAG(XY, Y, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MAX,X,MAX);
|
|
|
|
#elif CORE_DIAG(XZ, Z, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MIN,X,MAX);
|
|
|
|
#elif CORE_DIAG(XZ, Z, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MAX,X,MAX);
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 10:45:25 +02:00
|
|
|
if (stepper.axis_is_moving(Y_AXIS)) {
|
2018-05-21 22:51:38 +02:00
|
|
|
if (stepper.motor_direction(Y_AXIS_HEAD)) { // -direction
|
2019-08-05 05:22:58 +02:00
|
|
|
#if HAS_Y_MIN || (Y_SPI_SENSORLESS && Y_HOME_DIR < 0)
|
2020-02-06 22:28:46 +01:00
|
|
|
PROCESS_ENDSTOP_Y(MIN);
|
2020-05-16 08:06:18 +02:00
|
|
|
#if CORE_DIAG(XY, X, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MIN,Y,MIN);
|
|
|
|
#elif CORE_DIAG(XY, X, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MAX,Y,MIN);
|
|
|
|
#elif CORE_DIAG(YZ, Z, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MIN,Y,MIN);
|
|
|
|
#elif CORE_DIAG(YZ, Z, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MAX,Y,MIN);
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else { // +direction
|
2019-08-05 05:22:58 +02:00
|
|
|
#if HAS_Y_MAX || (Y_SPI_SENSORLESS && Y_HOME_DIR > 0)
|
2020-02-06 22:28:46 +01:00
|
|
|
PROCESS_ENDSTOP_Y(MAX);
|
2020-05-16 08:06:18 +02:00
|
|
|
#if CORE_DIAG(XY, X, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MIN,Y,MAX);
|
|
|
|
#elif CORE_DIAG(XY, X, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MAX,Y,MAX);
|
|
|
|
#elif CORE_DIAG(YZ, Z, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MIN,Y,MAX);
|
|
|
|
#elif CORE_DIAG(YZ, Z, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Z,MAX,Y,MAX);
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 10:45:25 +02:00
|
|
|
if (stepper.axis_is_moving(Z_AXIS)) {
|
2018-05-21 22:51:38 +02:00
|
|
|
if (stepper.motor_direction(Z_AXIS_HEAD)) { // Z -direction. Gantry down, bed up.
|
2020-02-06 22:28:46 +01:00
|
|
|
|
2019-08-05 05:22:58 +02:00
|
|
|
#if HAS_Z_MIN || (Z_SPI_SENSORLESS && Z_HOME_DIR < 0)
|
2020-04-22 23:35:03 +02:00
|
|
|
if ( TERN1(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, z_probe_enabled)
|
|
|
|
&& TERN1(HAS_CUSTOM_PROBE_PIN, !z_probe_enabled)
|
2020-02-06 22:28:46 +01:00
|
|
|
) PROCESS_ENDSTOP_Z(MIN);
|
2020-05-16 08:06:18 +02:00
|
|
|
#if CORE_DIAG(XZ, X, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MIN,Z,MIN);
|
|
|
|
#elif CORE_DIAG(XZ, X, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MAX,Z,MIN);
|
|
|
|
#elif CORE_DIAG(YZ, Y, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MIN,Z,MIN);
|
|
|
|
#elif CORE_DIAG(YZ, Y, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MAX,Z,MIN);
|
|
|
|
#endif
|
2018-05-21 22:51:38 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// When closing the gap check the enabled probe
|
2019-10-15 20:28:04 +02:00
|
|
|
#if HAS_CUSTOM_PROBE_PIN
|
2018-05-21 22:51:38 +02:00
|
|
|
if (z_probe_enabled) PROCESS_ENDSTOP(Z, MIN_PROBE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else { // Z +direction. Gantry up, bed down.
|
2019-08-05 05:22:58 +02:00
|
|
|
#if HAS_Z_MAX || (Z_SPI_SENSORLESS && Z_HOME_DIR > 0)
|
2020-01-20 06:35:07 +01:00
|
|
|
#if ENABLED(Z_MULTI_ENDSTOPS)
|
2020-02-06 22:28:46 +01:00
|
|
|
PROCESS_ENDSTOP_Z(MAX);
|
|
|
|
#elif !HAS_CUSTOM_PROBE_PIN || Z_MAX_PIN != Z_MIN_PROBE_PIN // No probe or probe is Z_MIN || Probe is not Z_MAX
|
2018-05-21 22:51:38 +02:00
|
|
|
PROCESS_ENDSTOP(Z, MAX);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
2020-05-16 08:06:18 +02:00
|
|
|
#if CORE_DIAG(XZ, X, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MIN,Z,MAX);
|
|
|
|
#elif CORE_DIAG(XZ, X, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(X,MAX,Z,MAX);
|
|
|
|
#elif CORE_DIAG(YZ, Y, MIN)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MIN,Z,MAX);
|
|
|
|
#elif CORE_DIAG(YZ, Y, MAX)
|
|
|
|
PROCESS_CORE_ENDSTOP(Y,MAX,Z,MAX);
|
|
|
|
#endif
|
2018-05-16 09:08:43 +02:00
|
|
|
#endif
|
2016-04-27 16:15:20 +02:00
|
|
|
}
|
2018-05-16 09:08:43 +02:00
|
|
|
}
|
2016-04-27 16:15:20 +02:00
|
|
|
} // Endstops::update()
|
2017-09-18 12:55:09 +02:00
|
|
|
|
2019-08-05 05:22:58 +02:00
|
|
|
#if ENABLED(SPI_ENDSTOPS)
|
|
|
|
|
|
|
|
bool Endstops::tmc_spi_homing_check() {
|
|
|
|
bool hit = false;
|
|
|
|
#if X_SPI_SENSORLESS
|
2020-05-14 20:00:47 +02:00
|
|
|
if (tmc_spi_homing.x && (stepperX.test_stall_status()
|
2020-09-04 03:12:53 +02:00
|
|
|
#if ANY(CORE_IS_XY, MARKFORGED_XY) && Y_SPI_SENSORLESS
|
2020-05-14 20:00:47 +02:00
|
|
|
|| stepperY.test_stall_status()
|
|
|
|
#elif CORE_IS_XZ && Z_SPI_SENSORLESS
|
|
|
|
|| stepperZ.test_stall_status()
|
|
|
|
#endif
|
|
|
|
)) {
|
2020-07-12 20:16:56 +02:00
|
|
|
SBI(live_state, X_ENDSTOP);
|
2019-08-05 05:22:58 +02:00
|
|
|
hit = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if Y_SPI_SENSORLESS
|
2020-05-14 20:00:47 +02:00
|
|
|
if (tmc_spi_homing.y && (stepperY.test_stall_status()
|
2020-09-04 03:12:53 +02:00
|
|
|
#if ANY(CORE_IS_XY, MARKFORGED_XY) && X_SPI_SENSORLESS
|
2020-05-14 20:00:47 +02:00
|
|
|
|| stepperX.test_stall_status()
|
|
|
|
#elif CORE_IS_YZ && Z_SPI_SENSORLESS
|
|
|
|
|| stepperZ.test_stall_status()
|
|
|
|
#endif
|
|
|
|
)) {
|
2020-07-12 20:16:56 +02:00
|
|
|
SBI(live_state, Y_ENDSTOP);
|
2019-08-05 05:22:58 +02:00
|
|
|
hit = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if Z_SPI_SENSORLESS
|
2020-05-14 20:00:47 +02:00
|
|
|
if (tmc_spi_homing.z && (stepperZ.test_stall_status()
|
|
|
|
#if CORE_IS_XZ && X_SPI_SENSORLESS
|
|
|
|
|| stepperX.test_stall_status()
|
|
|
|
#elif CORE_IS_YZ && Y_SPI_SENSORLESS
|
|
|
|
|| stepperY.test_stall_status()
|
|
|
|
#endif
|
|
|
|
)) {
|
2020-07-12 20:16:56 +02:00
|
|
|
SBI(live_state, Z_ENDSTOP);
|
2019-08-05 05:22:58 +02:00
|
|
|
hit = true;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return hit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Endstops::clear_endstop_state() {
|
2020-07-12 20:16:56 +02:00
|
|
|
TERN_(X_SPI_SENSORLESS, CBI(live_state, X_ENDSTOP));
|
|
|
|
TERN_(Y_SPI_SENSORLESS, CBI(live_state, Y_ENDSTOP));
|
|
|
|
TERN_(Z_SPI_SENSORLESS, CBI(live_state, Z_ENDSTOP));
|
2019-08-05 05:22:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // SPI_ENDSTOPS
|
|
|
|
|
2017-09-18 12:55:09 +02:00
|
|
|
#if ENABLED(PINS_DEBUGGING)
|
|
|
|
|
|
|
|
bool Endstops::monitor_flag = false;
|
|
|
|
|
|
|
|
/**
|
2019-07-24 08:52:36 +02:00
|
|
|
* Monitor Endstops and Z Probe for changes
|
2017-09-18 12:55:09 +02:00
|
|
|
*
|
|
|
|
* If a change is detected then the LED is toggled and
|
2019-07-24 08:52:36 +02:00
|
|
|
* a message is sent out the serial port.
|
2017-09-18 12:55:09 +02:00
|
|
|
*
|
|
|
|
* Yes, we could miss a rapid back & forth change but
|
|
|
|
* that won't matter because this is all manual.
|
|
|
|
*/
|
|
|
|
void Endstops::monitor() {
|
|
|
|
|
2018-05-21 22:51:38 +02:00
|
|
|
static uint16_t old_live_state_local = 0;
|
2017-09-18 12:55:09 +02:00
|
|
|
static uint8_t local_LED_status = 0;
|
2018-05-21 22:51:38 +02:00
|
|
|
uint16_t live_state_local = 0;
|
2017-09-18 12:55:09 +02:00
|
|
|
|
2018-11-30 21:25:43 +01:00
|
|
|
#define ES_GET_STATE(S) if (READ(S##_PIN)) SBI(live_state_local, S)
|
|
|
|
|
2017-09-18 12:55:09 +02:00
|
|
|
#if HAS_X_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(X_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(X_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Y_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Y_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN_PROBE_PIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z_MIN_PROBE);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
2017-10-29 09:43:44 +01:00
|
|
|
#if HAS_X2_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(X2_MIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_X2_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(X2_MAX);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Y2_MIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Y2_MAX);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
2017-09-18 12:55:09 +02:00
|
|
|
#if HAS_Z2_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z2_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z2_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z3_MIN);
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z3_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_GET_STATE(Z3_MAX);
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if HAS_Z4_MIN
|
|
|
|
ES_GET_STATE(Z4_MIN);
|
|
|
|
#endif
|
|
|
|
#if HAS_Z4_MAX
|
|
|
|
ES_GET_STATE(Z4_MAX);
|
|
|
|
#endif
|
2017-09-18 12:55:09 +02:00
|
|
|
|
2018-05-21 22:51:38 +02:00
|
|
|
uint16_t endstop_change = live_state_local ^ old_live_state_local;
|
2018-11-30 21:25:43 +01:00
|
|
|
#define ES_REPORT_CHANGE(S) if (TEST(endstop_change, S)) SERIAL_ECHOPAIR(" " STRINGIFY(S) ":", TEST(live_state_local, S))
|
2017-09-18 12:55:09 +02:00
|
|
|
|
|
|
|
if (endstop_change) {
|
|
|
|
#if HAS_X_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(X_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(X_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Y_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Y_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN_PROBE_PIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z_MIN_PROBE);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
2017-10-29 09:43:44 +01:00
|
|
|
#if HAS_X2_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(X2_MIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_X2_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(X2_MAX);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Y2_MIN);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Y2_MAX);
|
2017-10-29 09:43:44 +01:00
|
|
|
#endif
|
2017-09-18 12:55:09 +02:00
|
|
|
#if HAS_Z2_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z2_MIN);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z2_MAX);
|
2017-09-18 12:55:09 +02:00
|
|
|
#endif
|
2018-06-19 18:55:49 +02:00
|
|
|
#if HAS_Z3_MIN
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z3_MIN);
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
|
|
|
#if HAS_Z3_MAX
|
2018-11-30 21:25:43 +01:00
|
|
|
ES_REPORT_CHANGE(Z3_MAX);
|
2018-06-19 18:55:49 +02:00
|
|
|
#endif
|
2020-01-20 06:35:07 +01:00
|
|
|
#if HAS_Z4_MIN
|
|
|
|
ES_REPORT_CHANGE(Z4_MIN);
|
|
|
|
#endif
|
|
|
|
#if HAS_Z4_MAX
|
|
|
|
ES_REPORT_CHANGE(Z4_MAX);
|
|
|
|
#endif
|
2019-02-03 06:32:48 +01:00
|
|
|
SERIAL_ECHOLNPGM("\n");
|
2019-06-21 08:20:17 +02:00
|
|
|
analogWrite(pin_t(LED_PIN), local_LED_status);
|
2017-09-18 12:55:09 +02:00
|
|
|
local_LED_status ^= 255;
|
2018-05-21 22:51:38 +02:00
|
|
|
old_live_state_local = live_state_local;
|
2017-09-18 12:55:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PINS_DEBUGGING
|