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 "endstops.h"
|
|
|
|
#include "stepper.h"
|
2017-09-06 11:28:32 +00:00
|
|
|
|
|
|
|
#include "../Marlin.h"
|
|
|
|
#include "../sd/cardreader.h"
|
|
|
|
#include "../module/temperature.h"
|
|
|
|
#include "../lcd/ultralcd.h"
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2018-05-16 07:08:43 +00:00
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
|
|
|
#include HAL_PATH(../HAL, endstop_interrupts.h)
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
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()
|
2018-05-21 20:51:38 +00:00
|
|
|
volatile uint8_t Endstops::hit_state;
|
2016-05-26 18:01:20 +00:00
|
|
|
|
2018-05-21 20:51:38 +00:00
|
|
|
Endstops::esbits_t Endstops::live_state = 0;
|
2018-06-22 01:14:16 +00:00
|
|
|
|
2018-05-21 20:51:38 +00:00
|
|
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
2018-06-22 01:14:16 +00:00
|
|
|
Endstops::esbits_t Endstops::validated_live_state;
|
2018-05-21 20:51:38 +00:00
|
|
|
uint8_t Endstops::endstop_poll_count;
|
|
|
|
#endif
|
2016-05-26 18:01:20 +00:00
|
|
|
|
|
|
|
#if HAS_BED_PROBE
|
|
|
|
volatile bool Endstops::z_probe_enabled = false;
|
|
|
|
#endif
|
|
|
|
|
2018-03-10 11:56:04 +00:00
|
|
|
// Initialized by settings.load()
|
2017-10-29 08:43:44 +00:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
2018-03-10 11:56:04 +00:00
|
|
|
float Endstops::x_endstop_adj;
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
2018-03-10 11:56:04 +00:00
|
|
|
float Endstops::y_endstop_adj;
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
2017-09-18 10:56:10 +00:00
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
2018-03-10 11:56:04 +00:00
|
|
|
float Endstops::z_endstop_adj;
|
2017-09-18 10:56:10 +00:00
|
|
|
#endif
|
|
|
|
|
2016-05-26 18:01:20 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMIN)
|
|
|
|
SET_INPUT_PULLDOWN(X_MIN_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(X_MIN_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 08:43:44 +00:00
|
|
|
#if HAS_X2_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMIN)
|
|
|
|
SET_INPUT_PULLUP(X2_MIN_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMIN)
|
|
|
|
SET_INPUT_PULLDOWN(X2_MIN_PIN);
|
2017-10-29 08:43:44 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(X2_MIN_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
#if HAS_Y_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMIN)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Y_MIN_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Y_MIN_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y_MIN_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 08:43:44 +00:00
|
|
|
#if HAS_Y2_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMIN)
|
|
|
|
SET_INPUT_PULLUP(Y2_MIN_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Y2_MIN_PIN);
|
2017-10-29 08:43:44 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y2_MIN_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
#if HAS_Z_MIN
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMIN)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z_MIN_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Z_MIN_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#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);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN)
|
|
|
|
SET_INPUT_PULLDOWN(Z2_MIN_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#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);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMAX)
|
|
|
|
SET_INPUT_PULLDOWN(X_MAX_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(X_MAX_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 08:43:44 +00:00
|
|
|
#if HAS_X2_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_XMAX)
|
|
|
|
SET_INPUT_PULLUP(X2_MAX_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_XMAX)
|
|
|
|
SET_INPUT_PULLDOWN(X2_MAX_PIN);
|
2017-10-29 08:43:44 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(X2_MAX_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
#if HAS_Y_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMAX)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Y_MAX_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Y_MAX_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y_MAX_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2017-10-29 08:43:44 +00:00
|
|
|
#if HAS_Y2_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_YMAX)
|
|
|
|
SET_INPUT_PULLUP(Y2_MAX_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_YMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Y2_MAX_PIN);
|
2017-10-29 08:43:44 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(Y2_MAX_PIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
#if HAS_Z_MAX
|
|
|
|
#if ENABLED(ENDSTOPPULLUP_ZMAX)
|
2017-03-08 05:43:33 +00:00
|
|
|
SET_INPUT_PULLUP(Z_MAX_PIN);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Z_MAX_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#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);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMAX)
|
|
|
|
SET_INPUT_PULLDOWN(Z2_MAX_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#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);
|
2018-02-19 01:26:23 +00:00
|
|
|
#elif ENABLED(ENDSTOPPULLDOWN_ZMIN_PROBE)
|
|
|
|
SET_INPUT_PULLDOWN(Z_MIN_PROBE_PIN);
|
2017-03-08 05:43:33 +00:00
|
|
|
#else
|
|
|
|
SET_INPUT(Z_MIN_PROBE_PIN);
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-05-16 07:08:43 +00:00
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
|
|
|
setup_endstop_interrupts();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Enable endstops
|
|
|
|
enable_globally(
|
|
|
|
#if ENABLED(ENDSTOPS_ALWAYS_ON_DEFAULT)
|
|
|
|
true
|
|
|
|
#else
|
|
|
|
false
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
2016-04-27 14:15:20 +00:00
|
|
|
} // Endstops::init
|
|
|
|
|
2018-07-11 22:33:26 +00:00
|
|
|
// Called at ~1KHz from Temperature ISR: Poll endstop state if required
|
2018-05-16 07:08:43 +00:00
|
|
|
void Endstops::poll() {
|
|
|
|
|
|
|
|
#if ENABLED(PINS_DEBUGGING)
|
2018-05-23 08:45:25 +00:00
|
|
|
run_monitor(); // report changes in endstop status
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
|
|
|
|
2018-06-22 01:14:16 +00:00
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE) && ENABLED(ENDSTOP_NOISE_FILTER)
|
|
|
|
if (endstop_poll_count) update();
|
|
|
|
#elif DISABLED(ENDSTOP_INTERRUPTS_FEATURE) || ENABLED(ENDSTOP_NOISE_FILTER)
|
|
|
|
update();
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void Endstops::enable_globally(const bool onoff) {
|
|
|
|
enabled_globally = enabled = onoff;
|
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2018-06-22 01:14:16 +00:00
|
|
|
update();
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enable / disable endstop checking
|
|
|
|
void Endstops::enable(const bool onoff) {
|
|
|
|
enabled = onoff;
|
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2018-06-22 01:14:16 +00:00
|
|
|
update();
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable / Enable endstops based on ENSTOPS_ONLY_FOR_HOMING and global enable
|
|
|
|
void Endstops::not_homing() {
|
|
|
|
enabled = enabled_globally;
|
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2018-06-22 01:14:16 +00:00
|
|
|
update();
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-07-01 02:54:07 +00:00
|
|
|
// If the last move failed to trigger an endstop, call kill
|
|
|
|
void Endstops::validate_homing_move() {
|
2018-07-11 22:33:26 +00:00
|
|
|
if (trigger_state()) hit_on_purpose();
|
|
|
|
else kill(PSTR(MSG_ERR_HOMING_FAILED));
|
2018-07-01 02:54:07 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 07:08:43 +00:00
|
|
|
// Enable / disable endstop z-probe checking
|
|
|
|
#if HAS_BED_PROBE
|
2018-06-13 06:22:02 +00:00
|
|
|
void Endstops::enable_z_probe(const bool onoff) {
|
2018-05-16 07:08:43 +00:00
|
|
|
z_probe_enabled = onoff;
|
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2018-06-22 01:14:16 +00:00
|
|
|
update();
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#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-11 22:33:26 +00:00
|
|
|
void Endstops::event_handler() {
|
|
|
|
static uint8_t prev_hit_state; // = 0
|
|
|
|
if (hit_state && hit_state != prev_hit_state) {
|
2016-04-27 14:15:20 +00:00
|
|
|
#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{ \
|
2018-05-09 05:17:53 +00:00
|
|
|
SERIAL_ECHOPAIR(" " STRINGIFY(A) ":", planner.triggered_position_mm(_AXIS(A))); \
|
2016-04-27 14:15:20 +00:00
|
|
|
_SET_STOP_CHAR(A,C); }while(0)
|
|
|
|
|
|
|
|
#define _ENDSTOP_HIT_TEST(A,C) \
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(hit_state, A ##_MIN) || TEST(hit_state, A ##_MAX)) \
|
2016-04-27 14:15:20 +00:00
|
|
|
_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
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(hit_state, Z_MIN_PROBE)) _ENDSTOP_HIT_ECHO(P, 'P');
|
2016-04-27 14:15:20 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
#if ENABLED(ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED) && ENABLED(SDSUPPORT)
|
2018-05-09 05:17:53 +00:00
|
|
|
if (planner.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
|
|
|
|
}
|
2018-07-11 22:33:26 +00:00
|
|
|
prev_hit_state = hit_state;
|
2016-04-27 14:15:20 +00:00
|
|
|
} // 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);
|
2017-10-29 08:43:44 +00:00
|
|
|
#define ES_REPORT(AXIS) do{ \
|
|
|
|
SERIAL_PROTOCOLPGM(MSG_##AXIS); \
|
|
|
|
SERIAL_PROTOCOLLN(((READ(AXIS##_PIN)^AXIS##_ENDSTOP_INVERTING) ? MSG_ENDSTOP_HIT : MSG_ENDSTOP_OPEN)); \
|
|
|
|
}while(0)
|
2016-04-27 21:46:24 +00:00
|
|
|
#if HAS_X_MIN
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(X_MIN);
|
|
|
|
#endif
|
|
|
|
#if HAS_X2_MIN
|
|
|
|
ES_REPORT(X2_MIN);
|
2016-04-27 21:46:24 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(X_MAX);
|
|
|
|
#endif
|
|
|
|
#if HAS_X2_MAX
|
|
|
|
ES_REPORT(X2_MAX);
|
2016-04-27 21:46:24 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(Y_MIN);
|
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MIN
|
|
|
|
ES_REPORT(Y2_MIN);
|
2016-04-27 21:46:24 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(Y_MAX);
|
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MAX
|
|
|
|
ES_REPORT(Y2_MAX);
|
2016-04-27 21:46:24 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(Z_MIN);
|
2016-04-27 21:46:24 +00:00
|
|
|
#endif
|
2016-10-29 06:54:02 +00:00
|
|
|
#if HAS_Z2_MIN
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(Z2_MIN);
|
2016-10-29 06:54:02 +00:00
|
|
|
#endif
|
2016-04-27 21:46:24 +00:00
|
|
|
#if HAS_Z_MAX
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(Z_MAX);
|
2016-04-27 21:46:24 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
2017-10-29 08:43:44 +00:00
|
|
|
ES_REPORT(Z2_MAX);
|
2016-04-27 21:46:24 +00:00
|
|
|
#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
|
|
|
|
|
2018-05-16 07:08:43 +00: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 20:51:38 +00: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 09:15:53 +00:00
|
|
|
|
2018-07-11 22:33:26 +00:00
|
|
|
// Check endstops - Could be called from Temperature ISR!
|
2016-04-27 14:15:20 +00:00
|
|
|
void Endstops::update() {
|
|
|
|
|
2018-06-22 01:14:16 +00:00
|
|
|
#if DISABLED(ENDSTOP_NOISE_FILTER)
|
|
|
|
if (!abort_enabled()) return;
|
|
|
|
#endif
|
|
|
|
|
2018-05-24 05:04:47 +00: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 01:14:16 +00:00
|
|
|
#define COPY_LIVE_STATE(SRC_BIT, DST_BIT) SET_BIT_TO(live_state, DST_BIT, TEST(live_state, SRC_BIT))
|
2016-04-27 14:15:20 +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
|
2018-05-22 06:56:03 +00:00
|
|
|
if (G38_move) UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
2016-09-26 06:30:34 +00:00
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2018-05-23 08:45:25 +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.movement_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
|
2017-04-15 09:23:20 +00:00
|
|
|
#endif
|
2017-04-14 00:32:37 +00:00
|
|
|
|
2018-05-23 08:45:25 +00:00
|
|
|
// Use HEAD for core axes, AXIS for others
|
2017-04-15 09:23:20 +00:00
|
|
|
#if CORE_IS_XY || CORE_IS_XZ
|
|
|
|
#define X_AXIS_HEAD X_HEAD
|
|
|
|
#else
|
|
|
|
#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-15 09:23:20 +00:00
|
|
|
#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_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-15 09:23:20 +00:00
|
|
|
#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_AXIS_HEAD Z_AXIS
|
2016-04-27 14:15:20 +00:00
|
|
|
#endif
|
|
|
|
|
2017-04-15 09:23:20 +00:00
|
|
|
/**
|
2018-06-27 08:18:57 +00:00
|
|
|
* Check and update endstops
|
2017-04-15 09:23:20 +00:00
|
|
|
*/
|
2018-06-27 08:18:57 +00:00
|
|
|
#if HAS_X_MIN
|
2018-06-30 22:27:37 +00:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
2018-06-27 08:18:57 +00:00
|
|
|
UPDATE_ENDSTOP_BIT(X, MIN);
|
|
|
|
#if HAS_X2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(X2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(X_MIN, X2_MIN);
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
2018-06-27 08:18:57 +00:00
|
|
|
#else
|
|
|
|
UPDATE_ENDSTOP_BIT(X, MIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2018-06-27 08:18:57 +00:00
|
|
|
#if HAS_X_MAX
|
2018-06-30 22:27:37 +00:00
|
|
|
#if ENABLED(X_DUAL_ENDSTOPS)
|
2018-06-27 08:18:57 +00:00
|
|
|
UPDATE_ENDSTOP_BIT(X, MAX);
|
|
|
|
#if HAS_X2_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(X2, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(X_MAX, X2_MAX);
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
2018-06-27 08:18:57 +00:00
|
|
|
#else
|
|
|
|
UPDATE_ENDSTOP_BIT(X, MAX);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-06-30 22:27:37 +00:00
|
|
|
#if HAS_Y_MIN
|
2018-06-27 08:18:57 +00:00
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
UPDATE_ENDSTOP_BIT(Y, MIN);
|
|
|
|
#if HAS_Y2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Y2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Y_MIN, Y2_MIN);
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
2018-06-27 08:18:57 +00:00
|
|
|
#else
|
|
|
|
UPDATE_ENDSTOP_BIT(Y, MIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
|
2018-06-30 22:27:37 +00:00
|
|
|
#if HAS_Y_MAX
|
2018-06-27 08:18:57 +00:00
|
|
|
#if ENABLED(Y_DUAL_ENDSTOPS)
|
|
|
|
UPDATE_ENDSTOP_BIT(Y, MAX);
|
|
|
|
#if HAS_Y2_MAX
|
|
|
|
UPDATE_ENDSTOP_BIT(Y2, MAX);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Y_MAX, Y2_MAX);
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
2018-06-27 08:18:57 +00:00
|
|
|
#else
|
|
|
|
UPDATE_ENDSTOP_BIT(Y, MAX);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-05-16 07:08:43 +00:00
|
|
|
|
2018-06-27 08:18:57 +00:00
|
|
|
#if HAS_Z_MIN
|
2018-06-30 22:27:37 +00:00
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
2018-06-27 08:18:57 +00:00
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN);
|
|
|
|
#if HAS_Z2_MIN
|
|
|
|
UPDATE_ENDSTOP_BIT(Z2, MIN);
|
|
|
|
#else
|
|
|
|
COPY_LIVE_STATE(Z_MIN, Z2_MIN);
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
2018-06-27 08:18:57 +00:00
|
|
|
#elif ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN);
|
|
|
|
#elif Z_HOME_DIR < 0
|
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// When closing the gap check the enabled probe
|
|
|
|
#if ENABLED(Z_MIN_PROBE_ENDSTOP)
|
|
|
|
UPDATE_ENDSTOP_BIT(Z, MIN_PROBE);
|
|
|
|
#endif
|
|
|
|
|
2018-06-30 22:27:37 +00:00
|
|
|
#if HAS_Z_MAX
|
2018-06-27 08:18:57 +00:00
|
|
|
// Check both Z dual endstops
|
|
|
|
#if ENABLED(Z_DUAL_ENDSTOPS)
|
|
|
|
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 20:51:38 +00:00
|
|
|
#endif
|
2018-06-27 08:18:57 +00:00
|
|
|
#elif DISABLED(Z_MIN_PROBE_ENDSTOP) || Z_MAX_PIN != Z_MIN_PROBE_PIN
|
|
|
|
// If this pin isn't the bed probe it's the Z endstop
|
|
|
|
UPDATE_ENDSTOP_BIT(Z, MAX);
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-05-21 20:51:38 +00:00
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_NOISE_FILTER)
|
2018-06-22 01:14:16 +00: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-05-21 20:51:38 +00:00
|
|
|
endstop_poll_count = 7;
|
|
|
|
old_live_state = live_state;
|
|
|
|
}
|
|
|
|
else if (endstop_poll_count && !--endstop_poll_count)
|
|
|
|
validated_live_state = live_state;
|
|
|
|
|
2018-06-22 01:14:16 +00:00
|
|
|
if (!abort_enabled()) return;
|
2018-05-21 20:51:38 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Test the current status of an endstop
|
2018-06-22 01:14:16 +00:00
|
|
|
#define TEST_ENDSTOP(ENDSTOP) (TEST(state(), ENDSTOP))
|
2018-05-21 20:51:38 +00:00
|
|
|
|
|
|
|
// 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 { \
|
2018-06-02 00:02:22 +00:00
|
|
|
if (TEST_ENDSTOP(_ENDSTOP(AXIS, MINMAX))) { \
|
|
|
|
_ENDSTOP_HIT(AXIS, MINMAX); \
|
|
|
|
planner.endstop_triggered(_AXIS(AXIS)); \
|
|
|
|
} \
|
|
|
|
}while(0)
|
2018-05-21 20:51:38 +00:00
|
|
|
|
2018-06-02 00:02:22 +00:00
|
|
|
// Call the endstop triggered routine for dual endstops
|
2018-05-21 20:51:38 +00:00
|
|
|
#define PROCESS_DUAL_ENDSTOP(AXIS1, AXIS2, MINMAX) do { \
|
2018-06-02 00:02:22 +00:00
|
|
|
const byte dual_hit = TEST_ENDSTOP(_ENDSTOP(AXIS1, MINMAX)) | (TEST_ENDSTOP(_ENDSTOP(AXIS2, MINMAX)) << 1); \
|
|
|
|
if (dual_hit) { \
|
|
|
|
_ENDSTOP_HIT(AXIS1, MINMAX); \
|
|
|
|
/* if not performing home or if both endstops were trigged during homing... */ \
|
2018-07-11 22:33:26 +00:00
|
|
|
if (!stepper.homing_dual_axis || dual_hit == 0b11) \
|
2018-05-21 20:51:38 +00:00
|
|
|
planner.endstop_triggered(_AXIS(AXIS1)); \
|
2018-06-02 00:02:22 +00:00
|
|
|
} \
|
|
|
|
}while(0)
|
2018-05-21 20:51:38 +00:00
|
|
|
|
|
|
|
#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))) {
|
2018-05-24 05:04:47 +00:00
|
|
|
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); }
|
2018-05-21 20:51:38 +00:00
|
|
|
G38_endstop_hit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Now, we must signal, after validation, if an endstop limit is pressed or not
|
2018-05-23 08:45:25 +00:00
|
|
|
if (stepper.axis_is_moving(X_AXIS)) {
|
2018-05-21 20:51:38 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 08:45:25 +00:00
|
|
|
if (stepper.axis_is_moving(Y_AXIS)) {
|
2018-05-21 20:51:38 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 08:45:25 +00:00
|
|
|
if (stepper.axis_is_moving(Z_AXIS)) {
|
2018-05-21 20:51:38 +00:00
|
|
|
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);
|
2018-06-28 10:06:11 +00:00
|
|
|
#elif ENABLED(Z_MIN_PROBE_ENDSTOP)
|
|
|
|
if (!z_probe_enabled) PROCESS_ENDSTOP(Z, MIN);
|
2018-05-21 20:51:38 +00:00
|
|
|
#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);
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
2018-05-16 07:08:43 +00:00
|
|
|
#endif
|
2016-04-27 14:15:20 +00:00
|
|
|
}
|
2018-05-16 07:08:43 +00:00
|
|
|
}
|
2016-04-27 14:15:20 +00:00
|
|
|
} // Endstops::update()
|
2017-09-18 10:55:09 +00:00
|
|
|
|
|
|
|
#if ENABLED(PINS_DEBUGGING)
|
|
|
|
|
|
|
|
bool Endstops::monitor_flag = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* monitors endstops & Z probe for changes
|
|
|
|
*
|
|
|
|
* If a change is detected then the LED is toggled and
|
|
|
|
* a message is sent out the serial port
|
|
|
|
*
|
|
|
|
* 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 20:51:38 +00:00
|
|
|
static uint16_t old_live_state_local = 0;
|
2017-09-18 10:55:09 +00:00
|
|
|
static uint8_t local_LED_status = 0;
|
2018-05-21 20:51:38 +00:00
|
|
|
uint16_t live_state_local = 0;
|
2017-09-18 10:55:09 +00:00
|
|
|
|
|
|
|
#if HAS_X_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(X_MIN_PIN)) SBI(live_state_local, X_MIN);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(X_MAX_PIN)) SBI(live_state_local, X_MAX);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Y_MIN_PIN)) SBI(live_state_local, Y_MIN);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Y_MAX_PIN)) SBI(live_state_local, Y_MAX);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Z_MIN_PIN)) SBI(live_state_local, Z_MIN);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Z_MAX_PIN)) SBI(live_state_local, Z_MAX);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN_PROBE_PIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Z_MIN_PROBE_PIN)) SBI(live_state_local, Z_MIN_PROBE);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
2017-10-29 08:43:44 +00:00
|
|
|
#if HAS_X2_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(X2_MIN_PIN)) SBI(live_state_local, X2_MIN);
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_X2_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(X2_MAX_PIN)) SBI(live_state_local, X2_MAX);
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Y2_MIN_PIN)) SBI(live_state_local, Y2_MIN);
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Y2_MAX_PIN)) SBI(live_state_local, Y2_MAX);
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
2017-09-18 10:55:09 +00:00
|
|
|
#if HAS_Z2_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Z2_MIN_PIN)) SBI(live_state_local, Z2_MIN);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (READ(Z2_MAX_PIN)) SBI(live_state_local, Z2_MAX);
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
|
2018-05-21 20:51:38 +00:00
|
|
|
uint16_t endstop_change = live_state_local ^ old_live_state_local;
|
2017-09-18 10:55:09 +00:00
|
|
|
|
|
|
|
if (endstop_change) {
|
|
|
|
#if HAS_X_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR(" X_MIN:", TEST(live_state_local, X_MIN));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_X_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR(" X_MAX:", TEST(live_state_local, X_MAX));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR(" Y_MIN:", TEST(live_state_local, Y_MIN));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR(" Y_MAX:", TEST(live_state_local, Y_MAX));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR(" Z_MIN:", TEST(live_state_local, Z_MIN));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR(" Z_MAX:", TEST(live_state_local, Z_MAX));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z_MIN_PROBE_PIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR(" PROBE:", TEST(live_state_local, Z_MIN_PROBE));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
2017-10-29 08:43:44 +00:00
|
|
|
#if HAS_X2_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR(" X2_MIN:", TEST(live_state_local, X2_MIN));
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_X2_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR(" X2_MAX:", TEST(live_state_local, X2_MAX));
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR(" Y2_MIN:", TEST(live_state_local, Y2_MIN));
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Y2_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR(" Y2_MAX:", TEST(live_state_local, Y2_MAX));
|
2017-10-29 08:43:44 +00:00
|
|
|
#endif
|
2017-09-18 10:55:09 +00:00
|
|
|
#if HAS_Z2_MIN
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR(" Z2_MIN:", TEST(live_state_local, Z2_MIN));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
#if HAS_Z2_MAX
|
2018-05-21 20:51:38 +00:00
|
|
|
if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR(" Z2_MAX:", TEST(live_state_local, Z2_MAX));
|
2017-09-18 10:55:09 +00:00
|
|
|
#endif
|
|
|
|
SERIAL_PROTOCOLPGM("\n\n");
|
|
|
|
analogWrite(LED_PIN, local_LED_status);
|
|
|
|
local_LED_status ^= 255;
|
2018-05-21 20:51:38 +00:00
|
|
|
old_live_state_local = live_state_local;
|
2017-09-18 10:55:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PINS_DEBUGGING
|