From 13523cbf29f46b9e5fc0b50668c982449304f5b3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 20 Sep 2016 13:56:23 -0500 Subject: [PATCH] Fix and extend BLTouch support --- Marlin/Conditionals_LCD.h | 15 +++++++++++++-- Marlin/Marlin_main.cpp | 2 +- Marlin/enum.h | 9 --------- Marlin/language_en.h | 7 +++++-- Marlin/ultralcd.cpp | 16 ++++++++++++---- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/Marlin/Conditionals_LCD.h b/Marlin/Conditionals_LCD.h index 21bfdd4ee..a5c5dc4b7 100644 --- a/Marlin/Conditionals_LCD.h +++ b/Marlin/Conditionals_LCD.h @@ -318,6 +318,7 @@ /** * The BLTouch Probe emulates a servo probe + * and uses "special" angles for its state. */ #if ENABLED(BLTOUCH) #ifndef Z_ENDSTOP_SERVO_NR @@ -326,12 +327,22 @@ #ifndef NUM_SERVOS #define NUM_SERVOS (Z_ENDSTOP_SERVO_NR + 1) #endif - #undef Z_SERVO_ANGLES - #define Z_SERVO_ANGLES {10,90} // For BLTouch 10=deploy, 90=retract #undef DEACTIVATE_SERVOS_AFTER_MOVE + #undef Z_SERVO_ANGLES + #define Z_SERVO_ANGLES { BLTOUCH_DEPLOY, BLTOUCH_STOW } + + #define BLTOUCH_DEPLOY 10 + #define BLTOUCH_STOW 90 + #define BLTOUCH_SELFTEST 120 + #define BLTOUCH_RELEASE 160 + #define _TEST_BLTOUCH(P) (READ(P##_PIN) != P##_ENDSTOP_INVERTING) + #if ENABLED(Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN) #undef Z_MIN_ENDSTOP_INVERTING #define Z_MIN_ENDSTOP_INVERTING false + #define TEST_BLTOUCH() _TEST_BLTOUCH(Z_MIN) + #else + #define TEST_BLTOUCH() _TEST_BLTOUCH(Z_MIN_PROBE) #endif #endif diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 63dfcf76b..4bc63502d 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1883,7 +1883,7 @@ static void clean_up_after_endstop_or_probe_move() { // Check BLTOUCH probe status for an error #if ENABLED(BLTOUCH) - if (servo[Z_ENDSTOP_SERVO_NR].read() == BLTouchState_Error) { stop(); return true; } + if (TEST_BLTOUCH()) { stop(); return true; } #endif #if ENABLED(Z_PROBE_SLED) diff --git a/Marlin/enum.h b/Marlin/enum.h index 34e02234a..18db5a6f5 100644 --- a/Marlin/enum.h +++ b/Marlin/enum.h @@ -124,15 +124,6 @@ enum TempState { }; #endif -#if ENABLED(BLTOUCH) - enum BLTouchState { - BLTouchState_Deploy = 10, - BLTouchState_Stow = 90, - BLTouchState_Selftest = 120, - BLTouchState_Error = 160 - }; -#endif - #if ENABLED(FILAMENT_CHANGE_FEATURE) enum FilamentChangeMenuResponse { FILAMENT_CHANGE_RESPONSE_WAIT_FOR, diff --git a/Marlin/language_en.h b/Marlin/language_en.h index a84d1acfd..c5ee0849b 100644 --- a/Marlin/language_en.h +++ b/Marlin/language_en.h @@ -366,8 +366,11 @@ #ifndef MSG_ZPROBE_OUT #define MSG_ZPROBE_OUT "Z probe out. bed" #endif -#ifndef MSG_RESET_BLTOUCH - #define MSG_RESET_BLTOUCH "Reset BLTouch" +#ifndef MSG_BLTOUCH_RESET + #define MSG_BLTOUCH_SELFTEST "BLTouch Self-Test" +#endif +#ifndef MSG_BLTOUCH_RESET + #define MSG_BLTOUCH_RESET "Reset BLTouch" #endif #ifndef MSG_HOME #define MSG_HOME "Home" // Used as MSG_HOME " " MSG_X MSG_Y MSG_Z " " MSG_FIRST diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 5240c30fa..b4214de26 100755 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -31,8 +31,7 @@ #include "utility.h" #if ENABLED(BLTOUCH) - #include "servo.h" - extern Servo servo[NUM_SERVOS]; + #include "endstops.h" #endif #if ENABLED(PRINTCOUNTER) @@ -593,8 +592,8 @@ void kill_screen(const char* lcd_msg) { MENU_ITEM(back, MSG_WATCH); #if ENABLED(BLTOUCH) - if (servo[Z_ENDSTOP_SERVO_NR].read() == BLTouchState_Error) - MENU_ITEM(gcode, MSG_RESET_BLTOUCH, "M280 S90 P" STRINGIFY(Z_ENDSTOP_SERVO_NR)); + if (!endstops.z_probe_enabled && TEST_BLTOUCH()) + MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET))); #endif if (planner.movesplanned() || IS_SD_PRINTING) { @@ -1250,6 +1249,15 @@ void kill_screen(const char* lcd_msg) { // MENU_ITEM(function, MSG_COOLDOWN, lcd_cooldown); + // + // BLTouch Self-Test and Reset + // + #if ENABLED(BLTOUCH) + MENU_ITEM(gcode, MSG_BLTOUCH_TEST, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_SELFTEST))); + if (!endstops.z_probe_enabled && TEST_BLTOUCH()) + MENU_ITEM(gcode, MSG_BLTOUCH_RESET, PSTR("M280 P" STRINGIFY(Z_ENDSTOP_SERVO_NR) " S" STRINGIFY(BLTOUCH_RESET))); + #endif + // // Switch power on/off //