From 2643404ac88f8af65e00792f9aa5a28b81cf86d1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 10 Dec 2016 00:41:47 -0800 Subject: [PATCH] Throw an error in M420 if can't enable --- Marlin/Marlin_main.cpp | 27 +++++++++++++++++++++++++-- Marlin/language.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 68123ee23..4fb602a0b 100755 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -2243,7 +2243,13 @@ static void clean_up_after_endstop_or_probe_move() { #elif HAS_ABL - if (enable != planner.abl_enabled) { + #if ENABLED(AUTO_BED_LEVELING_BILINEAR) + const bool can_change = (!enable || (bilinear_grid_spacing[0] && bilinear_grid_spacing[1])); + #else + constexpr bool can_change = true; + #endif + + if (can_change && enable != planner.abl_enabled) { planner.abl_enabled = enable; if (!enable) set_current_from_steppers_for_axis( @@ -7007,10 +7013,27 @@ void quickstop_stepper() { * Z[height] Sets the Z fade height (0 or none to disable) */ inline void gcode_M420() { - if (code_seen('S')) set_bed_leveling_enabled(code_value_bool()); + bool to_enable = false; + + if (code_seen('S')) { + to_enable = code_value_bool(); + set_bed_leveling_enabled(to_enable); + } + #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) if (code_seen('Z')) set_z_fade_height(code_value_linear_units()); #endif + + if (to_enable && !( + #if ENABLED(MESH_BED_LEVELING) + mbl.active() + #else + planner.abl_enabled + #endif + ) ) { + SERIAL_ERROR_START; + SERIAL_ERRORLNPGM(MSG_ERR_M420_FAILED); + } } #endif diff --git a/Marlin/language.h b/Marlin/language.h index 2ab41cc9b..322db7617 100644 --- a/Marlin/language.h +++ b/Marlin/language.h @@ -157,6 +157,7 @@ #define MSG_ERR_MESH_XY "Mesh XY or IJ cannot be resolved" #define MSG_ERR_ARC_ARGS "G2/G3 bad parameters" #define MSG_ERR_PROTECTED_PIN "Protected Pin" +#define MSG_ERR_M420_FAILED "Failed to enable Bed Leveling" #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"