|
|
|
@ -35,15 +35,32 @@ void stop();
|
|
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
|
|
|
|
|
#include "../core/debug_out.h"
|
|
|
|
|
|
|
|
|
|
void BLTouch::command(const BLTCommand cmd) {
|
|
|
|
|
//SERIAL_ECHOLNPAIR("BLTouch Command :", cmd);
|
|
|
|
|
bool BLTouch::command(const BLTCommand cmd, const millis_t &ms) {
|
|
|
|
|
if (DEBUGGING(LEVELING)) SERIAL_ECHOLNPAIR("BLTouch Command :", cmd);
|
|
|
|
|
MOVE_SERVO(Z_PROBE_SERVO_NR, cmd);
|
|
|
|
|
safe_delay(BLTOUCH_DELAY);
|
|
|
|
|
safe_delay(MAX(ms, BLTOUCH_DELAY)); // BLTOUCH_DELAY is also the *minimum* delay
|
|
|
|
|
return triggered();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BLTouch::init() {
|
|
|
|
|
reset(); // Clear all BLTouch error conditions
|
|
|
|
|
stow();
|
|
|
|
|
// This is called by marlin.cpp on initialization
|
|
|
|
|
// SET_5V_MODE (if enabled). OD_MODE is the default on power on.
|
|
|
|
|
// This mode will stay active until manual SET_OD_MODE or power cycle
|
|
|
|
|
#if ENABLED(BLTOUCH_FORCE_5V_MODE)
|
|
|
|
|
_set_5V_mode(); // Set 5V mode if explicitely demanded (V3 upwards)
|
|
|
|
|
#endif
|
|
|
|
|
clear();
|
|
|
|
|
// There really should be no alarm outstanding now, and no triggered condition. But if there is,
|
|
|
|
|
// there is no need to worry people here on init right at the start of the printer.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BLTouch::clear() {
|
|
|
|
|
_reset(); // RESET or RESET_SW will clear an alarm condition but...
|
|
|
|
|
// ...it will not clear a triggered condition in SW mode when the pin is currently up
|
|
|
|
|
// ANTClabs <-- CODE ERROR
|
|
|
|
|
_stow(); // STOW will pull up the pin and clear any triggered condition unless it fails, don't care
|
|
|
|
|
_deploy(); // DEPLOY to test the probe. Could fail, don't care
|
|
|
|
|
_stow(); // STOW to be ready for meaningful work. Could fail, don't care
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BLTouch::triggered() {
|
|
|
|
@ -56,41 +73,92 @@ bool BLTouch::triggered() {
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BLTouch::set_deployed(const bool in_deploy) {
|
|
|
|
|
if (in_deploy && triggered()) { // If BLTouch says it's triggered
|
|
|
|
|
reset(); // try to reset it.
|
|
|
|
|
_deploy(); _stow(); // Deploy and stow to clear the "triggered" condition.
|
|
|
|
|
safe_delay(1500); // Wait for internal self-test to complete.
|
|
|
|
|
// (Measured completion time was 0.65 seconds
|
|
|
|
|
// after reset, deploy, and stow sequence)
|
|
|
|
|
if (triggered()) { // If it still claims to be triggered...
|
|
|
|
|
SERIAL_ERROR_MSG(MSG_STOP_BLTOUCH);
|
|
|
|
|
stop(); // punt!
|
|
|
|
|
return true;
|
|
|
|
|
bool BLTouch::deploy_proc() {
|
|
|
|
|
// Do a DEPLOY
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch DEPLOY requested");
|
|
|
|
|
|
|
|
|
|
// Attempt to DEPLOY, wait for DEPLOY_DELAY or ALARM
|
|
|
|
|
if (_deploy_query_alarm()) {
|
|
|
|
|
// The deploy might have failed or the probe is already triggered (nozzle too low?)
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch ALARM or TRIGGER after DEPLOY, recovering");
|
|
|
|
|
|
|
|
|
|
clear(); // Get the probe into start condition
|
|
|
|
|
|
|
|
|
|
// Last attempt to DEPLOY
|
|
|
|
|
if (_deploy_query_alarm()) {
|
|
|
|
|
// The deploy might have failed or the probe is actually triggered (nozzle too low?) again
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch Recovery Failed");
|
|
|
|
|
|
|
|
|
|
SERIAL_ERROR_MSG(MSG_STOP_BLTOUCH); // Tell the user something is wrong, needs action
|
|
|
|
|
stop(); // but it's not too bad, no need to kill, allow restart
|
|
|
|
|
|
|
|
|
|
return true; // Tell our caller we goofed in case he cares to know
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if ENABLED(BLTOUCH_V3)
|
|
|
|
|
#if EITHER(BLTOUCH_FORCE_5V_MODE, ENDSTOPPULLUPS) \
|
|
|
|
|
|| ALL(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN, ENDSTOPPULLUP_ZMIN) \
|
|
|
|
|
|| (USES_Z_MIN_PROBE_ENDSTOP && ENABLED(ENDSTOPPULLUP_ZMIN_PROBE))
|
|
|
|
|
set_5V_mode(); // Assume 5V DC logic level if endstop pullup resistors are enabled
|
|
|
|
|
#elif true || ENABLED(BLTOUCH_FORCE_OPEN_DRAIN_MODE)
|
|
|
|
|
set_OD_mode();
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
// Now the probe is ready to issue a 10ms pulse when the pin goes up.
|
|
|
|
|
// The trigger STOW (see motion.cpp for example) will pull up the probes pin as soon as the pulse
|
|
|
|
|
// is registered.
|
|
|
|
|
|
|
|
|
|
if (in_deploy) {
|
|
|
|
|
_deploy();
|
|
|
|
|
#if ENABLED(BLTOUCH_V3)
|
|
|
|
|
set_SW_mode();
|
|
|
|
|
#endif
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("bltouch.deploy_proc() end");
|
|
|
|
|
|
|
|
|
|
return false; // report success to caller
|
|
|
|
|
}
|
|
|
|
|
else _stow();
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("bltouch.set_deployed(", in_deploy, ")");
|
|
|
|
|
bool BLTouch::stow_proc() {
|
|
|
|
|
// Do a STOW
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch STOW requested");
|
|
|
|
|
|
|
|
|
|
// A STOW will clear a triggered condition in the probe (10ms pulse).
|
|
|
|
|
// At the moment that we come in here, we might (pulse) or will (SW mode) see the trigger on the pin.
|
|
|
|
|
// So even though we know a STOW will be ignored if an ALARM condition is active, we will STOW.
|
|
|
|
|
// Note: If the probe is deployed AND in an ALARM condition, this STOW will not pull up the pin
|
|
|
|
|
// and the ALARM condition will still be there. --> ANTClabs should change this behaviour maybe
|
|
|
|
|
|
|
|
|
|
// Attempt to STOW, wait for STOW_DELAY or ALARM
|
|
|
|
|
if (_stow_query_alarm()) {
|
|
|
|
|
// The stow might have failed
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch ALARM or TRIGGER after STOW, recovering");
|
|
|
|
|
|
|
|
|
|
_reset(); // This RESET will then also pull up the pin. If it doesn't
|
|
|
|
|
// work and the pin is still down, there will no longer be
|
|
|
|
|
// an ALARM condition though.
|
|
|
|
|
// But one more STOW will catch that
|
|
|
|
|
// Last attempt to STOW
|
|
|
|
|
if (_stow_query_alarm()) { // so if there is now STILL an ALARM condition:
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch Recovery Failed");
|
|
|
|
|
|
|
|
|
|
SERIAL_ERROR_MSG(MSG_STOP_BLTOUCH); // Tell the user something is wrong, needs action
|
|
|
|
|
stop(); // but it's not too bad, no need to kill, allow restart
|
|
|
|
|
|
|
|
|
|
return true; // Tell our caller we goofed in case he cares to know
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("bltouch.stow_proc() end");
|
|
|
|
|
|
|
|
|
|
return false; // report success to caller
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BLTouch::status_proc() {
|
|
|
|
|
/**
|
|
|
|
|
* Return a TRUE for "YES, it is DEPLOYED"
|
|
|
|
|
* This function will ensure switch state is reset after execution
|
|
|
|
|
* This may change pin position in some scenarios, specifically
|
|
|
|
|
* if the pin has been triggered but not yet stowed.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLN("BLTouch STATUS requested");
|
|
|
|
|
|
|
|
|
|
_set_SW_mode();
|
|
|
|
|
const bool tr = triggered(); // If triggered in SW mode, the pin is up, it is STOWED
|
|
|
|
|
|
|
|
|
|
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("BLTouch is ", (int)tr);
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
_reset(); // turn off the SW Mode
|
|
|
|
|
if (tr) _stow(); else _deploy(); // and reset any triggered signal, restore state
|
|
|
|
|
return !tr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif // BLTOUCH
|
|
|
|
|