Skip to content

Commit c867de5

Browse files
committed
ADD Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX to make UIs nicer, and limit M851 XY offsets
M851 would respect the limits, so the system would be safer. Fixes #26263
1 parent 11f98ad commit c867de5

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

Marlin/Configuration.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1630,6 +1630,24 @@
16301630

16311631
#define Z_PROBE_LOW_POINT -2 // Farthest distance below the trigger-point to go before stopping
16321632

1633+
// For M851 give a range for adjusting the X probe offset
1634+
#ifndef Z_PROBE_OFFSET_XRANGE_MIN
1635+
#define Z_PROBE_OFFSET_XRANGE_MIN -50
1636+
#endif
1637+
1638+
#ifndef Z_PROBE_OFFSET_XRANGE_MAX
1639+
#define Z_PROBE_OFFSET_XRANGE_MAX 50
1640+
#endif
1641+
1642+
// For M851 give a range for adjusting the Y probe offset
1643+
#ifndef Z_PROBE_OFFSET_YRANGE_MIN
1644+
#define Z_PROBE_OFFSET_YRANGE_MIN -50
1645+
#endif
1646+
1647+
#ifndef Z_PROBE_OFFSET_YRANGE_MAX
1648+
#define Z_PROBE_OFFSET_YRANGE_MAX 50
1649+
#endif
1650+
16331651
// For M851 give a range for adjusting the Z probe offset
16341652
#define Z_PROBE_OFFSET_RANGE_MIN -20
16351653
#define Z_PROBE_OFFSET_RANGE_MAX 20

Marlin/src/gcode/probe/M851.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ void GcodeSuite::M851() {
4444
if (parser.seenval('X')) {
4545
const float x = parser.value_float();
4646
#if HAS_PROBE_XY_OFFSET
47-
if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
47+
if (WITHIN(x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX))
4848
offs.x = x;
4949
else {
50-
SERIAL_ECHOLNPGM("?X out of range (-", X_BED_SIZE, " to ", X_BED_SIZE, ")");
50+
SERIAL_ECHOLNPGM("?X out of range (", Z_PROBE_OFFSET_XRANGE_MIN, " to ", Z_PROBE_OFFSET_XRANGE_MAX, ")");
5151
ok = false;
5252
}
5353
#else
@@ -58,10 +58,10 @@ void GcodeSuite::M851() {
5858
if (parser.seenval('Y')) {
5959
const float y = parser.value_float();
6060
#if HAS_PROBE_XY_OFFSET
61-
if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
61+
if (WITHIN(y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX))
6262
offs.y = y;
6363
else {
64-
SERIAL_ECHOLNPGM("?Y out of range (-", Y_BED_SIZE, " to ", Y_BED_SIZE, ")");
64+
SERIAL_ECHOLNPGM("?Y out of range (", Z_PROBE_OFFSET_YRANGE_MIN, " to ", Z_PROBE_OFFSET_YRANGE_MAX, ")");
6565
ok = false;
6666
}
6767
#else

Marlin/src/inc/SanityCheck.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,19 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
14191419
static_assert(PROBING_MARGIN_RIGHT >= 0, "PROBING_MARGIN_RIGHT must be >= 0.");
14201420
#endif
14211421

1422+
#define static_assert_within(varname, x, min, max) static_assert(WITHIN(x, min, max), #varname " must be within " #min " and " #max)
1423+
1424+
static_assert_within("Z_PROBE_OFFSET_XRANGE_MIN", Z_PROBE_OFFSET_XRANGE_MIN, -(X_BED_SIZE), X_BED_SIZE);
1425+
static_assert_within("Z_PROBE_OFFSET_XRANGE_MAX", Z_PROBE_OFFSET_XRANGE_MAX, -(X_BED_SIZE), X_BED_SIZE);
1426+
static_assert_within("Z_PROBE_OFFSET_YRANGE_MIN", Z_PROBE_OFFSET_YRANGE_MIN, -(Y_BED_SIZE), Y_BED_SIZE);
1427+
static_assert_within("Z_PROBE_OFFSET_YRANGE_MAX", Z_PROBE_OFFSET_YRANGE_MAX, -(Y_BED_SIZE), Y_BED_SIZE);
1428+
static_assert_within("Z_PROBE_OFFSET_RANGE_MIN", Z_PROBE_OFFSET_RANGE_MIN, -(Z_MAX_POS), Z_MAX_POS);
1429+
static_assert_within("Z_PROBE_OFFSET_RANGE_MAX", Z_PROBE_OFFSET_RANGE_MAX, -(Z_MAX_POS), Z_MAX_POS);
1430+
1431+
static_assert_within("NOZZLE_TO_PROBE_OFFSET.x", sanity_nozzle_to_probe_offset.x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX);
1432+
static_assert_within("NOZZLE_TO_PROBE_OFFSET.y", sanity_nozzle_to_probe_offset.y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX);
1433+
static_assert_within("NOZZLE_TO_PROBE_OFFSET.z", sanity_nozzle_to_probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
1434+
14221435
#define _MARGIN(A) TERN(IS_KINEMATIC, PRINTABLE_RADIUS, ((A##_BED_SIZE) / 2))
14231436
static_assert(PROBING_MARGIN < _MARGIN(X), "PROBING_MARGIN is too large.");
14241437
static_assert(PROBING_MARGIN_BACK < _MARGIN(Y), "PROBING_MARGIN_BACK is too large.");

Marlin/src/lcd/extui/mks_ui/draw_number_key.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,14 @@ static void set_value_confirm() {
358358
case x_offset: {
359359
#if HAS_PROBE_XY_OFFSET
360360
const float x = atof(key_value);
361-
if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE))
361+
if (WITHIN(x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX))
362362
probe.offset.x = x;
363363
#endif
364364
} break;
365365
case y_offset: {
366366
#if HAS_PROBE_XY_OFFSET
367367
const float y = atof(key_value);
368-
if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE))
368+
if (WITHIN(y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX))
369369
probe.offset.y = y;
370370
#endif
371371
} break;

Marlin/src/lcd/menu/menu_advanced.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -628,8 +628,8 @@ void menu_backlash();
628628
START_MENU();
629629
BACK_ITEM(MSG_ADVANCED_SETTINGS);
630630
#if HAS_PROBE_XY_OFFSET
631-
EDIT_ITEM(float31sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, -(X_BED_SIZE), X_BED_SIZE);
632-
EDIT_ITEM(float31sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, -(Y_BED_SIZE), Y_BED_SIZE);
631+
EDIT_ITEM(float31sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX);
632+
EDIT_ITEM(float31sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX);
633633
#endif
634634
EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
635635

0 commit comments

Comments
 (0)