BLTouch V3.1 changes (#14104)

This commit is contained in:
InsanityAutomation
2019-05-25 22:56:47 -04:00
committed by Scott Lahteine
parent 14fe41f6b2
commit 49e83dd7c8
103 changed files with 6059 additions and 622 deletions

View File

@ -28,6 +28,8 @@
BLTouch bltouch;
bool BLTouch::last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
#include "../module/servo.h"
void stop();
@ -38,21 +40,53 @@ void stop();
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(MAX(ms, BLTOUCH_DELAY)); // BLTOUCH_DELAY is also the *minimum* delay
safe_delay(MAX(ms, (uint32_t)BLTOUCH_DELAY)); // BLTOUCH_DELAY is also the *minimum* delay
return triggered();
}
void BLTouch::init() {
// 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)
// Init the class and device. Call from setup().
void BLTouch::init(const bool set_voltage/*=false*/) {
// Voltage Setting (if enabled). At every Marlin initialization:
// BLTOUCH < V3.0 and clones: This will be ignored by the probe
// BLTOUCH V3.0: SET_5V_MODE or SET_OD_MODE (if enabled).
// OD_MODE is the default on power on, but setting it does not hurt
// This mode will stay active until manual SET_OD_MODE or power cycle
// BLTOUCH V3.1: SET_5V_MODE or SET_OD_MODE (if enabled).
// At power on, the probe will default to the eeprom settings configured by the user
#if ENABLED(BLTOUCH_FORCE_MODE_SET)
constexpr bool should_set = true;
#else
if (DEBUGGING(LEVELING)) {
DEBUG_ECHOLNPAIR("last_written_mode - ", (int)last_written_mode);
DEBUG_ECHOLNPGM("config mode - "
#if ENABLED(BLTOUCH_SET_5V_MODE)
"BLTOUCH_SET_5V_MODE"
#else
"OD"
#endif
);
}
const bool should_set = last_written_mode != (false
#if ENABLED(BLTOUCH_SET_5V_MODE)
|| true
#endif
);
#endif
if (should_set && set_voltage)
mode_conv_proc((false
#if ENABLED(BLTOUCH_SET_5V_MODE)
|| true
#endif
));
_reset();
_stow();
// 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() {
@ -97,6 +131,11 @@ bool BLTouch::deploy_proc() {
}
}
// One of the recommended ANTClabs ways to probe, using SW MODE
#if ENABLED(BLTOUCH_FORCE_SW_MODE)
_set_SW_mode();
#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.
@ -159,4 +198,19 @@ bool BLTouch::status_proc() {
return !tr;
}
void BLTouch::mode_conv_proc(const bool M5V) {
/**
* BLTOUCH pre V3.0 and clones: No reaction at all to this sequence apart from a DEPLOY -> STOW
* BLTOUCH V3.0: This will set the mode (twice) and sadly, a STOW is needed at the end, because of the deploy
* BLTOUCH V3.1: This will set the mode and store it in the eeprom. The STOW is not needed but does not hurt
*/
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("BLTouch Set Mode - ", (int)M5V);
_deploy();
if (M5V) _set_5V_mode(); else _set_OD_mode();
_mode_store();
if (M5V) _set_5V_mode(); else _set_OD_mode();
_stow();
last_written_mode = M5V;
}
#endif // BLTOUCH

View File

@ -67,8 +67,8 @@ typedef unsigned char BLTCommand;
class BLTouch {
public:
static bool triggered(); // used by menu_advanced.cpp
static void init(); // used by main.cpp
static void init(const bool set_voltage=false);
static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain
// DEPLOY and STOW are wrapped for error handling - these are used by homing and by probing
FORCE_INLINE static bool deploy() { return deploy_proc(); }
@ -90,15 +90,20 @@ public:
FORCE_INLINE static void _deploy() { command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
FORCE_INLINE static void _stow() { command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
FORCE_INLINE static void mode_conv_5V() { mode_conv_proc(true); }
FORCE_INLINE static void mode_conv_OD() { mode_conv_proc(false); }
private:
FORCE_INLINE static bool _deploy_query_alarm() { return command(BLTOUCH_DEPLOY, BLTOUCH_DEPLOY_DELAY); }
FORCE_INLINE static bool _stow_query_alarm() { return command(BLTOUCH_STOW, BLTOUCH_STOW_DELAY); }
static void clear();
static bool command(const BLTCommand cmd, const millis_t &ms);
static bool triggered();
static bool deploy_proc();
static bool stow_proc();
static bool status_proc();
static void mode_conv_proc(const bool M5V);
};
// Deploy/stow angles for use by servo.cpp / servo.h