|
|
|
@ -34,6 +34,10 @@
|
|
|
|
|
#include "../../module/servo.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
|
#include "../../feature/bltouch.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
|
#include "../../feature/host_actions.h"
|
|
|
|
|
#endif
|
|
|
|
@ -91,122 +95,152 @@ inline void toggle_pins() {
|
|
|
|
|
} // toggle_pins
|
|
|
|
|
|
|
|
|
|
inline void servo_probe_test() {
|
|
|
|
|
|
|
|
|
|
#if !(NUM_SERVOS > 0 && HAS_SERVO_0)
|
|
|
|
|
|
|
|
|
|
SERIAL_ERROR_MSG("SERVO not setup");
|
|
|
|
|
SERIAL_ERROR_MSG("SERVO not set up.");
|
|
|
|
|
|
|
|
|
|
#elif !HAS_Z_SERVO_PROBE
|
|
|
|
|
|
|
|
|
|
SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not setup");
|
|
|
|
|
SERIAL_ERROR_MSG("Z_PROBE_SERVO_NR not set up.");
|
|
|
|
|
|
|
|
|
|
#else // HAS_Z_SERVO_PROBE
|
|
|
|
|
|
|
|
|
|
const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR);
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM("Servo probe test");
|
|
|
|
|
SERIAL_ECHOLNPAIR(". using index: ", probe_index);
|
|
|
|
|
SERIAL_ECHOLNPAIR(". deploy angle: ", servo_angles[probe_index][0]);
|
|
|
|
|
SERIAL_ECHOLNPAIR(". stow angle: ", servo_angles[probe_index][1]);
|
|
|
|
|
SERIAL_ECHOLNPAIR("Servo probe test\n"
|
|
|
|
|
". using index: ", int(probe_index),
|
|
|
|
|
", deploy angle: ", servo_angles[probe_index][0],
|
|
|
|
|
", stow angle: ", servo_angles[probe_index][1]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
bool probe_inverting;
|
|
|
|
|
bool deploy_state, stow_state;
|
|
|
|
|
|
|
|
|
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
|
|
|
|
|
|
|
|
|
|
#define PROBE_TEST_PIN Z_MIN_PIN
|
|
|
|
|
constexpr bool probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPAIR(". probe uses Z_MIN pin: ", PROBE_TEST_PIN);
|
|
|
|
|
SERIAL_ECHOLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)");
|
|
|
|
|
SERIAL_ECHOLNPAIR(". Probe Z_MIN_PIN: ", int(PROBE_TEST_PIN));
|
|
|
|
|
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: ");
|
|
|
|
|
|
|
|
|
|
#if Z_MIN_ENDSTOP_INVERTING
|
|
|
|
|
SERIAL_ECHOLNPGM("true");
|
|
|
|
|
#else
|
|
|
|
|
SERIAL_ECHOLNPGM("false");
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
probe_inverting = Z_MIN_ENDSTOP_INVERTING;
|
|
|
|
|
|
|
|
|
|
#elif USES_Z_MIN_PROBE_ENDSTOP
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
|
|
|
|
|
SERIAL_ECHOLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
|
|
|
|
|
SERIAL_ECHOLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)");
|
|
|
|
|
SERIAL_ECHOPGM(". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
|
|
|
|
|
|
|
|
|
#if Z_MIN_PROBE_ENDSTOP_INVERTING
|
|
|
|
|
SERIAL_ECHOLNPGM("true");
|
|
|
|
|
#else
|
|
|
|
|
SERIAL_ECHOLNPGM("false");
|
|
|
|
|
#endif
|
|
|
|
|
constexpr bool probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
|
|
|
|
|
|
|
|
|
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
|
|
|
|
|
SERIAL_ECHOLNPAIR(". Probe Z_MIN_PROBE_PIN: ", int(PROBE_TEST_PIN));
|
|
|
|
|
SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM(". deploy & stow 4 times");
|
|
|
|
|
serialprint_truefalse(probe_inverting);
|
|
|
|
|
SERIAL_EOL();
|
|
|
|
|
|
|
|
|
|
SET_INPUT_PULLUP(PROBE_TEST_PIN);
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
bool deploy_state, stow_state;
|
|
|
|
|
do {
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
|
|
safe_delay(500);
|
|
|
|
|
deploy_state = READ(PROBE_TEST_PIN);
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
|
|
|
safe_delay(500);
|
|
|
|
|
stow_state = READ(PROBE_TEST_PIN);
|
|
|
|
|
} while (++i < 4);
|
|
|
|
|
if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING - INVERTING setting probably backwards");
|
|
|
|
|
|
|
|
|
|
if (deploy_state != stow_state) {
|
|
|
|
|
SERIAL_ECHOLNPGM("BLTouch clone detected");
|
|
|
|
|
if (deploy_state) {
|
|
|
|
|
SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)");
|
|
|
|
|
SERIAL_ECHOLNPGM(". STOWED (triggered) state: LOW (logic 0)");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)");
|
|
|
|
|
SERIAL_ECHOLNPGM(". STOWED (triggered) state: HIGH (logic 1)");
|
|
|
|
|
|
|
|
|
|
// First, check for a probe that recognizes an advanced BLTouch sequence.
|
|
|
|
|
// In addition to STOW and DEPLOY, it uses SW MODE (and RESET in the beginning)
|
|
|
|
|
// to see if this is one of the following: BLTOUCH Classic 1.2, 1.3, or
|
|
|
|
|
// BLTouch Smart 1.0, 2.0, 2.2, 3.0, 3.1. But only if the user has actually
|
|
|
|
|
// configured a BLTouch as being present. If the user has not configured this,
|
|
|
|
|
// the BLTouch will be detected in the last phase of these tests (see further on).
|
|
|
|
|
bool blt = false;
|
|
|
|
|
// This code will try to detect a BLTouch probe or clone
|
|
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
|
SERIAL_ECHOLNPGM(". Check for BLTOUCH");
|
|
|
|
|
bltouch._reset();
|
|
|
|
|
bltouch._stow();
|
|
|
|
|
if (probe_inverting == READ(PROBE_TEST_PIN)) {
|
|
|
|
|
bltouch._set_SW_mode();
|
|
|
|
|
if (probe_inverting != READ(PROBE_TEST_PIN)) {
|
|
|
|
|
bltouch._deploy();
|
|
|
|
|
if (probe_inverting == READ(PROBE_TEST_PIN)) {
|
|
|
|
|
bltouch._stow();
|
|
|
|
|
SERIAL_ECHOLNPGM("= BLTouch Classic 1.2, 1.3, Smart 1.0, 2.0, 2.2, 3.0, 3.1 detected.");
|
|
|
|
|
// Check for a 3.1 by letting the user trigger it, later
|
|
|
|
|
blt = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
|
SERIAL_ECHOLNPGM("ERROR: BLTOUCH enabled - set this device up as a Z Servo Probe with inverting as true.");
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
else { // measure active signal length
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
|
|
safe_delay(500);
|
|
|
|
|
SERIAL_ECHOLNPGM("please trigger probe");
|
|
|
|
|
uint16_t probe_counter = 0;
|
|
|
|
|
|
|
|
|
|
// Allow 30 seconds max for operator to trigger probe
|
|
|
|
|
for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
|
|
|
|
|
|
|
|
|
safe_delay(2);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
|
|
|
|
// The following code is common to all kinds of servo probes.
|
|
|
|
|
// Since it could be a real servo or a BLTouch (any kind) or a clone,
|
|
|
|
|
// use only "common" functions - i.e. SERVO_MOVE. No bltouch.xxxx stuff.
|
|
|
|
|
|
|
|
|
|
// If it is already recognised as a being a BLTouch, no need for this test
|
|
|
|
|
if (!blt) {
|
|
|
|
|
// DEPLOY and STOW 4 times and see if the signal follows
|
|
|
|
|
// Then it is a mechanical switch
|
|
|
|
|
uint8_t i = 0;
|
|
|
|
|
SERIAL_ECHOLNPGM(". Deploy & stow 4 times");
|
|
|
|
|
do {
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
|
|
safe_delay(500);
|
|
|
|
|
deploy_state = READ(PROBE_TEST_PIN);
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
|
|
|
safe_delay(500);
|
|
|
|
|
stow_state = READ(PROBE_TEST_PIN);
|
|
|
|
|
} while (++i < 4);
|
|
|
|
|
|
|
|
|
|
if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING: INVERTING setting probably backwards.");
|
|
|
|
|
|
|
|
|
|
if (deploy_state != stow_state) {
|
|
|
|
|
SERIAL_ECHOLNPGM("= Mechanical Switch detected");
|
|
|
|
|
if (deploy_state) {
|
|
|
|
|
SERIAL_ECHOLNPAIR(" DEPLOYED state: HIGH (logic 1)",
|
|
|
|
|
" STOWED (triggered) state: LOW (logic 0)");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
SERIAL_ECHOLNPAIR(" DEPLOYED state: LOW (logic 0)",
|
|
|
|
|
" STOWED (triggered) state: HIGH (logic 1)");
|
|
|
|
|
}
|
|
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
|
SERIAL_ECHOLNPGM("FAIL: BLTOUCH enabled - Set up this device as a Servo Probe with INVERTING set to 'true'.");
|
|
|
|
|
#endif
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
|
|
|
|
|
// Ask the user for a trigger event and measure the pulse width.
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
|
|
safe_delay(500);
|
|
|
|
|
SERIAL_ECHOLNPGM("** Please trigger probe within 30 sec **");
|
|
|
|
|
uint16_t probe_counter = 0;
|
|
|
|
|
|
|
|
|
|
for (probe_counter = 1; probe_counter < 50 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter)
|
|
|
|
|
safe_delay(2);
|
|
|
|
|
// Wait 30 seconds for user to trigger probe
|
|
|
|
|
for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) {
|
|
|
|
|
safe_delay(2);
|
|
|
|
|
|
|
|
|
|
if (probe_counter == 50)
|
|
|
|
|
SERIAL_ECHOLNPGM("Z Servo Probe detected"); // >= 100mS active time
|
|
|
|
|
else if (probe_counter >= 2)
|
|
|
|
|
SERIAL_ECHOLNPAIR("BLTouch compatible probe detected - pulse width (+/- 4mS): ", probe_counter * 2); // allow 4 - 100mS pulse
|
|
|
|
|
else
|
|
|
|
|
SERIAL_ECHOLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
|
|
|
|
if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
|
|
|
|
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
|
|
|
if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
|
|
|
|
|
for (probe_counter = 0; probe_counter < 15 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter) safe_delay(2);
|
|
|
|
|
|
|
|
|
|
} // pulse detected
|
|
|
|
|
if (probe_counter = 15)
|
|
|
|
|
SERIAL_ECHOLNPGM(". Pulse width: 30ms or more");
|
|
|
|
|
else
|
|
|
|
|
SERIAL_ECHOLNPAIR(". Pulse width (+/- 4ms): ", probe_counter * 2);
|
|
|
|
|
|
|
|
|
|
} // for loop waiting for trigger
|
|
|
|
|
if (probe_counter >= 4) {
|
|
|
|
|
if (probe_counter == 15) {
|
|
|
|
|
if (blt) SERIAL_ECHOPGM("= BLTouch V3.1");
|
|
|
|
|
else SERIAL_ECHOPGM("= Z Servo Probe");
|
|
|
|
|
}
|
|
|
|
|
else SERIAL_ECHOPGM("= BLTouch pre V3.1 or compatible probe");
|
|
|
|
|
SERIAL_ECHOLNPGM(" detected.");
|
|
|
|
|
}
|
|
|
|
|
else SERIAL_ECHOLNPGM("FAIL: Noise detected - please re-run test");
|
|
|
|
|
|
|
|
|
|
if (probe_counter == 0) SERIAL_ECHOLNPGM("trigger not detected");
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // measure active signal length
|
|
|
|
|
if (!probe_counter) SERIAL_ECHOLNPGM("FAIL: Trigger not detected");
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
#endif // HAS_Z_SERVO_PROBE
|
|
|
|
|
|
|
|
|
|
} // servo_probe_test
|
|
|
|
|
|
|
|
|
@ -239,12 +273,10 @@ inline void servo_probe_test() {
|
|
|
|
|
*/
|
|
|
|
|
void GcodeSuite::M43() {
|
|
|
|
|
|
|
|
|
|
if (parser.seen('T')) { // must be first or else its "S" and "E" parameters will execute endstop or servo test
|
|
|
|
|
toggle_pins();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 'T' must be first. It uses 'S' and 'E' differently.
|
|
|
|
|
if (parser.seen('T')) return toggle_pins();
|
|
|
|
|
|
|
|
|
|
// Enable or disable endstop monitoring
|
|
|
|
|
// 'E' Enable or disable endstop monitoring and return
|
|
|
|
|
if (parser.seen('E')) {
|
|
|
|
|
endstops.monitor_flag = parser.value_bool();
|
|
|
|
|
SERIAL_ECHOPGM("endstop monitor ");
|
|
|
|
@ -253,25 +285,23 @@ void GcodeSuite::M43() {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parser.seen('S')) {
|
|
|
|
|
servo_probe_test();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 'S' Run servo probe test and return
|
|
|
|
|
if (parser.seen('S')) return servo_probe_test();
|
|
|
|
|
|
|
|
|
|
// Get the range of pins to test or watch
|
|
|
|
|
// 'P' Get the range of pins to test or watch
|
|
|
|
|
uint8_t first_pin = PARSED_PIN_INDEX('P', 0),
|
|
|
|
|
last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1;
|
|
|
|
|
|
|
|
|
|
if (first_pin > last_pin) return;
|
|
|
|
|
|
|
|
|
|
// 'I' to ignore protected pins
|
|
|
|
|
const bool ignore_protection = parser.boolval('I');
|
|
|
|
|
|
|
|
|
|
// Watch until click, M108, or reset
|
|
|
|
|
// 'W' Watch until click, M108, or reset
|
|
|
|
|
if (parser.boolval('W')) {
|
|
|
|
|
SERIAL_ECHOLNPGM("Watching pins");
|
|
|
|
|
|
|
|
|
|
#ifdef ARDUINO_ARCH_SAM
|
|
|
|
|
NOLESS(first_pin, 2); // don't hijack the UART pins
|
|
|
|
|
NOLESS(first_pin, 2); // Don't hijack the UART pins
|
|
|
|
|
#endif
|
|
|
|
|
uint8_t pin_state[last_pin - first_pin + 1];
|
|
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
|
|
@ -280,11 +310,11 @@ void GcodeSuite::M43() {
|
|
|
|
|
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
|
|
|
|
|
pinMode(pin, INPUT_PULLUP);
|
|
|
|
|
delay(1);
|
|
|
|
|
/*
|
|
|
|
|
/*
|
|
|
|
|
if (IS_ANALOG(pin))
|
|
|
|
|
pin_state[pin - first_pin] = analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)); // int16_t pin_state[...]
|
|
|
|
|
else
|
|
|
|
|
//*/
|
|
|
|
|
//*/
|
|
|
|
|
pin_state[i - first_pin] = extDigitalRead(pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -303,9 +333,9 @@ void GcodeSuite::M43() {
|
|
|
|
|
if (M43_NEVER_TOUCH(i) || (!ignore_protection && pin_is_protected(pin))) continue;
|
|
|
|
|
const byte val =
|
|
|
|
|
/*
|
|
|
|
|
IS_ANALOG(pin)
|
|
|
|
|
? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
|
|
|
|
|
:
|
|
|
|
|
IS_ANALOG(pin)
|
|
|
|
|
? analogRead(DIGITAL_PIN_TO_ANALOG_PIN(pin)) : // int16_t val
|
|
|
|
|
:
|
|
|
|
|
//*/
|
|
|
|
|
extDigitalRead(pin);
|
|
|
|
|
if (val != pin_state[i - first_pin]) {
|
|
|
|
@ -315,21 +345,18 @@ void GcodeSuite::M43() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if HAS_RESUME_CONTINUE
|
|
|
|
|
if (!wait_for_user) {
|
|
|
|
|
KEEPALIVE_STATE(IN_HANDLER);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (!wait_for_user) { KEEPALIVE_STATE(IN_HANDLER); break; }
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
safe_delay(200);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Report current state of selected pin(s)
|
|
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
|
|
|
pin_t pin = GET_PIN_MAP_PIN(i);
|
|
|
|
|
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
|
|
|
|
|
else {
|
|
|
|
|
// Report current state of selected pin(s)
|
|
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) {
|
|
|
|
|
pin_t pin = GET_PIN_MAP_PIN(i);
|
|
|
|
|
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|