diff --git a/Marlin/src/gcode/bedlevel/M420.cpp b/Marlin/src/gcode/bedlevel/M420.cpp index 4144fadcd5..7fed4f9996 100644 --- a/Marlin/src/gcode/bedlevel/M420.cpp +++ b/Marlin/src/gcode/bedlevel/M420.cpp @@ -49,10 +49,33 @@ * With mesh-based leveling only: * * C Center mesh on the mean of the lowest and highest + * + * With MARLIN_DEV_MODE: + * S2 Create a simple random mesh and enable */ void GcodeSuite::M420() { - const bool seen_S = parser.seen('S'); - bool to_enable = seen_S ? parser.value_bool() : planner.leveling_active; + const bool seen_S = parser.seen('S'), + to_enable = seen_S ? parser.value_bool() : planner.leveling_active; + + #if ENABLED(MARLIN_DEV_MODE) + if (parser.intval('S') == 2) { + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + bilinear_start[X_AXIS] = MIN_PROBE_X; + bilinear_start[Y_AXIS] = MIN_PROBE_Y; + bilinear_grid_spacing[X_AXIS] = (MAX_PROBE_X - (MIN_PROBE_X)) / (GRID_MAX_POINTS_X - 1); + bilinear_grid_spacing[Y_AXIS] = (MAX_PROBE_Y - (MIN_PROBE_Y)) / (GRID_MAX_POINTS_Y - 1); + #endif + for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) + for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) + Z_VALUES(x, y) = 0.001 * random(-200, 200); + SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_X) " mesh "); + SERIAL_ECHOPAIR(" (", MIN_PROBE_X); + SERIAL_CHAR(','); SERIAL_ECHO(MIN_PROBE_Y); + SERIAL_ECHOPAIR(")-(", MAX_PROBE_X); + SERIAL_CHAR(','); SERIAL_ECHO(MAX_PROBE_Y); + SERIAL_ECHOLNPGM(")"); + } + #endif // If disabling leveling do it right away // (Don't disable for just M420 or M420 V)