|
@@ -0,0 +1,339 @@
|
|
1
|
+/**
|
|
2
|
+ * Marlin 3D Printer Firmware
|
|
3
|
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
|
4
|
+ *
|
|
5
|
+ * Based on Sprinter and grbl.
|
|
6
|
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
|
|
7
|
+ *
|
|
8
|
+ * This program is free software: you can redistribute it and/or modify
|
|
9
|
+ * it under the terms of the GNU General Public License as published by
|
|
10
|
+ * the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+ * (at your option) any later version.
|
|
12
|
+ *
|
|
13
|
+ * This program is distributed in the hope that it will be useful,
|
|
14
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+ * GNU General Public License for more details.
|
|
17
|
+ *
|
|
18
|
+ * You should have received a copy of the GNU General Public License
|
|
19
|
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+ *
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+//
|
|
24
|
+// Bed Leveling Menus
|
|
25
|
+//
|
|
26
|
+
|
|
27
|
+#include "../../inc/MarlinConfigPre.h"
|
|
28
|
+
|
|
29
|
+#if HAS_LCD_MENU && ENABLED(LCD_BED_LEVELING)
|
|
30
|
+
|
|
31
|
+#include "menu.h"
|
|
32
|
+#include "../../module/planner.h"
|
|
33
|
+#include "../../feature/bedlevel/bedlevel.h"
|
|
34
|
+
|
|
35
|
+#if ENABLED(PROBE_MANUALLY) || ENABLED(MESH_BED_LEVELING)
|
|
36
|
+
|
|
37
|
+ #include "../../module/motion.h"
|
|
38
|
+ #include "../../gcode/queue.h"
|
|
39
|
+
|
|
40
|
+ //
|
|
41
|
+ // Motion > Level Bed handlers
|
|
42
|
+ //
|
|
43
|
+
|
|
44
|
+ static uint8_t manual_probe_index;
|
|
45
|
+
|
|
46
|
+ // LCD probed points are from defaults
|
|
47
|
+ constexpr uint8_t total_probe_points = (
|
|
48
|
+ #if ENABLED(AUTO_BED_LEVELING_3POINT)
|
|
49
|
+ 3
|
|
50
|
+ #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
|
|
51
|
+ GRID_MAX_POINTS
|
|
52
|
+ #endif
|
|
53
|
+ );
|
|
54
|
+
|
|
55
|
+ bool lcd_wait_for_move;
|
|
56
|
+
|
|
57
|
+ //
|
|
58
|
+ // Bed leveling is done. Wait for G29 to complete.
|
|
59
|
+ // A flag is used so that this can release control
|
|
60
|
+ // and allow the command queue to be processed.
|
|
61
|
+ //
|
|
62
|
+ // When G29 finishes the last move:
|
|
63
|
+ // - Raise Z to the "manual probe height"
|
|
64
|
+ // - Don't return until done.
|
|
65
|
+ //
|
|
66
|
+ // ** This blocks the command queue! **
|
|
67
|
+ //
|
|
68
|
+ void _lcd_level_bed_done() {
|
|
69
|
+ if (!lcd_wait_for_move) {
|
|
70
|
+ #if MANUAL_PROBE_HEIGHT > 0 && DISABLED(MESH_BED_LEVELING)
|
|
71
|
+ // Display "Done" screen and wait for moves to complete
|
|
72
|
+ line_to_z(MANUAL_PROBE_HEIGHT);
|
|
73
|
+ lcd_synchronize(PSTR(MSG_LEVEL_BED_DONE));
|
|
74
|
+ #endif
|
|
75
|
+ lcd_goto_previous_menu_no_defer();
|
|
76
|
+ lcd_completion_feedback();
|
|
77
|
+ }
|
|
78
|
+ if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_LEVEL_BED_DONE));
|
|
79
|
+ lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ void _lcd_level_goto_next_point();
|
|
83
|
+
|
|
84
|
+ //
|
|
85
|
+ // Step 7: Get the Z coordinate, click goes to the next point or exits
|
|
86
|
+ //
|
|
87
|
+ void _lcd_level_bed_get_z() {
|
|
88
|
+ ENCODER_DIRECTION_NORMAL();
|
|
89
|
+
|
|
90
|
+ if (use_click()) {
|
|
91
|
+
|
|
92
|
+ //
|
|
93
|
+ // Save the current Z position and move
|
|
94
|
+ //
|
|
95
|
+
|
|
96
|
+ // If done...
|
|
97
|
+ if (++manual_probe_index >= total_probe_points) {
|
|
98
|
+ //
|
|
99
|
+ // The last G29 records the point and enables bed leveling
|
|
100
|
+ //
|
|
101
|
+ lcd_wait_for_move = true;
|
|
102
|
+ lcd_goto_screen(_lcd_level_bed_done);
|
|
103
|
+ #if ENABLED(MESH_BED_LEVELING)
|
|
104
|
+ enqueue_and_echo_commands_P(PSTR("G29 S2"));
|
|
105
|
+ #elif ENABLED(PROBE_MANUALLY)
|
|
106
|
+ enqueue_and_echo_commands_P(PSTR("G29 V1"));
|
|
107
|
+ #endif
|
|
108
|
+ }
|
|
109
|
+ else
|
|
110
|
+ _lcd_level_goto_next_point();
|
|
111
|
+
|
|
112
|
+ return;
|
|
113
|
+ }
|
|
114
|
+
|
|
115
|
+ //
|
|
116
|
+ // Encoder knob or keypad buttons adjust the Z position
|
|
117
|
+ //
|
|
118
|
+ if (encoderPosition) {
|
|
119
|
+ const float z = current_position[Z_AXIS] + float((int32_t)encoderPosition) * (MBL_Z_STEP);
|
|
120
|
+ line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f));
|
|
121
|
+ lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
|
|
122
|
+ encoderPosition = 0;
|
|
123
|
+ }
|
|
124
|
+
|
|
125
|
+ //
|
|
126
|
+ // Draw on first display, then only on Z change
|
|
127
|
+ //
|
|
128
|
+ if (lcdDrawUpdate) {
|
|
129
|
+ const float v = current_position[Z_AXIS];
|
|
130
|
+ lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001f : 0.0001f), '+'));
|
|
131
|
+ }
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ //
|
|
135
|
+ // Step 6: Display "Next point: 1 / 9" while waiting for move to finish
|
|
136
|
+ //
|
|
137
|
+ void _lcd_level_bed_moving() {
|
|
138
|
+ if (lcdDrawUpdate) {
|
|
139
|
+ char msg[10];
|
|
140
|
+ sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
|
|
141
|
+ lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
|
|
142
|
+ }
|
|
143
|
+ lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
|
|
144
|
+ if (!lcd_wait_for_move) lcd_goto_screen(_lcd_level_bed_get_z);
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ //
|
|
148
|
+ // Step 5: Initiate a move to the next point
|
|
149
|
+ //
|
|
150
|
+ void _lcd_level_goto_next_point() {
|
|
151
|
+ lcd_goto_screen(_lcd_level_bed_moving);
|
|
152
|
+
|
|
153
|
+ // G29 Records Z, moves, and signals when it pauses
|
|
154
|
+ lcd_wait_for_move = true;
|
|
155
|
+ #if ENABLED(MESH_BED_LEVELING)
|
|
156
|
+ enqueue_and_echo_commands_P(manual_probe_index ? PSTR("G29 S2") : PSTR("G29 S1"));
|
|
157
|
+ #elif ENABLED(PROBE_MANUALLY)
|
|
158
|
+ enqueue_and_echo_commands_P(PSTR("G29 V1"));
|
|
159
|
+ #endif
|
|
160
|
+ }
|
|
161
|
+
|
|
162
|
+ //
|
|
163
|
+ // Step 4: Display "Click to Begin", wait for click
|
|
164
|
+ // Move to the first probe position
|
|
165
|
+ //
|
|
166
|
+ void _lcd_level_bed_homing_done() {
|
|
167
|
+ if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
|
|
168
|
+ if (use_click()) {
|
|
169
|
+ manual_probe_index = 0;
|
|
170
|
+ _lcd_level_goto_next_point();
|
|
171
|
+ }
|
|
172
|
+ }
|
|
173
|
+
|
|
174
|
+ //
|
|
175
|
+ // Step 3: Display "Homing XYZ" - Wait for homing to finish
|
|
176
|
+ //
|
|
177
|
+ void _lcd_level_bed_homing() {
|
|
178
|
+ _lcd_draw_homing();
|
|
179
|
+ if (all_axes_homed()) lcd_goto_screen(_lcd_level_bed_homing_done);
|
|
180
|
+ }
|
|
181
|
+
|
|
182
|
+ #if ENABLED(PROBE_MANUALLY)
|
|
183
|
+ extern bool g29_in_progress;
|
|
184
|
+ #endif
|
|
185
|
+
|
|
186
|
+ //
|
|
187
|
+ // Step 2: Continue Bed Leveling...
|
|
188
|
+ //
|
|
189
|
+ void _lcd_level_bed_continue() {
|
|
190
|
+ defer_return_to_status = true;
|
|
191
|
+ axis_homed = 0;
|
|
192
|
+ lcd_goto_screen(_lcd_level_bed_homing);
|
|
193
|
+ enqueue_and_echo_commands_P(PSTR("G28"));
|
|
194
|
+ }
|
|
195
|
+
|
|
196
|
+#endif // PROBE_MANUALLY || MESH_BED_LEVELING
|
|
197
|
+
|
|
198
|
+#if ENABLED(LEVEL_BED_CORNERS)
|
|
199
|
+
|
|
200
|
+ /**
|
|
201
|
+ * Level corners, starting in the front-left corner.
|
|
202
|
+ */
|
|
203
|
+ static int8_t bed_corner;
|
|
204
|
+ void _lcd_goto_next_corner() {
|
|
205
|
+ line_to_z(4.0);
|
|
206
|
+ switch (bed_corner) {
|
|
207
|
+ case 0:
|
|
208
|
+ current_position[X_AXIS] = X_MIN_BED + LEVEL_CORNERS_INSET;
|
|
209
|
+ current_position[Y_AXIS] = Y_MIN_BED + LEVEL_CORNERS_INSET;
|
|
210
|
+ break;
|
|
211
|
+ case 1:
|
|
212
|
+ current_position[X_AXIS] = X_MAX_BED - LEVEL_CORNERS_INSET;
|
|
213
|
+ break;
|
|
214
|
+ case 2:
|
|
215
|
+ current_position[Y_AXIS] = Y_MAX_BED - LEVEL_CORNERS_INSET;
|
|
216
|
+ break;
|
|
217
|
+ case 3:
|
|
218
|
+ current_position[X_AXIS] = X_MIN_BED + LEVEL_CORNERS_INSET;
|
|
219
|
+ break;
|
|
220
|
+ #if ENABLED(LEVEL_CENTER_TOO)
|
|
221
|
+ case 4:
|
|
222
|
+ current_position[X_AXIS] = X_CENTER;
|
|
223
|
+ current_position[Y_AXIS] = Y_CENTER;
|
|
224
|
+ break;
|
|
225
|
+ #endif
|
|
226
|
+ }
|
|
227
|
+ planner.buffer_line(current_position, MMM_TO_MMS(manual_feedrate_mm_m[X_AXIS]), active_extruder);
|
|
228
|
+ line_to_z(0.0);
|
|
229
|
+ if (++bed_corner > 3
|
|
230
|
+ #if ENABLED(LEVEL_CENTER_TOO)
|
|
231
|
+ + 1
|
|
232
|
+ #endif
|
|
233
|
+ ) bed_corner = 0;
|
|
234
|
+ }
|
|
235
|
+
|
|
236
|
+ void _lcd_corner_submenu() {
|
|
237
|
+ START_MENU();
|
|
238
|
+ MENU_ITEM(function,
|
|
239
|
+ #if ENABLED(LEVEL_CENTER_TOO)
|
|
240
|
+ MSG_LEVEL_BED_NEXT_POINT
|
|
241
|
+ #else
|
|
242
|
+ MSG_NEXT_CORNER
|
|
243
|
+ #endif
|
|
244
|
+ , _lcd_goto_next_corner);
|
|
245
|
+ MENU_ITEM(function, MSG_BACK, lcd_goto_previous_menu_no_defer);
|
|
246
|
+ END_MENU();
|
|
247
|
+ }
|
|
248
|
+
|
|
249
|
+ void _lcd_level_bed_corners_homing() {
|
|
250
|
+ _lcd_draw_homing();
|
|
251
|
+ if (all_axes_homed()) {
|
|
252
|
+ bed_corner = 0;
|
|
253
|
+ lcd_goto_screen(_lcd_corner_submenu);
|
|
254
|
+ _lcd_goto_next_corner();
|
|
255
|
+ }
|
|
256
|
+ }
|
|
257
|
+
|
|
258
|
+ void _lcd_level_bed_corners() {
|
|
259
|
+ defer_return_to_status = true;
|
|
260
|
+ if (!all_axes_known()) {
|
|
261
|
+ axis_homed = 0;
|
|
262
|
+ enqueue_and_echo_commands_P(PSTR("G28"));
|
|
263
|
+ }
|
|
264
|
+ lcd_goto_screen(_lcd_level_bed_corners_homing);
|
|
265
|
+ }
|
|
266
|
+
|
|
267
|
+#endif // LEVEL_BED_CORNERS
|
|
268
|
+
|
|
269
|
+/**
|
|
270
|
+ * Step 1: Bed Level entry-point
|
|
271
|
+ *
|
|
272
|
+ * << Motion
|
|
273
|
+ * Auto Home (if homing needed)
|
|
274
|
+ * Leveling On/Off (if data exists, and homed)
|
|
275
|
+ * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
|
|
276
|
+ * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
|
|
277
|
+ * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
|
|
278
|
+ * Level Bed >
|
|
279
|
+ * Level Corners > (if homed)
|
|
280
|
+ * Load Settings (Req: EEPROM_SETTINGS)
|
|
281
|
+ * Save Settings (Req: EEPROM_SETTINGS)
|
|
282
|
+ */
|
|
283
|
+void menu_bed_leveling() {
|
|
284
|
+ START_MENU();
|
|
285
|
+ MENU_BACK(MSG_MOTION);
|
|
286
|
+
|
|
287
|
+ const bool is_homed = all_axes_known();
|
|
288
|
+
|
|
289
|
+ // Auto Home if not using manual probing
|
|
290
|
+ #if DISABLED(PROBE_MANUALLY) && DISABLED(MESH_BED_LEVELING)
|
|
291
|
+ if (!is_homed) MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
|
|
292
|
+ #endif
|
|
293
|
+
|
|
294
|
+ // Level Bed
|
|
295
|
+ #if ENABLED(PROBE_MANUALLY) || ENABLED(MESH_BED_LEVELING)
|
|
296
|
+ // Manual leveling uses a guided procedure
|
|
297
|
+ MENU_ITEM(submenu, MSG_LEVEL_BED, _lcd_level_bed_continue);
|
|
298
|
+ #else
|
|
299
|
+ // Automatic leveling can just run the G-code
|
|
300
|
+ MENU_ITEM(gcode, MSG_LEVEL_BED, is_homed ? PSTR("G29") : PSTR("G28\nG29"));
|
|
301
|
+ #endif
|
|
302
|
+
|
|
303
|
+ // Homed and leveling is valid? Then leveling can be toggled.
|
|
304
|
+ if (is_homed && leveling_is_valid()) {
|
|
305
|
+ bool new_level_state = planner.leveling_active;
|
|
306
|
+ MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
|
|
307
|
+ }
|
|
308
|
+
|
|
309
|
+ // Z Fade Height
|
|
310
|
+ #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
|
311
|
+ MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &lcd_z_fade_height, 0, 100, _lcd_set_z_fade_height);
|
|
312
|
+ #endif
|
|
313
|
+
|
|
314
|
+ //
|
|
315
|
+ // MBL Z Offset
|
|
316
|
+ //
|
|
317
|
+ #if ENABLED(MESH_BED_LEVELING)
|
|
318
|
+ MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
|
|
319
|
+ #endif
|
|
320
|
+
|
|
321
|
+ #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
|
|
322
|
+ MENU_ITEM(submenu, MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
|
|
323
|
+ #elif HAS_BED_PROBE
|
|
324
|
+ MENU_ITEM_EDIT(float52, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
|
|
325
|
+ #endif
|
|
326
|
+
|
|
327
|
+ #if ENABLED(LEVEL_BED_CORNERS)
|
|
328
|
+ // Move to the next corner for leveling
|
|
329
|
+ MENU_ITEM(submenu, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
|
|
330
|
+ #endif
|
|
331
|
+
|
|
332
|
+ #if ENABLED(EEPROM_SETTINGS)
|
|
333
|
+ MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
|
|
334
|
+ MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
|
|
335
|
+ #endif
|
|
336
|
+ END_MENU();
|
|
337
|
+}
|
|
338
|
+
|
|
339
|
+#endif // HAS_LCD_MENU && LCD_BED_LEVELING
|