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

M428 axis filters #27015

Open
wants to merge 4 commits into
base: bugfix-2.1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 21 additions & 9 deletions Marlin/src/gcode/geometry/M206_M428.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,36 @@ void GcodeSuite::M206_report(const bool forReplay/*=true*/) {
* M428 can't be used more than 2cm away from 0 or an endstop.
*
* Use M206 to set these values directly.
*
* Parameters:
* X, Y, Z, ... - Flags to set the home offset for only the specified axes
* P - Flag to add the distance to the existing home offset
*/
void GcodeSuite::M428() {
if (homing_needed_error()) return;

const bool no_axes = !parser.seen(STR_AXES_LOGICAL);
xyz_float_t diff;
LOOP_NUM_AXES(i) {
diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0)
diff[i] = -current_position[i];
if (!WITHIN(diff[i], -20, 20)) {
SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR);
LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR);
ERR_BUZZ();
return;
if (no_axes || parser.seen_test(AXIS_CHAR(i))) {
diff[i] = base_home_pos((AxisEnum)i) - current_position[i];
// If the current position is too far, for min homing just set to the negative current position
if (!WITHIN(diff[i], -20, 20) && home_dir((AxisEnum)i) > 0) diff[i] = -current_position[i];
// If still too far report an error
if (!WITHIN(diff[i], -20, 20)) {
SERIAL_ERROR_MSG(STR_ERR_M428_TOO_FAR);
LCD_ALERTMESSAGE(MSG_ERR_M428_TOO_FAR);
ERR_BUZZ();
return;
}
}
else
diff[i] = 0;
}

LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i]);
const bool adding = parser.seen_test('P');
LOOP_NUM_AXES(i) set_home_offset((AxisEnum)i, diff[i] + (adding ? home_offset[i] : 0));

report_current_position();
LCD_MESSAGE(MSG_HOME_OFFSETS_APPLIED);
OKAY_BUZZ();
Expand Down