|
@ -34,6 +34,10 @@ |
|
|
#include "../../module/servo.h" |
|
|
#include "../../module/servo.h" |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BLTOUCH) |
|
|
|
|
|
#include "../../feature/bltouch.h" |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT) |
|
|
#if ENABLED(HOST_PROMPT_SUPPORT) |
|
|
#include "../../feature/host_actions.h" |
|
|
#include "../../feature/host_actions.h" |
|
|
#endif |
|
|
#endif |
|
@ -91,62 +95,86 @@ inline void toggle_pins() { |
|
|
} // toggle_pins
|
|
|
} // toggle_pins
|
|
|
|
|
|
|
|
|
inline void servo_probe_test() { |
|
|
inline void servo_probe_test() { |
|
|
|
|
|
|
|
|
#if !(NUM_SERVOS > 0 && HAS_SERVO_0) |
|
|
#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 |
|
|
#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
|
|
|
#else // HAS_Z_SERVO_PROBE
|
|
|
|
|
|
|
|
|
const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR); |
|
|
const uint8_t probe_index = parser.byteval('P', Z_PROBE_SERVO_NR); |
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM("Servo probe test"); |
|
|
SERIAL_ECHOLNPAIR("Servo probe test\n" |
|
|
SERIAL_ECHOLNPAIR(". using index: ", probe_index); |
|
|
". using index: ", int(probe_index), |
|
|
SERIAL_ECHOLNPAIR(". deploy angle: ", servo_angles[probe_index][0]); |
|
|
", deploy angle: ", servo_angles[probe_index][0], |
|
|
SERIAL_ECHOLNPAIR(". stow angle: ", servo_angles[probe_index][1]); |
|
|
", 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) |
|
|
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) |
|
|
|
|
|
|
|
|
#define PROBE_TEST_PIN Z_MIN_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_ECHOLNPAIR(". Probe Z_MIN_PIN: ", int(PROBE_TEST_PIN)); |
|
|
SERIAL_ECHOLNPGM(". uses Z_MIN_ENDSTOP_INVERTING (ignores Z_MIN_PROBE_ENDSTOP_INVERTING)"); |
|
|
|
|
|
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: "); |
|
|
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: "); |
|
|
|
|
|
|
|
|
#if Z_MIN_ENDSTOP_INVERTING |
|
|
|
|
|
SERIAL_ECHOLNPGM("true"); |
|
|
|
|
|
#else |
|
|
#else |
|
|
SERIAL_ECHOLNPGM("false"); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
probe_inverting = Z_MIN_ENDSTOP_INVERTING; |
|
|
|
|
|
|
|
|
|
|
|
#elif USES_Z_MIN_PROBE_ENDSTOP |
|
|
|
|
|
|
|
|
|
|
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN |
|
|
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN |
|
|
SERIAL_ECHOLNPAIR(". probe uses Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN); |
|
|
constexpr bool probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING; |
|
|
SERIAL_ECHOLNPGM(". uses Z_MIN_PROBE_ENDSTOP_INVERTING (ignores Z_MIN_ENDSTOP_INVERTING)"); |
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPAIR(". Probe Z_MIN_PROBE_PIN: ", int(PROBE_TEST_PIN)); |
|
|
SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: "); |
|
|
SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: "); |
|
|
|
|
|
|
|
|
#if Z_MIN_PROBE_ENDSTOP_INVERTING |
|
|
|
|
|
SERIAL_ECHOLNPGM("true"); |
|
|
|
|
|
#else |
|
|
|
|
|
SERIAL_ECHOLNPGM("false"); |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING; |
|
|
serialprint_truefalse(probe_inverting); |
|
|
|
|
|
SERIAL_EOL(); |
|
|
|
|
|
|
|
|
|
|
|
SET_INPUT_PULLUP(PROBE_TEST_PIN); |
|
|
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
SERIAL_ECHOLNPGM(". deploy & stow 4 times"); |
|
|
// The following code is common to all kinds of servo probes.
|
|
|
SET_INPUT_PULLUP(PROBE_TEST_PIN); |
|
|
// 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; |
|
|
uint8_t i = 0; |
|
|
bool deploy_state, stow_state; |
|
|
SERIAL_ECHOLNPGM(". Deploy & stow 4 times"); |
|
|
do { |
|
|
do { |
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
safe_delay(500); |
|
|
safe_delay(500); |
|
@ -155,58 +183,64 @@ inline void servo_probe_test() { |
|
|
safe_delay(500); |
|
|
safe_delay(500); |
|
|
stow_state = READ(PROBE_TEST_PIN); |
|
|
stow_state = READ(PROBE_TEST_PIN); |
|
|
} while (++i < 4); |
|
|
} while (++i < 4); |
|
|
if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING - INVERTING setting probably backwards"); |
|
|
|
|
|
|
|
|
if (probe_inverting != deploy_state) SERIAL_ECHOLNPGM("WARNING: INVERTING setting probably backwards."); |
|
|
|
|
|
|
|
|
if (deploy_state != stow_state) { |
|
|
if (deploy_state != stow_state) { |
|
|
SERIAL_ECHOLNPGM("BLTouch clone detected"); |
|
|
SERIAL_ECHOLNPGM("= Mechanical Switch detected"); |
|
|
if (deploy_state) { |
|
|
if (deploy_state) { |
|
|
SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)"); |
|
|
SERIAL_ECHOLNPAIR(" DEPLOYED state: HIGH (logic 1)", |
|
|
SERIAL_ECHOLNPGM(". STOWED (triggered) state: LOW (logic 0)"); |
|
|
" STOWED (triggered) state: LOW (logic 0)"); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)"); |
|
|
SERIAL_ECHOLNPAIR(" DEPLOYED state: LOW (logic 0)", |
|
|
SERIAL_ECHOLNPGM(". STOWED (triggered) state: HIGH (logic 1)"); |
|
|
" STOWED (triggered) state: HIGH (logic 1)"); |
|
|
} |
|
|
} |
|
|
#if ENABLED(BLTOUCH) |
|
|
#if ENABLED(BLTOUCH) |
|
|
SERIAL_ECHOLNPGM("ERROR: BLTOUCH enabled - set this device up as a Z Servo Probe with inverting as true."); |
|
|
SERIAL_ECHOLNPGM("FAIL: BLTOUCH enabled - Set up this device as a Servo Probe with INVERTING set to 'true'."); |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else { // measure active signal length
|
|
|
|
|
|
|
|
|
// Ask the user for a trigger event and measure the pulse width.
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
|
|
|
safe_delay(500); |
|
|
safe_delay(500); |
|
|
SERIAL_ECHOLNPGM("please trigger probe"); |
|
|
SERIAL_ECHOLNPGM("** Please trigger probe within 30 sec **"); |
|
|
uint16_t probe_counter = 0; |
|
|
uint16_t probe_counter = 0; |
|
|
|
|
|
|
|
|
// Allow 30 seconds max for operator to trigger probe
|
|
|
// Wait 30 seconds for user to trigger probe
|
|
|
for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) { |
|
|
for (uint16_t j = 0; j < 500 * 30 && probe_counter == 0 ; j++) { |
|
|
|
|
|
|
|
|
safe_delay(2); |
|
|
safe_delay(2); |
|
|
|
|
|
|
|
|
if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
|
|
if (0 == j % (500 * 1)) gcode.reset_stepper_timeout(); // Keep steppers powered
|
|
|
|
|
|
|
|
|
if (deploy_state != READ(PROBE_TEST_PIN)) { // probe triggered
|
|
|
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); |
|
|
|
|
|
|
|
|
for (probe_counter = 1; probe_counter < 50 && deploy_state != READ(PROBE_TEST_PIN); ++probe_counter) |
|
|
if (probe_counter = 15) |
|
|
safe_delay(2); |
|
|
SERIAL_ECHOLNPGM(". Pulse width: 30ms or more"); |
|
|
|
|
|
|
|
|
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 |
|
|
else |
|
|
SERIAL_ECHOLNPGM("noise detected - please re-run test"); // less than 2mS pulse
|
|
|
SERIAL_ECHOLNPAIR(". Pulse width (+/- 4ms): ", probe_counter * 2); |
|
|
|
|
|
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
|
if (probe_counter >= 4) { |
|
|
|
|
|
if (probe_counter == 15) { |
|
|
} // pulse detected
|
|
|
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"); |
|
|
|
|
|
|
|
|
} // for loop waiting for trigger
|
|
|
MOVE_SERVO(probe_index, servo_angles[Z_PROBE_SERVO_NR][1]); // Stow
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (probe_counter == 0) SERIAL_ECHOLNPGM("trigger not detected"); |
|
|
if (!probe_counter) SERIAL_ECHOLNPGM("FAIL: Trigger not detected"); |
|
|
|
|
|
|
|
|
} // measure active signal length
|
|
|
#endif // HAS_Z_SERVO_PROBE
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
} // servo_probe_test
|
|
|
} // servo_probe_test
|
|
|
|
|
|
|
|
@ -239,12 +273,10 @@ inline void servo_probe_test() { |
|
|
*/ |
|
|
*/ |
|
|
void GcodeSuite::M43() { |
|
|
void GcodeSuite::M43() { |
|
|
|
|
|
|
|
|
if (parser.seen('T')) { // must be first or else its "S" and "E" parameters will execute endstop or servo test
|
|
|
// 'T' must be first. It uses 'S' and 'E' differently.
|
|
|
toggle_pins(); |
|
|
if (parser.seen('T')) return toggle_pins(); |
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Enable or disable endstop monitoring
|
|
|
// 'E' Enable or disable endstop monitoring and return
|
|
|
if (parser.seen('E')) { |
|
|
if (parser.seen('E')) { |
|
|
endstops.monitor_flag = parser.value_bool(); |
|
|
endstops.monitor_flag = parser.value_bool(); |
|
|
SERIAL_ECHOPGM("endstop monitor "); |
|
|
SERIAL_ECHOPGM("endstop monitor "); |
|
@ -253,25 +285,23 @@ void GcodeSuite::M43() { |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (parser.seen('S')) { |
|
|
// 'S' Run servo probe test and return
|
|
|
servo_probe_test(); |
|
|
if (parser.seen('S')) return servo_probe_test(); |
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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), |
|
|
uint8_t first_pin = PARSED_PIN_INDEX('P', 0), |
|
|
last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1; |
|
|
last_pin = parser.seenval('P') ? first_pin : NUMBER_PINS_TOTAL - 1; |
|
|
|
|
|
|
|
|
if (first_pin > last_pin) return; |
|
|
if (first_pin > last_pin) return; |
|
|
|
|
|
|
|
|
|
|
|
// 'I' to ignore protected pins
|
|
|
const bool ignore_protection = parser.boolval('I'); |
|
|
const bool ignore_protection = parser.boolval('I'); |
|
|
|
|
|
|
|
|
// Watch until click, M108, or reset
|
|
|
// 'W' Watch until click, M108, or reset
|
|
|
if (parser.boolval('W')) { |
|
|
if (parser.boolval('W')) { |
|
|
SERIAL_ECHOLNPGM("Watching pins"); |
|
|
SERIAL_ECHOLNPGM("Watching pins"); |
|
|
|
|
|
|
|
|
#ifdef ARDUINO_ARCH_SAM |
|
|
#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 |
|
|
#endif |
|
|
uint8_t pin_state[last_pin - first_pin + 1]; |
|
|
uint8_t pin_state[last_pin - first_pin + 1]; |
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) { |
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) { |
|
@ -315,22 +345,19 @@ void GcodeSuite::M43() { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if HAS_RESUME_CONTINUE |
|
|
#if HAS_RESUME_CONTINUE |
|
|
if (!wait_for_user) { |
|
|
if (!wait_for_user) { KEEPALIVE_STATE(IN_HANDLER); break; } |
|
|
KEEPALIVE_STATE(IN_HANDLER); |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
safe_delay(200); |
|
|
safe_delay(200); |
|
|
} |
|
|
} |
|
|
return; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
else { |
|
|
// Report current state of selected pin(s)
|
|
|
// Report current state of selected pin(s)
|
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) { |
|
|
for (uint8_t i = first_pin; i <= last_pin; i++) { |
|
|
pin_t pin = GET_PIN_MAP_PIN(i); |
|
|
pin_t pin = GET_PIN_MAP_PIN(i); |
|
|
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true); |
|
|
if (VALID_PIN(pin)) report_pin_state_extended(pin, ignore_protection, true); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
#endif // PINS_DEBUGGING
|
|
|
#endif // PINS_DEBUGGING
|
|
|