From 13175ce7da7a1cc260e923df3bf81f801fb6438d Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 14 May 2016 17:12:44 -0700 Subject: [PATCH] Fix error checking in M421 --- Marlin/Marlin_main.cpp | 23 +++++++++++++---------- Marlin/language.h | 2 +- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 5416243f1..0767979ac 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -5851,19 +5851,22 @@ inline void gcode_M410() { stepper.quick_stop(); } if ((hasY = code_seen('Y'))) y = code_value(); if ((hasZ = code_seen('Z'))) z = code_value(); - if (!hasX || !hasY || !hasZ) { + if (hasX && hasY && hasZ) { + + int8_t ix = mbl.select_x_index(x), + iy = mbl.select_y_index(y); + + if (ix >= 0 && iy >= 0) + mbl.set_z(ix, iy, z); + else { + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY); + } + } + else { SERIAL_ERROR_START; SERIAL_ERRORLNPGM(MSG_ERR_M421_REQUIRES_XYZ); - err = true; } - - if (x >= MESH_NUM_X_POINTS || y >= MESH_NUM_Y_POINTS) { - SERIAL_ERROR_START; - SERIAL_ERRORLNPGM(MSG_ERR_MESH_INDEX_OOB); - err = true; - } - - if (!err) mbl.set_z(mbl.select_x_index(x), mbl.select_y_index(y), z); } #endif diff --git a/Marlin/language.h b/Marlin/language.h index 179b1f710..02f177221 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -148,7 +148,7 @@ #define MSG_Z_PROBE "z_probe: " #define MSG_ERR_MATERIAL_INDEX "M145 S out of range (0-1)" #define MSG_ERR_M421_REQUIRES_XYZ "M421 requires XYZ parameters" -#define MSG_ERR_MESH_INDEX_OOB "Mesh XY index is out of bounds" +#define MSG_ERR_MESH_XY "Mesh XY cannot be resolved" #define MSG_ERR_M428_TOO_FAR "Too far from reference point" #define MSG_ERR_M303_DISABLED "PIDTEMP disabled" #define MSG_M119_REPORT "Reporting endstop status"