My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

menu_ubl.cpp 18KB

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