Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix g12 for single nozzle #17540

41 changes: 34 additions & 7 deletions Marlin/src/libs/nozzle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,49 @@ Nozzle nozzle;
void Nozzle::clean(const uint8_t &pattern, const uint8_t &strokes, const float &radius, const uint8_t &objects, const uint8_t cleans) {
xyz_pos_t start[HOTENDS] = NOZZLE_CLEAN_START_POINT, end[HOTENDS] = NOZZLE_CLEAN_END_POINT, middle[HOTENDS] = NOZZLE_CLEAN_CIRCLE_MIDDLE;

const uint8_t arrPos = ANY(SINGLENOZZLE, MIXING_EXTRUDER) ? 0 : active_extruder;

#if HAS_SOFTWARE_ENDSTOPS

#define LIMIT_AXIS(A) do{ \
LIMIT( start[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \
LIMIT(middle[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \
LIMIT( end[arrPos].A, soft_endstop.min.A, soft_endstop.max.A); \
}while(0)

LIMIT_AXIS(x);
LIMIT_AXIS(y);
LIMIT_AXIS(z);

const float arc_part = radius / M_PI;
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
const bool radiusOutOfRange = (middle.x + arc_part > soft_endstop.max.x)
|| (middle.x + arc_part < soft_endstop.min.x)
|| (middle.y + arc_part > soft_endstop.max.y)
|| (middle.y + arc_part < soft_endstop.min.y);

if (radiusOutOfRange && pattern == 2) {
SERIAL_ECHOLNPGM("Warning: Radius Out of Range");
return;
}

#endif

if (pattern == 2) {
if (!(cleans & (_BV(X_AXIS) | _BV(Y_AXIS)))) {
SERIAL_ECHOLNPGM("Warning : Clean Circle requires XY");
SERIAL_ECHOLNPGM("Warning: Clean Circle requires XY");
return;
}
}
else {
if (!TEST(cleans, X_AXIS)) start[active_extruder].x = end[active_extruder].x = current_position.x;
if (!TEST(cleans, Y_AXIS)) start[active_extruder].y = end[active_extruder].y = current_position.y;
if (!TEST(cleans, X_AXIS)) start[arrPos].x = end[arrPos].x = current_position.x;
if (!TEST(cleans, Y_AXIS)) start[arrPos].y = end[arrPos].y = current_position.y;
}
if (!TEST(cleans, Z_AXIS)) start[active_extruder].z = end[active_extruder].z = current_position.z;
if (!TEST(cleans, Z_AXIS)) start[arrPos].z = end[arrPos].z = current_position.z;

switch (pattern) {
case 1: zigzag(start[active_extruder], end[active_extruder], strokes, objects); break;
case 2: circle(start[active_extruder], middle[active_extruder], strokes, radius); break;
default: stroke(start[active_extruder], end[active_extruder], strokes);
case 1: zigzag(start[arrPos], end[arrPos], strokes, objects); break;
case 2: circle(start[arrPos], middle[arrPos], strokes, radius); break;
default: stroke(start[arrPos], end[arrPos], strokes);
}
}

Expand Down