MCPcopy Create free account
hub / github.com/MarlinFirmware/Marlin / M420

Method M420

Marlin/src/gcode/bedlevel/M420.cpp:64–245  ·  view source on GitHub ↗

* M420: Enable/Disable Bed Leveling and/or set the Z fade height. * * S Turns leveling on or off * Z Sets the Z fade height (0 or none to disable) * V Verbose - Print the leveling grid * * With AUTO_BED_LEVELING_UBL only: * * L Load UBL mesh from index (0 is default) * T 0:Human-readable 1:CSV 2:"LCD" 4:Compact * * With mesh-based leveli

Source from the content-addressed store, hash-verified

62 * S2 Create a simple random mesh and enable
63 */
64void GcodeSuite::M420() {
65 const bool seen_S = parser.seen('S'),
66 to_enable = seen_S ? parser.value_bool() : planner.leveling_active;
67
68 #if ENABLED(MARLIN_DEV_MODE)
69 if (parser.intval('S') == 2) {
70 const float x_min = probe.min_x(), x_max = probe.max_x(),
71 y_min = probe.min_y(), y_max = probe.max_y();
72 #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
73 xy_pos_t start, spacing;
74 start.set(x_min, y_min);
75 spacing.set((x_max - x_min) / (GRID_MAX_CELLS_X),
76 (y_max - y_min) / (GRID_MAX_CELLS_Y));
77 bedlevel.set_grid(spacing, start);
78 #endif
79 GRID_LOOP(x, y) {
80 bedlevel.z_values[x][y] = 0.001 * random(-200, 200);
81 TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, bedlevel.z_values[x][y]));
82 }
83 TERN_(AUTO_BED_LEVELING_BILINEAR, bedlevel.refresh_bed_level());
84 SERIAL_ECHOPGM("Simulated " STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh ");
85 SERIAL_ECHOPGM(" (", x_min);
86 SERIAL_CHAR(','); SERIAL_ECHO(y_min);
87 SERIAL_ECHOPGM(")-(", x_max);
88 SERIAL_CHAR(','); SERIAL_ECHO(y_max);
89 SERIAL_ECHOLNPGM(")");
90 }
91 #endif
92
93 xyz_pos_t oldpos = current_position;
94
95 // If disabling leveling do it right away
96 // (Don't disable for just M420 or M420 V)
97 if (seen_S && !to_enable) set_bed_leveling_enabled(false);
98
99 #if ENABLED(AUTO_BED_LEVELING_UBL)
100
101 // L to load a mesh from the EEPROM
102 if (parser.seen('L')) {
103
104 set_bed_leveling_enabled(false);
105
106 #if ENABLED(EEPROM_SETTINGS)
107 const int8_t storage_slot = parser.has_value() ? parser.value_int() : bedlevel.storage_slot;
108 const int16_t a = settings.calc_num_meshes();
109
110 if (!a) {
111 SERIAL_ECHOLNPGM(GCODE_ERR_MSG("EEPROM storage not available."));
112 return;
113 }
114
115 if (!WITHIN(storage_slot, 0, a - 1)) {
116 SERIAL_ECHOLNPGM(GCODE_ERR_MSG("Invalid storage slot. Use 0 to ", a - 1));
117 return;
118 }
119
120 settings.load_mesh(storage_slot);
121 bedlevel.storage_slot = storage_slot;

Callers

nothing calls this directly

Calls 15

set_bed_leveling_enabledFunction · 0.85
leveling_is_validFunction · 0.85
set_z_fade_heightFunction · 0.85
ON_OFFFunction · 0.85
SERIAL_ECHO_STARTFunction · 0.85
report_current_positionFunction · 0.85
seenMethod · 0.80
value_boolMethod · 0.80
intvalMethod · 0.80
min_xMethod · 0.80
max_xMethod · 0.80
min_yMethod · 0.80

Tested by

no test coverage detected