My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

menu_ubl.cpp 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Unified Bed Leveling Menus
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if BOTH(HAS_LCD_MENU, AUTO_BED_LEVELING_UBL)
  27. #include "menu_item.h"
  28. #include "../../gcode/gcode.h"
  29. #include "../../gcode/queue.h"
  30. #include "../../module/motion.h"
  31. #include "../../module/planner.h"
  32. #include "../../module/settings.h"
  33. #include "../../feature/bedlevel/bedlevel.h"
  34. static int16_t ubl_storage_slot = 0,
  35. custom_hotend_temp = 190,
  36. side_points = 3,
  37. ubl_fillin_amount = 5,
  38. ubl_height_amount = 1;
  39. static uint8_t n_edit_pts = 1;
  40. static int8_t x_plot = 0, y_plot = 0; // May be negative during move
  41. #if HAS_HEATED_BED
  42. static int16_t custom_bed_temp = 50;
  43. #endif
  44. float mesh_edit_accumulator; // Rounded to 2.5 decimal places on use
  45. inline float rounded_mesh_value() {
  46. const int32_t rounded = int32_t(mesh_edit_accumulator * 1000);
  47. return float(rounded - (rounded % 5L)) / 1000;
  48. }
  49. static void _lcd_mesh_fine_tune(PGM_P const msg) {
  50. ui.defer_status_screen();
  51. if (ubl.encoder_diff) {
  52. mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
  53. ubl.encoder_diff * 0.005f / ENCODER_PULSES_PER_STEP,
  54. ubl.encoder_diff > 0 ? 0.005f : -0.005f
  55. );
  56. ubl.encoder_diff = 0;
  57. IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
  58. }
  59. TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
  60. if (ui.should_draw()) {
  61. const float rounded_f = rounded_mesh_value();
  62. MenuEditItemBase::draw_edit_screen(msg, ftostr43sign(rounded_f));
  63. TERN_(MESH_EDIT_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(rounded_f));
  64. TERN_(HAS_GRAPHICAL_TFT, ui.refresh(LCDVIEW_NONE));
  65. }
  66. }
  67. //
  68. // Called external to the menu system to acquire the result of an edit.
  69. //
  70. float lcd_mesh_edit() { return rounded_mesh_value(); }
  71. void lcd_mesh_edit_setup(const float &initial) {
  72. TERN_(HAS_GRAPHICAL_TFT, ui.clear_lcd());
  73. mesh_edit_accumulator = initial;
  74. ui.goto_screen([]{ _lcd_mesh_fine_tune(GET_TEXT(MSG_MESH_EDIT_Z)); });
  75. }
  76. void _lcd_z_offset_edit() {
  77. _lcd_mesh_fine_tune(GET_TEXT(MSG_UBL_Z_OFFSET));
  78. }
  79. float lcd_z_offset_edit() {
  80. ui.goto_screen(_lcd_z_offset_edit);
  81. return rounded_mesh_value();
  82. }
  83. void lcd_z_offset_edit_setup(const float &initial) {
  84. mesh_edit_accumulator = initial;
  85. ui.goto_screen(_lcd_z_offset_edit);
  86. }
  87. /**
  88. * UBL Build Custom Mesh Command
  89. */
  90. void _lcd_ubl_build_custom_mesh() {
  91. char ubl_lcd_gcode[64];
  92. #if HAS_HEATED_BED
  93. sprintf_P(ubl_lcd_gcode, PSTR("G28\nM190 S%i\nM109 S%i\nG29 P1"), custom_bed_temp, custom_hotend_temp);
  94. #else
  95. sprintf_P(ubl_lcd_gcode, PSTR("G28\nM109 S%i\nG29 P1"), custom_hotend_temp);
  96. #endif
  97. queue.inject(ubl_lcd_gcode);
  98. }
  99. /**
  100. * UBL Custom Mesh submenu
  101. *
  102. * << Build Mesh
  103. * Hotend Temp: ---
  104. * Bed Temp: ---
  105. * Build Custom Mesh
  106. */
  107. void _lcd_ubl_custom_mesh() {
  108. START_MENU();
  109. BACK_ITEM(MSG_UBL_BUILD_MESH_MENU);
  110. #if HAS_HOTEND
  111. EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - HOTEND_OVERSHOOT);
  112. #endif
  113. #if HAS_HEATED_BED
  114. EDIT_ITEM(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, BED_MAX_TARGET);
  115. #endif
  116. ACTION_ITEM(MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  117. END_MENU();
  118. }
  119. /**
  120. * UBL Adjust Mesh Height Command
  121. */
  122. void _lcd_ubl_adjust_height_cmd() {
  123. char ubl_lcd_gcode[16];
  124. const int ind = ubl_height_amount > 0 ? 9 : 10;
  125. strcpy_P(ubl_lcd_gcode, PSTR("G29 P6 C -"));
  126. sprintf_P(&ubl_lcd_gcode[ind], PSTR(".%i"), ABS(ubl_height_amount));
  127. queue.inject(ubl_lcd_gcode);
  128. }
  129. /**
  130. * UBL Adjust Mesh Height submenu
  131. *
  132. * << Edit Mesh
  133. * Height Amount: ---
  134. * Adjust Mesh Height
  135. * << Info Screen
  136. */
  137. void _menu_ubl_height_adjust() {
  138. START_MENU();
  139. BACK_ITEM(MSG_EDIT_MESH);
  140. EDIT_ITEM(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
  141. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  142. END_MENU();
  143. }
  144. /**
  145. * UBL Edit Mesh submenu
  146. *
  147. * << UBL Tools
  148. * Fine Tune All
  149. * Fine Tune Closest
  150. * - Adjust Mesh Height >>
  151. * << Info Screen
  152. */
  153. void _lcd_ubl_edit_mesh() {
  154. START_MENU();
  155. BACK_ITEM(MSG_UBL_TOOLS);
  156. GCODES_ITEM(MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  157. GCODES_ITEM(MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  158. SUBMENU(MSG_UBL_MESH_HEIGHT_ADJUST, _menu_ubl_height_adjust);
  159. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  160. END_MENU();
  161. }
  162. #if ENABLED(G26_MESH_VALIDATION)
  163. /**
  164. * UBL Validate Custom Mesh Command
  165. */
  166. void _lcd_ubl_validate_custom_mesh() {
  167. char ubl_lcd_gcode[24];
  168. sprintf_P(ubl_lcd_gcode, PSTR("G28\nG26 C P H%" PRIi16 TERN_(HAS_HEATED_BED, " B%" PRIi16))
  169. , custom_hotend_temp
  170. #if HAS_HEATED_BED
  171. , custom_bed_temp
  172. #endif
  173. );
  174. queue.inject(ubl_lcd_gcode);
  175. }
  176. /**
  177. * UBL Validate Mesh submenu
  178. *
  179. * << UBL Tools
  180. * Mesh Validation with Material 1 up to 5
  181. * Validate Custom Mesh
  182. * << Info Screen
  183. */
  184. void _lcd_ubl_validate_mesh() {
  185. START_MENU();
  186. BACK_ITEM(MSG_UBL_TOOLS);
  187. #if PREHEAT_COUNT
  188. #if HAS_HEATED_BED
  189. #define VALIDATE_MESH_GCODE_ITEM(M) \
  190. GCODES_ITEM_N_S(M, ui.get_preheat_label(M), MSG_UBL_VALIDATE_MESH_M, PSTR("G28\nG26 C P I" STRINGIFY(M)))
  191. #else
  192. #define VALIDATE_MESH_GCODE_ITEM(M) \
  193. GCODES_ITEM_N_S(M, ui.get_preheat_label(M), MSG_UBL_VALIDATE_MESH_M, PSTR("G28\nG26 C P B0 I" STRINGIFY(M)))
  194. #endif
  195. VALIDATE_MESH_GCODE_ITEM(0);
  196. #if PREHEAT_COUNT > 1
  197. VALIDATE_MESH_GCODE_ITEM(1);
  198. #if PREHEAT_COUNT > 2
  199. VALIDATE_MESH_GCODE_ITEM(2);
  200. #if PREHEAT_COUNT > 3
  201. VALIDATE_MESH_GCODE_ITEM(3);
  202. #if PREHEAT_COUNT > 4
  203. VALIDATE_MESH_GCODE_ITEM(4);
  204. #endif
  205. #endif
  206. #endif
  207. #endif
  208. #endif // PREHEAT_COUNT
  209. ACTION_ITEM(MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  210. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  211. END_MENU();
  212. }
  213. #endif
  214. /**
  215. * UBL Grid Leveling submenu
  216. *
  217. * << UBL Tools
  218. * Side points: ---
  219. * Level Mesh
  220. */
  221. void _lcd_ubl_grid_level() {
  222. START_MENU();
  223. BACK_ITEM(MSG_UBL_TOOLS);
  224. EDIT_ITEM(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  225. ACTION_ITEM(MSG_UBL_MESH_LEVEL, []{
  226. char ubl_lcd_gcode[12];
  227. sprintf_P(ubl_lcd_gcode, PSTR("G29 J%i"), side_points);
  228. queue.inject(ubl_lcd_gcode);
  229. });
  230. END_MENU();
  231. }
  232. /**
  233. * UBL Mesh Leveling submenu
  234. *
  235. * << UBL Tools
  236. * 3-Point Mesh Leveling
  237. * - Grid Mesh Leveling >>
  238. * << Info Screen
  239. */
  240. void _lcd_ubl_mesh_leveling() {
  241. START_MENU();
  242. BACK_ITEM(MSG_UBL_TOOLS);
  243. GCODES_ITEM(MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  244. SUBMENU(MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  245. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  246. END_MENU();
  247. }
  248. /**
  249. * UBL Fill-in Amount Mesh Command
  250. */
  251. void _lcd_ubl_fillin_amount_cmd() {
  252. char ubl_lcd_gcode[18];
  253. sprintf_P(ubl_lcd_gcode, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  254. gcode.process_subcommands_now(ubl_lcd_gcode);
  255. }
  256. /**
  257. * UBL Fill-in Mesh submenu
  258. *
  259. * << Build Mesh
  260. * Fill-in Amount: ---
  261. * Fill-in Mesh
  262. * Smart Fill-in
  263. * Manual Fill-in
  264. * << Info Screen
  265. */
  266. void _menu_ubl_fillin() {
  267. START_MENU();
  268. BACK_ITEM(MSG_UBL_BUILD_MESH_MENU);
  269. EDIT_ITEM(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
  270. GCODES_ITEM(MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
  271. GCODES_ITEM(MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  272. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  273. END_MENU();
  274. }
  275. void _lcd_ubl_invalidate() {
  276. ubl.invalidate();
  277. SERIAL_ECHOLNPGM("Mesh invalidated.");
  278. }
  279. /**
  280. * UBL Build Mesh submenu
  281. *
  282. * << UBL Tools
  283. * Build Mesh with Material 1 up to 5
  284. * - Build Custom Mesh >>
  285. * Build Cold Mesh
  286. * - Fill-in Mesh >>
  287. * Continue Bed Mesh
  288. * Invalidate All
  289. * Invalidate Closest
  290. * << Info Screen
  291. */
  292. void _lcd_ubl_build_mesh() {
  293. START_MENU();
  294. BACK_ITEM(MSG_UBL_TOOLS);
  295. #if PREHEAT_COUNT
  296. #if HAS_HEATED_BED
  297. #define PREHEAT_BED_GCODE(M) "M190 I" STRINGIFY(M) "\n"
  298. #else
  299. #define PREHEAT_BED_GCODE(M) ""
  300. #endif
  301. #define BUILD_MESH_GCODE_ITEM(M) GCODES_ITEM_S(ui.get_preheat_label(M), MSG_UBL_BUILD_MESH_M, \
  302. PSTR( \
  303. "G28\n" \
  304. PREHEAT_BED_GCODE(M) \
  305. "M109 I" STRINGIFY(M) "\n" \
  306. "G29 P1\n" \
  307. "M104 S0\n" \
  308. "M140 S0" \
  309. ) )
  310. BUILD_MESH_GCODE_ITEM(0);
  311. #if PREHEAT_COUNT > 1
  312. BUILD_MESH_GCODE_ITEM(1);
  313. #if PREHEAT_COUNT > 2
  314. BUILD_MESH_GCODE_ITEM(2);
  315. #if PREHEAT_COUNT > 3
  316. BUILD_MESH_GCODE_ITEM(3);
  317. #if PREHEAT_COUNT > 4
  318. BUILD_MESH_GCODE_ITEM(4);
  319. #endif
  320. #endif
  321. #endif
  322. #endif
  323. #endif // PREHEAT_COUNT
  324. SUBMENU(MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  325. GCODES_ITEM(MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  326. SUBMENU(MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
  327. GCODES_ITEM(MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  328. ACTION_ITEM(MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  329. GCODES_ITEM(MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  330. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  331. END_MENU();
  332. }
  333. /**
  334. * UBL Load / Save Mesh Commands
  335. */
  336. inline void _lcd_ubl_load_save_cmd(const char loadsave, PGM_P const msg) {
  337. char ubl_lcd_gcode[40];
  338. sprintf_P(ubl_lcd_gcode, PSTR("G29 %c%i\nM117 "), loadsave, ubl_storage_slot);
  339. sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], msg, ubl_storage_slot);
  340. gcode.process_subcommands_now(ubl_lcd_gcode);
  341. }
  342. void _lcd_ubl_load_mesh_cmd() { _lcd_ubl_load_save_cmd('L', GET_TEXT(MSG_MESH_LOADED)); }
  343. void _lcd_ubl_save_mesh_cmd() { _lcd_ubl_load_save_cmd('S', GET_TEXT(MSG_MESH_SAVED)); }
  344. /**
  345. * UBL Mesh Storage submenu
  346. *
  347. * << Unified Bed Leveling
  348. * Memory Slot: ---
  349. * Load Bed Mesh
  350. * Save Bed Mesh
  351. */
  352. void _lcd_ubl_storage_mesh() {
  353. int16_t a = settings.calc_num_meshes();
  354. START_MENU();
  355. BACK_ITEM(MSG_UBL_LEVEL_BED);
  356. if (!WITHIN(ubl_storage_slot, 0, a - 1))
  357. STATIC_ITEM(MSG_UBL_NO_STORAGE);
  358. else {
  359. EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
  360. ACTION_ITEM(MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  361. ACTION_ITEM(MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  362. }
  363. END_MENU();
  364. }
  365. /**
  366. * UBL LCD "radar" map point editing
  367. */
  368. void _lcd_ubl_map_edit_cmd() {
  369. char ubl_lcd_gcode[50], str[10], str2[10];
  370. dtostrf(ubl.mesh_index_to_xpos(x_plot), 0, 2, str);
  371. dtostrf(ubl.mesh_index_to_ypos(y_plot), 0, 2, str2);
  372. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, int(n_edit_pts));
  373. queue.inject(ubl_lcd_gcode);
  374. }
  375. /**
  376. * UBL LCD Map Movement
  377. */
  378. void ubl_map_move_to_xy() {
  379. #if ENABLED(DELTA)
  380. if (current_position.z > delta_clip_start_height) { // Make sure the delta has fully free motion
  381. destination = current_position;
  382. destination.z = delta_clip_start_height;
  383. prepare_internal_fast_move_to_destination(homing_feedrate(Z_AXIS)); // Set current_position from destination
  384. }
  385. #endif
  386. // Set the nozzle position to the mesh point
  387. current_position.set(ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot));
  388. // Use the built-in manual move handler
  389. ui.manual_move.soon(ALL_AXES);
  390. }
  391. inline int32_t grid_index(const uint8_t x, const uint8_t y) {
  392. return (GRID_MAX_POINTS_X) * y + x;
  393. }
  394. /**
  395. * UBL LCD "radar" map
  396. */
  397. void ubl_map_screen() {
  398. // static millis_t next_move = 0;
  399. // const millis_t ms = millis();
  400. uint8_t x, y;
  401. if (ui.first_page) {
  402. // On click send "G29 P4 ..." to edit the Z value
  403. if (ui.use_click()) {
  404. _lcd_ubl_map_edit_cmd();
  405. return;
  406. }
  407. ui.defer_status_screen();
  408. #if IS_KINEMATIC
  409. // Index of the mesh point upon entry
  410. const int32_t old_pos_index = grid_index(x_plot, y_plot);
  411. // Direction from new (unconstrained) encoder value
  412. const int8_t step_dir = int32_t(ui.encoderPosition) < old_pos_index ? -1 : 1;
  413. #endif
  414. do {
  415. // Now, keep the encoder position within range
  416. if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = GRID_MAX_POINTS + TERN(TOUCH_SCREEN, ui.encoderPosition, -1);
  417. if (int32_t(ui.encoderPosition) > GRID_MAX_POINTS - 1) ui.encoderPosition = TERN(TOUCH_SCREEN, ui.encoderPosition - GRID_MAX_POINTS, 0);
  418. // Draw the grid point based on the encoder
  419. x = ui.encoderPosition % (GRID_MAX_POINTS_X);
  420. y = ui.encoderPosition / (GRID_MAX_POINTS_X);
  421. // Validate if needed
  422. #if IS_KINEMATIC
  423. const xy_pos_t xy = { ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) };
  424. if (position_is_reachable(xy)) break; // Found a valid point
  425. ui.encoderPosition += step_dir; // Test the next point
  426. #endif
  427. } while(ENABLED(IS_KINEMATIC));
  428. // Determine number of points to edit
  429. #if IS_KINEMATIC
  430. n_edit_pts = 9; // TODO: Delta accessible edit points
  431. #else
  432. const bool xc = WITHIN(x, 1, GRID_MAX_POINTS_X - 2),
  433. yc = WITHIN(y, 1, GRID_MAX_POINTS_Y - 2);
  434. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  435. #endif
  436. // Refresh is also set by encoder movement
  437. //if (int32_t(ui.encoderPosition) != grid_index(x, y))
  438. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  439. }
  440. // Draw the grid point based on the encoder
  441. x = ui.encoderPosition % (GRID_MAX_POINTS_X);
  442. y = ui.encoderPosition / (GRID_MAX_POINTS_X);
  443. if (ui.should_draw()) ui.ubl_plot(x, y);
  444. // Add a move if needed to match the grid point
  445. if (x != x_plot || y != y_plot) {
  446. x_plot = x; y_plot = y; // The move is always posted, so update the grid point now
  447. ubl_map_move_to_xy(); // Sets up a "manual move"
  448. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); // Clean up a half drawn box
  449. }
  450. }
  451. /**
  452. * UBL LCD "radar" map homing
  453. */
  454. void _ubl_map_screen_homing() {
  455. ui.defer_status_screen();
  456. _lcd_draw_homing();
  457. if (all_axes_homed()) {
  458. ubl.lcd_map_control = true; // Return to the map screen after editing Z
  459. ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
  460. ui.manual_move.menu_scale = 0; // Immediate move
  461. ubl_map_move_to_xy(); // Move to current mesh point
  462. ui.manual_move.menu_scale = 1; // Delayed moves
  463. }
  464. }
  465. /**
  466. * UBL Homing before LCD map
  467. */
  468. void _ubl_goto_map_screen() {
  469. if (planner.movesplanned()) return; // The ACTION_ITEM will do nothing
  470. if (!all_axes_trusted()) {
  471. set_all_unhomed();
  472. queue.inject_P(G28_STR);
  473. }
  474. ui.goto_screen(_ubl_map_screen_homing); // Go to the "Homing" screen
  475. }
  476. /**
  477. * UBL Output map submenu
  478. *
  479. * << Unified Bed Leveling
  480. * Output for Host
  481. * Output for CSV
  482. * Off Printer Backup
  483. */
  484. void _lcd_ubl_output_map() {
  485. START_MENU();
  486. BACK_ITEM(MSG_UBL_LEVEL_BED);
  487. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  488. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  489. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  490. END_MENU();
  491. }
  492. /**
  493. * UBL Tools submenu
  494. *
  495. * << Unified Bed Leveling
  496. * - Build Mesh >>
  497. * - Validate Mesh >>
  498. * - Edit Mesh >>
  499. * - Mesh Leveling >>
  500. */
  501. void _menu_ubl_tools() {
  502. START_MENU();
  503. BACK_ITEM(MSG_UBL_LEVEL_BED);
  504. SUBMENU(MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  505. GCODES_ITEM(MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  506. #if ENABLED(G26_MESH_VALIDATION)
  507. SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  508. #endif
  509. SUBMENU(MSG_EDIT_MESH, _lcd_ubl_edit_mesh);
  510. SUBMENU(MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  511. END_MENU();
  512. }
  513. #if ENABLED(G26_MESH_VALIDATION)
  514. /**
  515. * UBL Step-By-Step submenu
  516. *
  517. * << Unified Bed Leveling
  518. * 1 Build Cold Mesh
  519. * 2 Smart Fill-in
  520. * - 3 Validate Mesh >>
  521. * 4 Fine Tune All
  522. * - 5 Validate Mesh >>
  523. * 6 Fine Tune All
  524. * 7 Save Bed Mesh
  525. */
  526. void _lcd_ubl_step_by_step() {
  527. START_MENU();
  528. BACK_ITEM(MSG_UBL_LEVEL_BED);
  529. GCODES_ITEM(MSG_UBL_1_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  530. GCODES_ITEM(MSG_UBL_2_SMART_FILLIN, PSTR("G29 P3 T0"));
  531. SUBMENU(MSG_UBL_3_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  532. GCODES_ITEM(MSG_UBL_4_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  533. SUBMENU(MSG_UBL_5_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  534. GCODES_ITEM(MSG_UBL_6_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  535. ACTION_ITEM(MSG_UBL_7_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  536. END_MENU();
  537. }
  538. #endif
  539. /**
  540. * UBL System submenu
  541. *
  542. * << Motion
  543. * - Manually Build Mesh >>
  544. * - Activate UBL >>
  545. * - Deactivate UBL >>
  546. * - Step-By-Step UBL >>
  547. * - Mesh Storage >>
  548. * - Output Map >>
  549. * - UBL Tools >>
  550. * - Output UBL Info >>
  551. */
  552. void _lcd_ubl_level_bed() {
  553. START_MENU();
  554. BACK_ITEM(MSG_MOTION);
  555. if (planner.leveling_active)
  556. GCODES_ITEM(MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  557. else
  558. GCODES_ITEM(MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  559. #if ENABLED(G26_MESH_VALIDATION)
  560. SUBMENU(MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  561. #endif
  562. ACTION_ITEM(MSG_UBL_MESH_EDIT, _ubl_goto_map_screen);
  563. SUBMENU(MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  564. SUBMENU(MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  565. SUBMENU(MSG_UBL_TOOLS, _menu_ubl_tools);
  566. GCODES_ITEM(MSG_UBL_INFO_UBL, PSTR("G29 W"));
  567. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  568. editable.decimal = planner.z_fade_height;
  569. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  570. #endif
  571. END_MENU();
  572. }
  573. #endif // HAS_LCD_MENU && AUTO_BED_LEVELING_UBL