From e09b4ce4a5a552eb93c509ff38d3e6d475296b34 Mon Sep 17 00:00:00 2001 From: Brian Date: Wed, 17 May 2017 19:46:16 -0400 Subject: [PATCH] Add checking --- Marlin/Marlin_main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 1d29853667..34b1566160 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -51,6 +51,7 @@ * G3 - CCW ARC * G4 - Dwell S or P * G5 - Cubic B-spline with XYZE destination and IJPQ offsets + * G7 - Coordinated move between UBL mesh points (I & J) * G10 - Retract filament according to settings of M207 * G11 - Retract recover filament according to settings of M208 * G12 - Clean tool @@ -3405,8 +3406,18 @@ inline void gcode_G7( #endif ) { if (IsRunning()) { - destination[X_AXIS] = code_seen('I') ? pgm_read_float(&ubl.mesh_index_to_xpos[code_has_value() ? code_value_int() : 0]) : current_position[X_AXIS]; - destination[Y_AXIS] = code_seen('J') ? pgm_read_float(&ubl.mesh_index_to_ypos[code_has_value() ? code_value_int() : 0]) : current_position[Y_AXIS]; + const bool hasI = code_seen('I'); + const int8_t ix = code_has_value() ? code_value_int() : 0; + const bool hasJ = code_seen('J'); + const int8_t iy = code_has_value() ? code_value_int() : 0; + + if ((hasI && !WITHIN(ix, 0, GRID_MAX_POINTS_X - 1)) || (hasJ && !WITHIN(iy, 0, GRID_MAX_POINTS_Y - 1))) { + SERIAL_ECHOLNPGM(MSG_ERR_MESH_XY); + return; + } + + destination[X_AXIS] = hasI ? pgm_read_float(&ubl.mesh_index_to_xpos[ix]) : current_position[X_AXIS]; + destination[Y_AXIS] = hasJ ? pgm_read_float(&ubl.mesh_index_to_ypos[iy]) : current_position[Y_AXIS]; destination[Z_AXIS] = current_position[Z_AXIS]; //todo: perhaps add Z-move support? destination[E_AXIS] = current_position[E_AXIS];