Skip to content

Commit

Permalink
clean up and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Oct 9, 2021
1 parent 4f62ae9 commit 5e8db0a
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 40 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/feature/bltouch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions Marlin/src/feature/bltouch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_basic_clearance() return { Z_CLEARANCE_BETWEEN_PROBES + (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(); }
Expand Down
3 changes: 1 addition & 2 deletions Marlin/src/gcode/bedlevel/G35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(TERN(BLTOUCH, bltouch.z_basic_clearance(), Z_CLEARANCE_BETWEEN_PROBES));
const float z_probed_height = probe.probe_at_point(tramming_points[i], PROBE_PT_RAISE, 0, true);

if (isnan(z_probed_height)) {
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 TERN(BLTOUCH, bltouch.z_basic_clearance(), Z_CLEARANCE_BETWEEN_PROBES)

// Compute a worst-case clearance height to probe from. After the first
// iteration this will be re-calculated based on the actual bed position
Expand Down
9 changes: 2 additions & 7 deletions Marlin/src/gcode/probe/M401_M402.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions Marlin/src/lcd/menu/menu_bed_corners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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(SUM_TERN(bltouch.z_basic_clearance(), current_position.z + LEVEL_CORNERS_Z_HOP, 7)); // 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
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_tramming.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/module/motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions Marlin/src/module/probe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ typedef struct SettingsDataStruct {
// BLTOUCH
//
bool bltouch_last_written_mode;
bool bltouch_high_speed;
bool high_speed_mode;

//
// Kinematic Settings
Expand Down Expand Up @@ -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);
}

//
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
//
Expand Down

0 comments on commit 5e8db0a

Please sign in to comment.