From ec7a4eb69ebea87362e8bbc7bd48c929c0e963d9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 9 Oct 2021 18:41:47 -0500 Subject: [PATCH] clean up and fix --- Marlin/src/feature/bltouch.cpp | 4 ++-- Marlin/src/feature/bltouch.h | 7 +++++-- Marlin/src/gcode/bedlevel/G35.cpp | 3 +-- Marlin/src/gcode/calibrate/G34_M422.cpp | 2 +- Marlin/src/gcode/probe/M401_M402.cpp | 9 ++------- Marlin/src/lcd/menu/menu_bed_corners.cpp | 13 ++++++------- Marlin/src/lcd/menu/menu_configuration.cpp | 2 +- Marlin/src/lcd/menu/menu_tramming.cpp | 2 +- Marlin/src/module/motion.cpp | 6 +++--- Marlin/src/module/probe.cpp | 11 +++++------ Marlin/src/module/settings.cpp | 16 ++++++++-------- 11 files changed, 35 insertions(+), 40 deletions(-) diff --git a/Marlin/src/feature/bltouch.cpp b/Marlin/src/feature/bltouch.cpp index fbe6012bbe..9450ae8ee7 100644 --- a/Marlin/src/feature/bltouch.cpp +++ b/Marlin/src/feature/bltouch.cpp @@ -28,8 +28,8 @@ BLTouch bltouch; -bool BLTouch::last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain -bool BLTouch::bltouch_high_speed; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed +bool BLTouch::last_written_mode, // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain + BLTouch::high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed #include "../module/servo.h" #include "../module/probe.h" diff --git a/Marlin/src/feature/bltouch.h b/Marlin/src/feature/bltouch.h index 7d9a0bb126..f1485826b5 100644 --- a/Marlin/src/feature/bltouch.h +++ b/Marlin/src/feature/bltouch.h @@ -66,9 +66,12 @@ typedef unsigned char BLTCommand; class BLTouch { public: + static void init(const bool set_voltage=false); - static bool last_written_mode; // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain - static bool bltouch_high_speed; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed + static bool last_written_mode, // Initialized by settings.load, 0 = Open Drain; 1 = 5V Drain + high_speed_mode; // Initialized by settings.load, 0 = Low Speed; 1 = High Speed + + const float z_extra_clearance() { return high_speed_mode ? 7 : 0; } // DEPLOY and STOW are wrapped for error handling - these are used by homing and by probing static bool deploy() { return deploy_proc(); } diff --git a/Marlin/src/gcode/bedlevel/G35.cpp b/Marlin/src/gcode/bedlevel/G35.cpp index 08539f8966..8ce6abfb95 100644 --- a/Marlin/src/gcode/bedlevel/G35.cpp +++ b/Marlin/src/gcode/bedlevel/G35.cpp @@ -102,8 +102,7 @@ void GcodeSuite::G35() { // In BLTOUCH HS mode, the probe travels in a deployed state. // Users of G35 might have a badly misaligned bed, so raise Z by the // length of the deployed pin (BLTOUCH stroke < 7mm) - float z_raise_probe = Z_CLEARANCE_BETWEEN_PROBES if(bltouch.bltouch_high_speed) + 7; - do_blocking_move_to_z(z_raise_probe); + do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance())); const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true); if (isnan(z_probed_height)) { diff --git a/Marlin/src/gcode/calibrate/G34_M422.cpp b/Marlin/src/gcode/calibrate/G34_M422.cpp index 5b70dc588e..11f3eac6fa 100644 --- a/Marlin/src/gcode/calibrate/G34_M422.cpp +++ b/Marlin/src/gcode/calibrate/G34_M422.cpp @@ -149,7 +149,7 @@ void GcodeSuite::G34() { // In BLTOUCH HS mode, the probe travels in a deployed state. // Users of G34 might have a badly misaligned bed, so raise Z by the // length of the deployed pin (BLTOUCH stroke < 7mm) - #define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + 7.0f * bltouch.bltouch_high_speed) + #define Z_BASIC_CLEARANCE (Z_CLEARANCE_BETWEEN_PROBES + TERN0(BLTOUCH, bltouch.z_extra_clearance())) // Compute a worst-case clearance height to probe from. After the first // iteration this will be re-calculated based on the actual bed position diff --git a/Marlin/src/gcode/probe/M401_M402.cpp b/Marlin/src/gcode/probe/M401_M402.cpp index 95828c23b1..390c31b2db 100644 --- a/Marlin/src/gcode/probe/M401_M402.cpp +++ b/Marlin/src/gcode/probe/M401_M402.cpp @@ -38,13 +38,8 @@ */ void GcodeSuite::M401() { #if ENABLED(BLTOUCH) - const bool seen_S = parser.seen('S'), - to_enable = (seen_S && parser.value_bool()); - if (seen_S) { - if(to_enable) - bltouch.bltouch_high_speed = true; - else - bltouch.bltouch_high_speed = false; + if (parser.seen('S')) { + bltouch.high_speed_mode = parser.value_bool(); return; } #endif diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 8dd737a805..b1dfe5a4a4 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -221,13 +221,13 @@ static void _lcd_level_bed_corners_get_next_position() { bool _lcd_level_bed_corners_probe(bool verify=false) { if (verify) do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); // do clearance if needed - if(!bltouch.bltouch_high_speed) bltouch.deploy(); // Deploy in LOW SPEED MODE on every probe action + if (!bltouch.high_speed_mode) bltouch.deploy(); // Deploy in LOW SPEED MODE on every probe action do_blocking_move_to_z(last_z - LEVEL_CORNERS_PROBE_TOLERANCE, MMM_TO_MMS(Z_PROBE_FEEDRATE_SLOW)); // Move down to lower tolerance if (TEST(endstops.trigger_state(), Z_MIN_PROBE)) { // check if probe triggered endstops.hit_on_purpose(); set_current_from_steppers_for_axis(Z_AXIS); sync_plan_position(); - if(!bltouch.bltouch_high_speed) bltouch.stow(); // Stow in LOW SPEED MODE on every trigger + if (!bltouch.high_speed_mode) bltouch.stow(); // Stow in LOW SPEED MODE on every trigger // Triggered outside tolerance range? if (ABS(current_position.z - last_z) > LEVEL_CORNERS_PROBE_TOLERANCE) { last_z = current_position.z; // Above tolerance. Set a new Z for subsequent corners. @@ -253,7 +253,7 @@ static void _lcd_level_bed_corners_get_next_position() { } idle(); } - if(!bltouch.bltouch_high_speed) bltouch.stow(); + if (!bltouch.high_speed_mode) bltouch.stow(); ui.goto_screen(_lcd_draw_probing); return (probe_triggered); } @@ -267,14 +267,13 @@ static void _lcd_level_bed_corners_get_next_position() { do { ui.refresh(LCDVIEW_REDRAW_NOW); _lcd_draw_probing(); // update screen with # of good points - float z_raise_probe = Z_CLEARANCE_BETWEEN_PROBES if(bltouch.bltouch_high_speed) + 7; - do_blocking_move_to_z(SUM_TERN(z_raise_probe, current_position.z + LEVEL_CORNERS_Z_HOP, 7)); // clearance + do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP + (bltouch.high_speed_mode ? 7, 0)); // clearance _lcd_level_bed_corners_get_next_position(); // Select next corner coordinates current_position -= probe.offset_xy; // Account for probe offsets do_blocking_move_to_xy(current_position); // Goto corner - if(bltouch.bltouch_high_speed) bltouch.deploy(); // Deploy in HIGH SPEED MODE + if (bltouch.high_speed_mode) bltouch.deploy(); // Deploy in HIGH SPEED MODE if (!_lcd_level_bed_corners_probe()) { // Probe down to tolerance if (_lcd_level_bed_corners_raise()) { // Prompt user to raise bed if needed #if ENABLED(LEVEL_CORNERS_VERIFY_RAISED) // Verify @@ -295,7 +294,7 @@ static void _lcd_level_bed_corners_get_next_position() { } while (good_points < nr_edge_points); // loop until all points within tolerance - if (bltouch.bltouch_high_speed) + if (bltouch.high_speed_mode) // In HIGH SPEED MODE do clearance and stow at the very end do_blocking_move_to_z(current_position.z + LEVEL_CORNERS_Z_HOP); bltouch.stow(); diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index 5865d4898c..6006f86891 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -235,7 +235,7 @@ void menu_advanced_settings(); ACTION_ITEM(MSG_BLTOUCH_DEPLOY, bltouch._deploy); ACTION_ITEM(MSG_BLTOUCH_STOW, bltouch._stow); ACTION_ITEM(MSG_BLTOUCH_SW_MODE, bltouch._set_SW_mode); - EDIT_ITEM(bool, MSG_BLTOUCH_SPEED_MODE, &bltouch.bltouch_high_speed); + EDIT_ITEM(bool, MSG_BLTOUCH_SPEED_MODE, &bltouch.high_speed_mode); #if ENABLED(BLTOUCH_LCD_VOLTAGE_MENU) CONFIRM_ITEM(MSG_BLTOUCH_5V_MODE, MSG_BLTOUCH_5V_MODE, MSG_BUTTON_CANCEL, bltouch._set_5V_mode, nullptr, GET_TEXT(MSG_BLTOUCH_MODE_CHANGE)); CONFIRM_ITEM(MSG_BLTOUCH_OD_MODE, MSG_BLTOUCH_OD_MODE, MSG_BUTTON_CANCEL, bltouch._set_OD_mode, nullptr, GET_TEXT(MSG_BLTOUCH_MODE_CHANGE)); diff --git a/Marlin/src/lcd/menu/menu_tramming.cpp b/Marlin/src/lcd/menu/menu_tramming.cpp index 5109a699ed..ce9e50b3e7 100644 --- a/Marlin/src/lcd/menu/menu_tramming.cpp +++ b/Marlin/src/lcd/menu/menu_tramming.cpp @@ -52,7 +52,7 @@ static bool probe_single_point() { do_blocking_move_to_z(TERN(BLTOUCH, Z_CLEARANCE_DEPLOY_PROBE, Z_CLEARANCE_BETWEEN_PROBES)); // Stow after each point with BLTouch "HIGH SPEED" mode for push-pin safety - const float z_probed_height = probe.probe_at_point(tramming_points[tram_index], if(bltouch.bltouch_high_speed) PROBE_PT_STOW else PROBE_PT_RAISE), 0, true); + const float z_probed_height = probe.probe_at_point(tramming_points[tram_index], bltouch.high_speed_mode ? PROBE_PT_STOW : PROBE_PT_RAISE, 0, true); z_measured[tram_index] = z_probed_height; if (reference_index < 0) reference_index = tram_index; move_to_tramming_wait_pos(); diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 091facc94c..f05e31a498 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -1800,7 +1800,7 @@ void prepare_line_to_destination() { do_homing_move(axis, move_length, 0.0, !use_probe_bump); #if ENABLED(HOMING_Z_WITH_PROBE, BLTOUCH) - if (axis == Z_AXIS && !bltouch.bltouch_high_speed) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) + if (axis == Z_AXIS && !bltouch.high_speed_mode) bltouch.stow(); // Intermediate STOW (in LOW SPEED MODE) #endif // If a second homing move is configured... @@ -1834,8 +1834,8 @@ void prepare_line_to_destination() { #endif #if BOTH(HOMING_Z_WITH_PROBE, BLTOUCH) - if(!bltouch.bltouch_high_speed) - if (axis == Z_AXIS && bltouch.deploy()) return; // Intermediate DEPLOY (in LOW SPEED MODE) + if (axis == Z_AXIS && !bltouch.high_speed_mode && bltouch.deploy()) + return; // Intermediate DEPLOY (in LOW SPEED MODE) #endif // Slow move towards endstop until triggered diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp index f2f5eee520..02903419aa 100644 --- a/Marlin/src/module/probe.cpp +++ b/Marlin/src/module/probe.cpp @@ -488,8 +488,8 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) { thermalManager.wait_for_hotend_heating(active_extruder); #endif #if ENABLED(BLTOUCH) - if(!bltouch.bltouch_high_speed) - if (bltouch.deploy()) return true; // Deploy in LOW SPEED MODE on every probe action + if (!bltouch.high_speed_mode && bltouch.deploy()) + return true; // Deploy in LOW SPEED MODE on every probe action #endif // Disable stealthChop if used. Enable diag1 pin on driver. @@ -531,9 +531,8 @@ bool Probe::probe_down_to_z(const_float_t z, const_feedRate_t fr_mm_s) { set_homing_current(false); #endif #if ENABLED(BLTOUCH) - if(!bltouch.bltouch_high_speed) - if (probe_triggered && bltouch.stow()) // Stow in LOW SPEED MODE on every trigger - return true; + if (!bltouch.high_speed_mode && probe_triggered && bltouch.stow()) + return true; // Stow in LOW SPEED MODE on every trigger #endif // Clear endstop flags endstops.hit_on_purpose(); @@ -764,7 +763,7 @@ float Probe::probe_at_point(const_float_t rx, const_float_t ry, const ProbePtRai } #if ENABLED(BLTOUCH) - if (bltouch.triggered() && bltouch.bltouch_high_speed) bltouch._reset(); + if (bltouch.triggered() && bltouch.high_speed_mode) bltouch._reset(); #endif // On delta keep Z below clip height or do_blocking_move_to will abort diff --git a/Marlin/src/module/settings.cpp b/Marlin/src/module/settings.cpp index 80b9736478..56b071acd2 100644 --- a/Marlin/src/module/settings.cpp +++ b/Marlin/src/module/settings.cpp @@ -277,7 +277,7 @@ typedef struct SettingsDataStruct { // BLTOUCH // bool bltouch_last_written_mode; - bool bltouch_high_speed; + bool high_speed_mode; // // Kinematic Settings @@ -863,9 +863,9 @@ void MarlinSettings::postprocess() { const bool bltouch_last_written_mode = TERN(BLTOUCH, bltouch.last_written_mode, false); EEPROM_WRITE(bltouch_last_written_mode); - _FIELD_TEST(bltouch_high_speed); - const bool bltouch_high_speed = TERN(BLTOUCH, bltouch.bltouch_high_speed, false); - EEPROM_WRITE(bltouch_high_speed); + _FIELD_TEST(high_speed_mode); + const bool high_speed_mode = TERN(BLTOUCH, bltouch.high_speed_mode, false); + EEPROM_WRITE(high_speed_mode); } // @@ -1738,11 +1738,11 @@ void MarlinSettings::postprocess() { #endif EEPROM_READ(bltouch_last_written_mode); - _FIELD_TEST(bltouch_high_speed); + _FIELD_TEST(high_speed_mode); #if ENABLED(BLTOUCH) - const bool &bltouch_high_speed = bltouch.bltouch_high_speed; + const bool &high_speed_mode = bltouch.high_speed_mode; #else - bool bltouch_high_speed; + bool high_speed_mode; #endif EEPROM_READ(bltouch_last_written_mode); } @@ -2744,7 +2744,7 @@ void MarlinSettings::reset() { // // BLTouch // - TERN_(BLTOUCH_HS_MODE, bltouch.bltouch_high_speed = true); + TERN_(BLTOUCH_HS_MODE, bltouch.high_speed_mode = true); // // Kinematic settings //