Skip to content

Commit

Permalink
Update tool_change.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored Mar 8, 2020
1 parent 7919170 commit 306e0eb
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,18 +368,16 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a

#if ENABLED(SWITCHING_TOOLHEAD)

void swt_init() {
constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;

// lock tool.
MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[0]);
inline void swt_lock(const bool locked=true) {
constexpr uint16_t swt_angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;
MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[locked ? 0 : 1]);
}

void swt_init() { swt_lock(); }

inline void switching_toolhead_tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
if (no_move) return;

constexpr uint16_t angles[2] = SWITCHING_TOOLHEAD_SERVO_ANGLES;

constexpr float toolheadposx[] = SWITCHING_TOOLHEAD_X_POS;
const float placexpos = toolheadposx[active_extruder],
grabxpos = toolheadposx[new_tool];
Expand Down Expand Up @@ -413,7 +411,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a

planner.synchronize();
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("(2) Unlock and Place Toolhead");
MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[1]);
swt_lock(false);
safe_delay(500);

current_position.y = SWITCHING_TOOLHEAD_Y_POS;
Expand Down Expand Up @@ -458,7 +456,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
// Wait for move to finish, pause 0.2s, move servo, pause 0.5s
planner.synchronize();
safe_delay(200);
MOVE_SERVO(SWITCHING_TOOLHEAD_SERVO_NR, angles[0]);
swt_lock();
safe_delay(500);

current_position.y -= SWITCHING_TOOLHEAD_Y_CLEAR;
Expand Down

1 comment on commit 306e0eb

@MangaValk
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great refractor! :)

Please sign in to comment.