From 9641bae325a47e73470aa5df595ab359419e8243 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 2 Jun 2018 16:50:22 -0500 Subject: [PATCH] Cleanup for dual endstops homing --- Marlin/Marlin_main.cpp | 69 ++++++++++++++++++++++++------------------ Marlin/endstops.cpp | 2 +- Marlin/stepper.cpp | 6 ++-- Marlin/stepper.h | 10 +++--- 4 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 735fdb991a2..dd44cc073d8 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1372,7 +1372,7 @@ bool get_target_extruder_from_command(const uint16_t code) { #endif #if ENABLED(DELTA) - switch(axis) { + switch (axis) { #if HAS_SOFTWARE_ENDSTOPS case X_AXIS: case Y_AXIS: @@ -2937,9 +2937,14 @@ static void do_homing_move(const AxisEnum axis, const float distance, const floa if (DEBUGGING(LEVELING)) { SERIAL_ECHOPAIR(">>> do_homing_move(", axis_codes[axis]); SERIAL_ECHOPAIR(", ", distance); - SERIAL_ECHOPAIR(", ", fr_mm_s); - SERIAL_ECHOPAIR(" [", fr_mm_s ? fr_mm_s : homing_feedrate(axis)); - SERIAL_ECHOLNPGM("])"); + SERIAL_ECHOPGM(", "); + if (fr_mm_s) + SERIAL_ECHO(fr_mm_s); + else { + SERIAL_ECHOPAIR("[", homing_feedrate(axis)); + SERIAL_CHAR(']'); + } + SERIAL_ECHOLNPGM(")"); } #endif @@ -3058,11 +3063,12 @@ static void homeaxis(const AxisEnum axis) { } #endif - const int axis_home_dir = + const int axis_home_dir = ( #if ENABLED(DUAL_X_CARRIAGE) - (axis == X_AXIS) ? x_home_dir(active_extruder) : + axis == X_AXIS ? x_home_dir(active_extruder) : #endif - home_dir(axis); + home_dir(axis) + ); // Homing Z towards the bed? Deploy the Z probe or endstop. #if HOMING_Z_WITH_PROBE @@ -3070,14 +3076,20 @@ static void homeaxis(const AxisEnum axis) { #endif // Set flags for X, Y, Z motor locking - #if ENABLED(X_DUAL_ENDSTOPS) - if (axis == X_AXIS) stepper.set_homing_flag_x(true); - #endif - #if ENABLED(Y_DUAL_ENDSTOPS) - if (axis == Y_AXIS) stepper.set_homing_flag_y(true); - #endif - #if ENABLED(Z_DUAL_ENDSTOPS) - if (axis == Z_AXIS) stepper.set_homing_flag_z(true); + #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) + switch (axis) { + #if ENABLED(X_DUAL_ENDSTOPS) + case X_AXIS: + #endif + #if ENABLED(Y_DUAL_ENDSTOPS) + case Y_AXIS: + #endif + #if ENABLED(Z_DUAL_ENDSTOPS) + case Z_AXIS: + #endif + stepper.set_homing_dual_axis(true); + default: break; + } #endif // Fast move towards endstop until triggered @@ -3120,34 +3132,32 @@ static void homeaxis(const AxisEnum axis) { const bool pos_dir = axis_home_dir > 0; #if ENABLED(X_DUAL_ENDSTOPS) if (axis == X_AXIS) { - const bool lock_x1 = pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0); const float adj = ABS(endstops.x_endstop_adj); - if (lock_x1) stepper.set_x_lock(true); else stepper.set_x2_lock(true); + if (pos_dir ? (endstops.x_endstop_adj > 0) : (endstops.x_endstop_adj < 0)) stepper.set_x_lock(true); else stepper.set_x2_lock(true); do_homing_move(axis, pos_dir ? -adj : adj); - if (lock_x1) stepper.set_x_lock(false); else stepper.set_x2_lock(false); - stepper.set_homing_flag_x(false); + stepper.set_x_lock(false); + stepper.set_x2_lock(false); } #endif #if ENABLED(Y_DUAL_ENDSTOPS) if (axis == Y_AXIS) { - const bool lock_y1 = pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0); const float adj = ABS(endstops.y_endstop_adj); - if (lock_y1) stepper.set_y_lock(true); else stepper.set_y2_lock(true); + if (pos_dir ? (endstops.y_endstop_adj > 0) : (endstops.y_endstop_adj < 0)) stepper.set_y_lock(true); else stepper.set_y2_lock(true); do_homing_move(axis, pos_dir ? -adj : adj); - if (lock_y1) stepper.set_y_lock(false); else stepper.set_y2_lock(false); - stepper.set_homing_flag_y(false); + stepper.set_y_lock(false); + stepper.set_y2_lock(false); } #endif #if ENABLED(Z_DUAL_ENDSTOPS) if (axis == Z_AXIS) { - const bool lock_z1 = pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0); const float adj = ABS(endstops.z_endstop_adj); - if (lock_z1) stepper.set_z_lock(true); else stepper.set_z2_lock(true); + if (pos_dir ? (endstops.z_endstop_adj > 0) : (endstops.z_endstop_adj < 0)) stepper.set_z_lock(true); else stepper.set_z2_lock(true); do_homing_move(axis, pos_dir ? -adj : adj); - if (lock_z1) stepper.set_z_lock(false); else stepper.set_z2_lock(false); - stepper.set_homing_flag_z(false); + stepper.set_z_lock(false); + stepper.set_z2_lock(false); } #endif + stepper.set_homing_dual_axis(false); #endif #if IS_SCARA @@ -3191,8 +3201,7 @@ static void homeaxis(const AxisEnum axis) { // Clear retracted status if homing the Z axis #if ENABLED(FWRETRACT) - if (axis == Z_AXIS) - fwretract.hop_amount = 0.0; + if (axis == Z_AXIS) fwretract.hop_amount = 0.0; #endif #if ENABLED(DEBUG_LEVELING_FEATURE) @@ -4442,7 +4451,7 @@ void home_all_axes() { gcode_G28(true); } reset_bed_level(); break; - } // switch(state) + } // switch (state) if (state == MeshNext) { SERIAL_PROTOCOLPAIR("MBL G29 point ", MIN(mbl_probe_index, GRID_MAX_POINTS)); diff --git a/Marlin/endstops.cpp b/Marlin/endstops.cpp index 31cab777fc6..06846f9b5d9 100644 --- a/Marlin/endstops.cpp +++ b/Marlin/endstops.cpp @@ -562,7 +562,7 @@ void Endstops::update() { if (dual_hit) { \ _ENDSTOP_HIT(AXIS1, MINMAX); \ /* if not performing home or if both endstops were trigged during homing... */ \ - if (!stepper.performing_homing || dual_hit == 0x3) \ + if (!stepper.homing_dual_axis || dual_hit == 0x3) \ planner.endstop_triggered(_AXIS(AXIS1)); \ } \ }while(0) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index ffa081f4673..7a201c3f9d5 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -76,7 +76,7 @@ Stepper stepper; // Singleton block_t* Stepper::current_block = NULL; // A pointer to the block currently being traced #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) - bool Stepper::performing_homing = false; + bool Stepper::homing_dual_axis = false; #endif #if HAS_MOTOR_CURRENT_PWM @@ -153,7 +153,7 @@ bool Stepper::all_steps_done = false; uint32_t Stepper::acceleration_time, Stepper::deceleration_time; volatile int32_t Stepper::count_position[NUM_AXIS] = { 0 }; -volatile signed char Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; +int8_t Stepper::count_direction[NUM_AXIS] = { 1, 1, 1, 1 }; #if ENABLED(MIXING_EXTRUDER) int32_t Stepper::counter_m[MIXING_STEPPERS]; @@ -170,7 +170,7 @@ volatile int32_t Stepper::endstops_trigsteps[XYZ]; #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) #define DUAL_ENDSTOP_APPLY_STEP(A,V) \ - if (performing_homing) { \ + if (homing_dual_axis) { \ if (A##_HOME_DIR < 0) { \ if (!(TEST(endstops.state(), A##_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##_motor) A##_STEP_WRITE(V); \ if (!(TEST(endstops.state(), A##2_MIN) && count_direction[_AXIS(A)] < 0) && !locked_##A##2_motor) A##2_STEP_WRITE(V); \ diff --git a/Marlin/stepper.h b/Marlin/stepper.h index dc8213691af..8d31429f512 100644 --- a/Marlin/stepper.h +++ b/Marlin/stepper.h @@ -86,7 +86,7 @@ class Stepper { static block_t* current_block; // A pointer to the block currently being traced #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) - static bool performing_homing; + static bool homing_dual_axis; #endif #if HAS_MOTOR_CURRENT_PWM @@ -164,7 +164,7 @@ class Stepper { // // Current direction of stepper motors (+1 or -1) // - static volatile signed char count_direction[NUM_AXIS]; + static int8_t count_direction[NUM_AXIS]; // // Mixing extruder mix counters @@ -241,18 +241,18 @@ class Stepper { static void microstep_readings(); #endif + #if ENABLED(X_DUAL_ENDSTOPS) || ENABLED(Y_DUAL_ENDSTOPS) || ENABLED(Z_DUAL_ENDSTOPS) + FORCE_INLINE static void set_homing_dual_axis(const bool state) { homing_dual_axis = state; } + #endif #if ENABLED(X_DUAL_ENDSTOPS) - FORCE_INLINE static void set_homing_flag_x(const bool state) { performing_homing = state; } FORCE_INLINE static void set_x_lock(const bool state) { locked_X_motor = state; } FORCE_INLINE static void set_x2_lock(const bool state) { locked_X2_motor = state; } #endif #if ENABLED(Y_DUAL_ENDSTOPS) - FORCE_INLINE static void set_homing_flag_y(const bool state) { performing_homing = state; } FORCE_INLINE static void set_y_lock(const bool state) { locked_Y_motor = state; } FORCE_INLINE static void set_y2_lock(const bool state) { locked_Y2_motor = state; } #endif #if ENABLED(Z_DUAL_ENDSTOPS) - FORCE_INLINE static void set_homing_flag_z(const bool state) { performing_homing = state; } FORCE_INLINE static void set_z_lock(const bool state) { locked_Z_motor = state; } FORCE_INLINE static void set_z2_lock(const bool state) { locked_Z2_motor = state; } #endif