diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index c00e59b5cd5d..cef8829f31ea 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1630,6 +1630,24 @@ #define Z_PROBE_LOW_POINT -2 // Farthest distance below the trigger-point to go before stopping +// For M851 give a range for adjusting the X probe offset +#ifndef Z_PROBE_OFFSET_XRANGE_MIN + #define Z_PROBE_OFFSET_XRANGE_MIN -50 +#endif + +#ifndef Z_PROBE_OFFSET_XRANGE_MAX + #define Z_PROBE_OFFSET_XRANGE_MAX 50 +#endif + +// For M851 give a range for adjusting the Y probe offset +#ifndef Z_PROBE_OFFSET_YRANGE_MIN + #define Z_PROBE_OFFSET_YRANGE_MIN -50 +#endif + +#ifndef Z_PROBE_OFFSET_YRANGE_MAX + #define Z_PROBE_OFFSET_YRANGE_MAX 50 +#endif + // For M851 give a range for adjusting the Z probe offset #define Z_PROBE_OFFSET_RANGE_MIN -20 #define Z_PROBE_OFFSET_RANGE_MAX 20 diff --git a/Marlin/src/gcode/probe/M851.cpp b/Marlin/src/gcode/probe/M851.cpp index e66392acb454..e35e73da35a5 100644 --- a/Marlin/src/gcode/probe/M851.cpp +++ b/Marlin/src/gcode/probe/M851.cpp @@ -44,10 +44,10 @@ void GcodeSuite::M851() { if (parser.seenval('X')) { const float x = parser.value_float(); #if HAS_PROBE_XY_OFFSET - if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE)) + if (WITHIN(x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX)) offs.x = x; else { - SERIAL_ECHOLNPGM("?X out of range (-", X_BED_SIZE, " to ", X_BED_SIZE, ")"); + SERIAL_ECHOLNPGM("?X out of range (", Z_PROBE_OFFSET_XRANGE_MIN, " to ", Z_PROBE_OFFSET_XRANGE_MAX, ")"); ok = false; } #else @@ -58,10 +58,10 @@ void GcodeSuite::M851() { if (parser.seenval('Y')) { const float y = parser.value_float(); #if HAS_PROBE_XY_OFFSET - if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE)) + if (WITHIN(y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX)) offs.y = y; else { - SERIAL_ECHOLNPGM("?Y out of range (-", Y_BED_SIZE, " to ", Y_BED_SIZE, ")"); + SERIAL_ECHOLNPGM("?Y out of range (", Z_PROBE_OFFSET_YRANGE_MIN, " to ", Z_PROBE_OFFSET_YRANGE_MAX, ")"); ok = false; } #else diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index b2b336bd17a7..97a1e2cc7def 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -1419,6 +1419,19 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L static_assert(PROBING_MARGIN_RIGHT >= 0, "PROBING_MARGIN_RIGHT must be >= 0."); #endif + #define static_assert_within(varname, x, min, max) static_assert(WITHIN(x, min, max), #varname " must be within " #min " and " #max) + + static_assert_within("Z_PROBE_OFFSET_XRANGE_MIN", Z_PROBE_OFFSET_XRANGE_MIN, -(X_BED_SIZE), X_BED_SIZE); + static_assert_within("Z_PROBE_OFFSET_XRANGE_MAX", Z_PROBE_OFFSET_XRANGE_MAX, -(X_BED_SIZE), X_BED_SIZE); + static_assert_within("Z_PROBE_OFFSET_YRANGE_MIN", Z_PROBE_OFFSET_YRANGE_MIN, -(Y_BED_SIZE), Y_BED_SIZE); + static_assert_within("Z_PROBE_OFFSET_YRANGE_MAX", Z_PROBE_OFFSET_YRANGE_MAX, -(Y_BED_SIZE), Y_BED_SIZE); + static_assert_within("Z_PROBE_OFFSET_RANGE_MIN", Z_PROBE_OFFSET_RANGE_MIN, -(Z_MAX_POS), Z_MAX_POS); + static_assert_within("Z_PROBE_OFFSET_RANGE_MAX", Z_PROBE_OFFSET_RANGE_MAX, -(Z_MAX_POS), Z_MAX_POS); + + static_assert_within("NOZZLE_TO_PROBE_OFFSET.x", sanity_nozzle_to_probe_offset.x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX); + static_assert_within("NOZZLE_TO_PROBE_OFFSET.y", sanity_nozzle_to_probe_offset.y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX); + static_assert_within("NOZZLE_TO_PROBE_OFFSET.z", sanity_nozzle_to_probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX); + #define _MARGIN(A) TERN(IS_KINEMATIC, PRINTABLE_RADIUS, ((A##_BED_SIZE) / 2)) static_assert(PROBING_MARGIN < _MARGIN(X), "PROBING_MARGIN is too large."); static_assert(PROBING_MARGIN_BACK < _MARGIN(Y), "PROBING_MARGIN_BACK is too large."); diff --git a/Marlin/src/lcd/extui/mks_ui/draw_number_key.cpp b/Marlin/src/lcd/extui/mks_ui/draw_number_key.cpp index 850a409a1857..fdf42a506bfe 100644 --- a/Marlin/src/lcd/extui/mks_ui/draw_number_key.cpp +++ b/Marlin/src/lcd/extui/mks_ui/draw_number_key.cpp @@ -358,14 +358,14 @@ static void set_value_confirm() { case x_offset: { #if HAS_PROBE_XY_OFFSET const float x = atof(key_value); - if (WITHIN(x, -(X_BED_SIZE), X_BED_SIZE)) + if (WITHIN(x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX)) probe.offset.x = x; #endif } break; case y_offset: { #if HAS_PROBE_XY_OFFSET const float y = atof(key_value); - if (WITHIN(y, -(Y_BED_SIZE), Y_BED_SIZE)) + if (WITHIN(y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX)) probe.offset.y = y; #endif } break; diff --git a/Marlin/src/lcd/menu/menu_advanced.cpp b/Marlin/src/lcd/menu/menu_advanced.cpp index 2bcd4e681b61..56da46028451 100644 --- a/Marlin/src/lcd/menu/menu_advanced.cpp +++ b/Marlin/src/lcd/menu/menu_advanced.cpp @@ -628,8 +628,8 @@ void menu_backlash(); START_MENU(); BACK_ITEM(MSG_ADVANCED_SETTINGS); #if HAS_PROBE_XY_OFFSET - EDIT_ITEM(float31sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, -(X_BED_SIZE), X_BED_SIZE); - EDIT_ITEM(float31sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, -(Y_BED_SIZE), Y_BED_SIZE); + EDIT_ITEM(float31sign, MSG_ZPROBE_XOFFSET, &probe.offset.x, Z_PROBE_OFFSET_XRANGE_MIN, Z_PROBE_OFFSET_XRANGE_MAX); + EDIT_ITEM(float31sign, MSG_ZPROBE_YOFFSET, &probe.offset.y, Z_PROBE_OFFSET_YRANGE_MIN, Z_PROBE_OFFSET_YRANGE_MAX); #endif EDIT_ITEM(LCD_Z_OFFSET_TYPE, MSG_ZPROBE_ZOFFSET, &probe.offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);