My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

menu_ubl.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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_MARLINUI_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 = 150,
  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 bedlevel.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(FSTR_P const fmsg) {
  61. constexpr float mesh_edit_step = 1.0f / 200.0f;
  62. ui.defer_status_screen();
  63. if (bedlevel.encoder_diff) {
  64. mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
  65. bedlevel.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
  66. bedlevel.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_step
  67. );
  68. bedlevel.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(fmsg, ftostr43sign(rounded_f));
  75. TERN_(MESH_EDIT_GFX_OVERLAY, ui.zoffset_overlay(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 (bedlevel.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_F(MSG_MESH_EDIT_Z)); });
  87. }
  88. //
  89. // Get the mesh value within a Z adjustment loop (bedlevel.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, F("G29P4RT"));
  162. GCODES_ITEM(MSG_UBL_FINE_TUNE_CLOSEST, F("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. OPTARG(HAS_HEATED_BED, custom_bed_temp)
  176. );
  177. queue.inject(ubl_lcd_gcode);
  178. }
  179. /**
  180. * UBL Validate Mesh submenu
  181. *
  182. * << UBL Tools
  183. * Mesh Validation with Material 1 up to 5
  184. * Validate Custom Mesh
  185. * << Info Screen
  186. */
  187. void _lcd_ubl_validate_mesh() {
  188. START_MENU();
  189. BACK_ITEM(MSG_UBL_TOOLS);
  190. #if HAS_PREHEAT
  191. #if HAS_HEATED_BED
  192. #define VALIDATE_MESH_GCODE_ITEM(M) \
  193. GCODES_ITEM_N_f(M, ui.get_preheat_label(M), MSG_UBL_VALIDATE_MESH_M, F("G28\nG26CPI" STRINGIFY(M)));
  194. #else
  195. #define VALIDATE_MESH_GCODE_ITEM(M) \
  196. GCODES_ITEM_N_f(M, ui.get_preheat_label(M), MSG_UBL_VALIDATE_MESH_M, F("G28\nG26CPB0I" STRINGIFY(M)));
  197. #endif
  198. REPEAT(PREHEAT_COUNT, VALIDATE_MESH_GCODE_ITEM)
  199. #endif
  200. ACTION_ITEM(MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  201. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  202. END_MENU();
  203. }
  204. #endif
  205. /**
  206. * UBL Grid Leveling submenu
  207. *
  208. * << UBL Tools
  209. * Side points: ---
  210. * Level Mesh
  211. */
  212. void _lcd_ubl_grid_level() {
  213. START_MENU();
  214. BACK_ITEM(MSG_UBL_TOOLS);
  215. EDIT_ITEM(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  216. ACTION_ITEM(MSG_UBL_MESH_LEVEL, []{
  217. char ubl_lcd_gcode[12];
  218. sprintf_P(ubl_lcd_gcode, PSTR("G29J%i"), side_points);
  219. queue.inject(ubl_lcd_gcode);
  220. });
  221. END_MENU();
  222. }
  223. /**
  224. * UBL Mesh Leveling submenu
  225. *
  226. * << UBL Tools
  227. * 3-Point Mesh Leveling
  228. * - Grid Mesh Leveling >>
  229. * << Info Screen
  230. */
  231. void _lcd_ubl_mesh_leveling() {
  232. START_MENU();
  233. BACK_ITEM(MSG_UBL_TOOLS);
  234. GCODES_ITEM(MSG_UBL_3POINT_MESH_LEVELING, F("G29J0"));
  235. SUBMENU(MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  236. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  237. END_MENU();
  238. }
  239. /**
  240. * UBL Fill-in Amount Mesh Command
  241. */
  242. void _lcd_ubl_fillin_amount_cmd() {
  243. char ubl_lcd_gcode[18];
  244. sprintf_P(ubl_lcd_gcode, PSTR("G29P3RC.%i"), ubl_fillin_amount);
  245. gcode.process_subcommands_now(ubl_lcd_gcode);
  246. }
  247. /**
  248. * UBL Fill-in Mesh submenu
  249. *
  250. * << Build Mesh
  251. * Fill-in Amount: ---
  252. * Fill-in Mesh
  253. * Smart Fill-in
  254. * Manual Fill-in
  255. * << Info Screen
  256. */
  257. void _menu_ubl_fillin() {
  258. START_MENU();
  259. BACK_ITEM(MSG_UBL_BUILD_MESH_MENU);
  260. EDIT_ITEM(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
  261. GCODES_ITEM(MSG_UBL_SMART_FILLIN, F("G29P3T0"));
  262. GCODES_ITEM(MSG_UBL_MANUAL_FILLIN, F("G29P2BT0"));
  263. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  264. END_MENU();
  265. }
  266. void _lcd_ubl_invalidate() {
  267. bedlevel.invalidate();
  268. SERIAL_ECHOLNPGM("Mesh invalidated.");
  269. }
  270. /**
  271. * UBL Build Mesh submenu
  272. *
  273. * << UBL Tools
  274. * Build Mesh with Material 1 up to 5
  275. * - Build Custom Mesh >>
  276. * Build Cold Mesh
  277. * - Fill-in Mesh >>
  278. * Continue Bed Mesh
  279. * Invalidate All
  280. * Invalidate Closest
  281. * << Info Screen
  282. */
  283. void _lcd_ubl_build_mesh() {
  284. START_MENU();
  285. BACK_ITEM(MSG_UBL_TOOLS);
  286. #if HAS_PREHEAT
  287. #define PREHEAT_BED_GCODE(M) TERN(HAS_HEATED_BED, "M190I" STRINGIFY(M) "\n", "")
  288. #define BUILD_MESH_GCODE_ITEM(M) GCODES_ITEM_f(ui.get_preheat_label(M), MSG_UBL_BUILD_MESH_M, \
  289. F( \
  290. "G28\n" \
  291. PREHEAT_BED_GCODE(M) \
  292. "M109I" STRINGIFY(M) "\n" \
  293. "G29P1\n" \
  294. "M104S0\n" \
  295. "M140S0" \
  296. ) );
  297. REPEAT(PREHEAT_COUNT, BUILD_MESH_GCODE_ITEM)
  298. #endif // HAS_PREHEAT
  299. SUBMENU(MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  300. GCODES_ITEM(MSG_UBL_BUILD_COLD_MESH, F("G29NP1"));
  301. SUBMENU(MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
  302. GCODES_ITEM(MSG_UBL_CONTINUE_MESH, F("G29P1C"));
  303. ACTION_ITEM(MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  304. GCODES_ITEM(MSG_UBL_INVALIDATE_CLOSEST, F("G29I"));
  305. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  306. END_MENU();
  307. }
  308. /**
  309. * UBL Load / Save Mesh Commands
  310. */
  311. inline void _lcd_ubl_load_save_cmd(const char loadsave, FSTR_P const fmsg) {
  312. char ubl_lcd_gcode[40];
  313. sprintf_P(ubl_lcd_gcode, PSTR("G29%c%i\nM117 "), loadsave, ubl_storage_slot);
  314. sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], FTOP(fmsg), ubl_storage_slot);
  315. gcode.process_subcommands_now(ubl_lcd_gcode);
  316. }
  317. void _lcd_ubl_load_mesh_cmd() { _lcd_ubl_load_save_cmd('L', GET_TEXT_F(MSG_MESH_LOADED)); }
  318. void _lcd_ubl_save_mesh_cmd() { _lcd_ubl_load_save_cmd('S', GET_TEXT_F(MSG_MESH_SAVED)); }
  319. /**
  320. * UBL Mesh Storage submenu
  321. *
  322. * << Unified Bed Leveling
  323. * Memory Slot: ---
  324. * Load Bed Mesh
  325. * Save Bed Mesh
  326. */
  327. void _lcd_ubl_storage_mesh() {
  328. int16_t a = settings.calc_num_meshes();
  329. START_MENU();
  330. BACK_ITEM(MSG_UBL_LEVEL_BED);
  331. if (!WITHIN(ubl_storage_slot, 0, a - 1))
  332. STATIC_ITEM(MSG_UBL_NO_STORAGE);
  333. else {
  334. EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
  335. ACTION_ITEM(MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  336. ACTION_ITEM(MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  337. }
  338. END_MENU();
  339. }
  340. /**
  341. * UBL LCD "radar" map point editing
  342. */
  343. void _lcd_ubl_map_edit_cmd() {
  344. char ubl_lcd_gcode[50], str[10], str2[10];
  345. dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str);
  346. dtostrf(bedlevel.get_mesh_y(y_plot), 0, 2, str2);
  347. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
  348. queue.inject(ubl_lcd_gcode);
  349. }
  350. /**
  351. * UBL LCD Map Movement
  352. */
  353. void ubl_map_move_to_xy() {
  354. const xy_pos_t xy = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) };
  355. // Some printers have unreachable areas in the mesh. Skip the move if unreachable.
  356. if (!position_is_reachable(xy)) return;
  357. #if ENABLED(DELTA)
  358. if (current_position.z > delta_clip_start_height) { // Make sure the delta has fully free motion
  359. destination = current_position;
  360. destination.z = delta_clip_start_height;
  361. prepare_internal_fast_move_to_destination(homing_feedrate(Z_AXIS)); // Set current_position from destination
  362. }
  363. #endif
  364. // Use the built-in manual move handler to move to the mesh point.
  365. ui.manual_move.set_destination(xy);
  366. ui.manual_move.soon(ALL_AXES_ENUM);
  367. }
  368. inline int32_t grid_index(const uint8_t x, const uint8_t y) {
  369. return (GRID_MAX_POINTS_X) * y + x;
  370. }
  371. /**
  372. * UBL LCD "radar" map
  373. */
  374. void ubl_map_screen() {
  375. // static millis_t next_move = 0;
  376. // const millis_t ms = millis();
  377. uint8_t x, y;
  378. if (ui.first_page) {
  379. // On click send "G29 P4 ..." to edit the Z value
  380. if (ui.use_click()) {
  381. _lcd_ubl_map_edit_cmd();
  382. return;
  383. }
  384. ui.defer_status_screen();
  385. #if IS_KINEMATIC
  386. // Index of the mesh point upon entry
  387. const int32_t old_pos_index = grid_index(x_plot, y_plot);
  388. // Direction from new (unconstrained) encoder value
  389. const int8_t step_dir = int32_t(ui.encoderPosition) < old_pos_index ? -1 : 1;
  390. #endif
  391. do {
  392. // Now, keep the encoder position within range
  393. if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = GRID_MAX_POINTS + TERN(TOUCH_SCREEN, ui.encoderPosition, -1);
  394. if (int32_t(ui.encoderPosition) > GRID_MAX_POINTS - 1) ui.encoderPosition = TERN(TOUCH_SCREEN, ui.encoderPosition - GRID_MAX_POINTS, 0);
  395. // Draw the grid point based on the encoder
  396. x = ui.encoderPosition % (GRID_MAX_POINTS_X);
  397. y = ui.encoderPosition / (GRID_MAX_POINTS_X);
  398. // Validate if needed
  399. #if IS_KINEMATIC
  400. const xy_pos_t xy = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
  401. if (position_is_reachable(xy)) break; // Found a valid point
  402. ui.encoderPosition += step_dir; // Test the next point
  403. #endif
  404. } while (ENABLED(IS_KINEMATIC));
  405. // Determine number of points to edit
  406. #if IS_KINEMATIC
  407. n_edit_pts = 9; // TODO: Delta accessible edit points
  408. #else
  409. const bool xc = WITHIN(x, 1, (GRID_MAX_POINTS_X) - 2),
  410. yc = WITHIN(y, 1, (GRID_MAX_POINTS_Y) - 2);
  411. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  412. #endif
  413. // Refresh is also set by encoder movement
  414. //if (int32_t(ui.encoderPosition) != grid_index(x, y))
  415. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  416. }
  417. // Draw the grid point based on the encoder
  418. x = ui.encoderPosition % (GRID_MAX_POINTS_X);
  419. y = ui.encoderPosition / (GRID_MAX_POINTS_X);
  420. if (ui.should_draw()) ui.ubl_plot(x, y);
  421. // Add a move if needed to match the grid point
  422. if (x != x_plot || y != y_plot) {
  423. x_plot = x; y_plot = y; // The move is always posted, so update the grid point now
  424. ubl_map_move_to_xy(); // Sets up a "manual move"
  425. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); // Clean up a half drawn box
  426. }
  427. }
  428. /**
  429. * UBL LCD "radar" map homing
  430. */
  431. void _ubl_map_screen_homing() {
  432. ui.defer_status_screen();
  433. _lcd_draw_homing();
  434. if (all_axes_homed()) {
  435. bedlevel.lcd_map_control = true; // Return to the map screen after editing Z
  436. ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
  437. ui.manual_move.menu_scale = 0; // Immediate move
  438. ubl_map_move_to_xy(); // Move to current mesh point
  439. ui.manual_move.menu_scale = 1; // Delayed moves
  440. }
  441. }
  442. /**
  443. * UBL Homing before LCD map
  444. */
  445. void _ubl_goto_map_screen() {
  446. if (planner.movesplanned()) return; // The ACTION_ITEM will do nothing
  447. if (!all_axes_trusted()) {
  448. set_all_unhomed();
  449. queue.inject_P(G28_STR);
  450. }
  451. ui.goto_screen(_ubl_map_screen_homing); // Go to the "Homing" screen
  452. }
  453. /**
  454. * UBL Output map submenu
  455. *
  456. * << Unified Bed Leveling
  457. * Output for Host
  458. * Output for CSV
  459. * Off Printer Backup
  460. */
  461. void _lcd_ubl_output_map() {
  462. START_MENU();
  463. BACK_ITEM(MSG_UBL_LEVEL_BED);
  464. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_HOST, F("G29T0"));
  465. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_CSV, F("G29T1"));
  466. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_BACKUP, F("G29S-1"));
  467. END_MENU();
  468. }
  469. /**
  470. * UBL Tools submenu
  471. *
  472. * << Unified Bed Leveling
  473. * - Build Mesh >>
  474. * - Validate Mesh >>
  475. * - Edit Mesh >>
  476. * - Mesh Leveling >>
  477. */
  478. void _menu_ubl_tools() {
  479. START_MENU();
  480. BACK_ITEM(MSG_UBL_LEVEL_BED);
  481. SUBMENU(MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  482. GCODES_ITEM(MSG_UBL_MANUAL_MESH, F("G29I999\nG29P2BT0"));
  483. #if ENABLED(G26_MESH_VALIDATION)
  484. SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  485. #endif
  486. SUBMENU(MSG_EDIT_MESH, _lcd_ubl_edit_mesh);
  487. SUBMENU(MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  488. END_MENU();
  489. }
  490. #if ENABLED(G26_MESH_VALIDATION)
  491. /**
  492. * UBL Step-By-Step submenu
  493. *
  494. * << Unified Bed Leveling
  495. * 1 Build Cold Mesh
  496. * 2 Smart Fill-in
  497. * - 3 Validate Mesh >>
  498. * 4 Fine Tune All
  499. * - 5 Validate Mesh >>
  500. * 6 Fine Tune All
  501. * 7 Save Bed Mesh
  502. */
  503. void _lcd_ubl_step_by_step() {
  504. START_MENU();
  505. BACK_ITEM(MSG_UBL_LEVEL_BED);
  506. GCODES_ITEM(MSG_UBL_1_BUILD_COLD_MESH, F("G29NP1"));
  507. GCODES_ITEM(MSG_UBL_2_SMART_FILLIN, F("G29P3T0"));
  508. SUBMENU(MSG_UBL_3_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  509. GCODES_ITEM(MSG_UBL_4_FINE_TUNE_ALL, F("G29P4RT"));
  510. SUBMENU(MSG_UBL_5_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  511. GCODES_ITEM(MSG_UBL_6_FINE_TUNE_ALL, F("G29P4RT"));
  512. ACTION_ITEM(MSG_UBL_7_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  513. END_MENU();
  514. }
  515. #endif
  516. #if ENABLED(UBL_MESH_WIZARD)
  517. /**
  518. * UBL Mesh Wizard - One-click mesh creation with or without a probe
  519. */
  520. void _lcd_ubl_mesh_wizard() {
  521. char ubl_lcd_gcode[30];
  522. #if HAS_HEATED_BED && HAS_HOTEND
  523. sprintf_P(ubl_lcd_gcode, PSTR("M1004B%iH%iS%i"), custom_bed_temp, custom_hotend_temp, ubl_storage_slot);
  524. #elif HAS_HOTEND
  525. sprintf_P(ubl_lcd_gcode, PSTR("M1004H%iS%i"), custom_hotend_temp, ubl_storage_slot);
  526. #else
  527. sprintf_P(ubl_lcd_gcode, PSTR("M1004S%i"), ubl_storage_slot);
  528. #endif
  529. queue.inject(ubl_lcd_gcode);
  530. ui.return_to_status();
  531. }
  532. void _menu_ubl_mesh_wizard() {
  533. const int16_t total_slots = settings.calc_num_meshes();
  534. START_MENU();
  535. BACK_ITEM(MSG_UBL_LEVEL_BED);
  536. #if HAS_HOTEND
  537. EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, HEATER_0_MINTEMP + 20, thermalManager.hotend_max_target(0));
  538. #endif
  539. #if HAS_HEATED_BED
  540. EDIT_ITEM(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP + 20, BED_MAX_TARGET);
  541. #endif
  542. EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, total_slots);
  543. ACTION_ITEM(MSG_UBL_MESH_WIZARD, _lcd_ubl_mesh_wizard);
  544. #if ENABLED(G26_MESH_VALIDATION)
  545. SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  546. #endif
  547. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  548. END_MENU();
  549. }
  550. #endif
  551. /**
  552. * UBL System submenu
  553. *
  554. * << Motion
  555. * - Manually Build Mesh >>
  556. * - Activate UBL >>
  557. * - Deactivate UBL >>
  558. * - Step-By-Step UBL >>
  559. * - Mesh Storage >>
  560. * - Output Map >>
  561. * - UBL Tools >>
  562. * - Output UBL Info >>
  563. */
  564. void _lcd_ubl_level_bed() {
  565. START_MENU();
  566. BACK_ITEM(MSG_MOTION);
  567. if (planner.leveling_active)
  568. GCODES_ITEM(MSG_UBL_DEACTIVATE_MESH, F("G29D"));
  569. else
  570. GCODES_ITEM(MSG_UBL_ACTIVATE_MESH, F("G29A"));
  571. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  572. editable.decimal = planner.z_fade_height;
  573. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  574. #endif
  575. #if ENABLED(G26_MESH_VALIDATION)
  576. SUBMENU(MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  577. #endif
  578. #if ENABLED(UBL_MESH_WIZARD)
  579. SUBMENU(MSG_UBL_MESH_WIZARD, _menu_ubl_mesh_wizard);
  580. #endif
  581. ACTION_ITEM(MSG_UBL_MESH_EDIT, _ubl_goto_map_screen);
  582. SUBMENU(MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  583. SUBMENU(MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  584. SUBMENU(MSG_UBL_TOOLS, _menu_ubl_tools);
  585. GCODES_ITEM(MSG_UBL_INFO_UBL, F("G29W"));
  586. END_MENU();
  587. }
  588. #endif // HAS_MARLINUI_MENU && AUTO_BED_LEVELING_UBL