🔧 Refactor endstop state config (#25574)

This commit is contained in:
Scott Lahteine
2023-03-26 04:00:12 -05:00
committed by GitHub
parent cb0a8f2fe2
commit ea5d7e2eee
15 changed files with 445 additions and 624 deletions
+17 -25
View File
@@ -139,24 +139,17 @@ inline void servo_probe_test() {
bool deploy_state = false, stow_state;
#if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN)
constexpr bool probe_hit_state = Z_MIN_ENDSTOP_HIT_STATE;
#define PROBE_TEST_PIN Z_MIN_PIN
constexpr bool probe_inverting = Z_MIN_ENDSTOP_INVERTING;
SERIAL_ECHOLNPGM(". Probe Z_MIN_PIN: ", PROBE_TEST_PIN);
SERIAL_ECHOPGM(". Z_MIN_ENDSTOP_INVERTING: ");
#define _PROBE_PREF "Z_MIN"
#else
constexpr bool probe_hit_state = Z_MIN_PROBE_ENDSTOP_HIT_STATE;
#define PROBE_TEST_PIN Z_MIN_PROBE_PIN
constexpr bool probe_inverting = Z_MIN_PROBE_ENDSTOP_INVERTING;
SERIAL_ECHOLNPGM(". Probe Z_MIN_PROBE_PIN: ", PROBE_TEST_PIN);
SERIAL_ECHOPGM( ". Z_MIN_PROBE_ENDSTOP_INVERTING: ");
#define _PROBE_PREF "Z_MIN_PROBE"
#endif
serialprint_truefalse(probe_inverting);
SERIAL_ECHOLNPGM(". Probe " _PROBE_PREF "_PIN: ", PROBE_TEST_PIN);
serial_ternary(probe_hit_state, F(". " _PROBE_PREF "_ENDSTOP_HIT_STATE: "), F("HIGH"), F("LOW"));
SERIAL_EOL();
SET_INPUT_PULLUP(PROBE_TEST_PIN);
@@ -173,11 +166,11 @@ inline void servo_probe_test() {
SERIAL_ECHOLNPGM(". Check for BLTOUCH");
bltouch._reset();
bltouch._stow();
if (probe_inverting == READ(PROBE_TEST_PIN)) {
if (READ(PROBE_TEST_PIN) != probe_hit_state) {
bltouch._set_SW_mode();
if (probe_inverting != READ(PROBE_TEST_PIN)) {
if (READ(PROBE_TEST_PIN) == probe_hit_state) {
bltouch._deploy();
if (probe_inverting == READ(PROBE_TEST_PIN)) {
if (READ(PROBE_TEST_PIN) != probe_hit_state) {
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
@@ -195,31 +188,30 @@ inline void servo_probe_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 {
LOOP_L_N(i, 4) {
servo[probe_index].move(servo_angles[Z_PROBE_SERVO_NR][0]); // Deploy
safe_delay(500);
deploy_state = READ(PROBE_TEST_PIN);
servo[probe_index].move(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 (probe_hit_state == deploy_state) SERIAL_ECHOLNPGM("WARNING: " _PROBE_PREF "_ENDSTOP_HIT_STATE is probably wrong.");
if (deploy_state != stow_state) {
SERIAL_ECHOLNPGM("= Mechanical Switch detected");
if (deploy_state) {
SERIAL_ECHOLNPGM(" DEPLOYED state: HIGH (logic 1)",
" STOWED (triggered) state: LOW (logic 0)");
SERIAL_ECHOLNPGM(". DEPLOYED state: HIGH (logic 1)\n"
". STOWED (triggered) state: LOW (logic 0)");
}
else {
SERIAL_ECHOLNPGM(" DEPLOYED state: LOW (logic 0)",
" STOWED (triggered) state: HIGH (logic 1)");
SERIAL_ECHOLNPGM(". DEPLOYED state: LOW (logic 0)\n"
". 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'.");
SERIAL_ECHOLNPGM("FAIL: Can't enable BLTOUCH. Check your settings.");
#endif
return;
}