Skip to content

Commit 4b84b28

Browse files
committed
🚸 Improve M422 error messages
1 parent c6a6d35 commit 4b84b28

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

Marlin/src/gcode/calibrate/G34_M422.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ void GcodeSuite::M422() {
493493
return;
494494
}
495495

496-
xy_pos_t *pos_dest = (
496+
xy_pos_t * const pos_dest = (
497497
TERN_(HAS_Z_STEPPER_ALIGN_STEPPER_XY, !is_probe_point ? z_stepper_align.stepper_xy :)
498498
z_stepper_align.xy
499499
);
@@ -504,24 +504,25 @@ void GcodeSuite::M422() {
504504
}
505505

506506
// Get the Probe Position Index or Z Stepper Index
507-
int8_t position_index;
508-
if (is_probe_point) {
509-
position_index = parser.intval('S') - 1;
510-
if (!WITHIN(position_index, 0, int8_t(NUM_Z_STEPPER_DRIVERS) - 1)) {
511-
SERIAL_ECHOLNPGM("?(S) Probe-position index invalid.");
512-
return;
513-
}
514-
}
507+
int8_t position_index = 1;
508+
FSTR_P err_string = F("?(S) Probe-position");
509+
if (is_probe_point)
510+
position_index = parser.intval('S');
515511
else {
516512
#if HAS_Z_STEPPER_ALIGN_STEPPER_XY
517-
position_index = parser.intval('W') - 1;
518-
if (!WITHIN(position_index, 0, NUM_Z_STEPPER_DRIVERS - 1)) {
519-
SERIAL_ECHOLNPGM("?(W) Z-stepper index invalid.");
520-
return;
521-
}
513+
err_string = F("?(W) Z-stepper");
514+
position_index = parser.intval('W');
522515
#endif
523516
}
524517

518+
if (!WITHIN(position_index, 1, NUM_Z_STEPPER_DRIVERS)) {
519+
SERIAL_ECHOF(err_string);
520+
SERIAL_ECHOLNPGM(" index invalid (1.." STRINGIFY(NUM_Z_STEPPER_DRIVERS) ").");
521+
return;
522+
}
523+
524+
--position_index;
525+
525526
const xy_pos_t pos = {
526527
parser.floatval('X', pos_dest[position_index].x),
527528
parser.floatval('Y', pos_dest[position_index].y)

0 commit comments

Comments
 (0)