My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

menu_ubl.cpp 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  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. #if HAS_HEATED_BED
  288. #define PREHEAT_BED_GCODE(M) "M190I" STRINGIFY(M) "\n"
  289. #else
  290. #define PREHEAT_BED_GCODE(M) ""
  291. #endif
  292. #define BUILD_MESH_GCODE_ITEM(M) GCODES_ITEM_f(ui.get_preheat_label(M), MSG_UBL_BUILD_MESH_M, \
  293. F( \
  294. "G28\n" \
  295. PREHEAT_BED_GCODE(M) \
  296. "M109I" STRINGIFY(M) "\n" \
  297. "G29P1\n" \
  298. "M104S0\n" \
  299. "M140S0" \
  300. ) )
  301. BUILD_MESH_GCODE_ITEM(0);
  302. #if PREHEAT_COUNT > 1
  303. BUILD_MESH_GCODE_ITEM(1);
  304. #if PREHEAT_COUNT > 2
  305. BUILD_MESH_GCODE_ITEM(2);
  306. #if PREHEAT_COUNT > 3
  307. BUILD_MESH_GCODE_ITEM(3);
  308. #if PREHEAT_COUNT > 4
  309. BUILD_MESH_GCODE_ITEM(4);
  310. #endif
  311. #endif
  312. #endif
  313. #endif
  314. #endif // HAS_PREHEAT
  315. SUBMENU(MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  316. GCODES_ITEM(MSG_UBL_BUILD_COLD_MESH, F("G29NP1"));
  317. SUBMENU(MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
  318. GCODES_ITEM(MSG_UBL_CONTINUE_MESH, F("G29P1C"));
  319. ACTION_ITEM(MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  320. GCODES_ITEM(MSG_UBL_INVALIDATE_CLOSEST, F("G29I"));
  321. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  322. END_MENU();
  323. }
  324. /**
  325. * UBL Load / Save Mesh Commands
  326. */
  327. inline void _lcd_ubl_load_save_cmd(const char loadsave, FSTR_P const fmsg) {
  328. char ubl_lcd_gcode[40];
  329. sprintf_P(ubl_lcd_gcode, PSTR("G29%c%i\nM117 "), loadsave, ubl_storage_slot);
  330. sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], FTOP(fmsg), ubl_storage_slot);
  331. gcode.process_subcommands_now(ubl_lcd_gcode);
  332. }
  333. void _lcd_ubl_load_mesh_cmd() { _lcd_ubl_load_save_cmd('L', GET_TEXT_F(MSG_MESH_LOADED)); }
  334. void _lcd_ubl_save_mesh_cmd() { _lcd_ubl_load_save_cmd('S', GET_TEXT_F(MSG_MESH_SAVED)); }
  335. /**
  336. * UBL Mesh Storage submenu
  337. *
  338. * << Unified Bed Leveling
  339. * Memory Slot: ---
  340. * Load Bed Mesh
  341. * Save Bed Mesh
  342. */
  343. void _lcd_ubl_storage_mesh() {
  344. int16_t a = settings.calc_num_meshes();
  345. START_MENU();
  346. BACK_ITEM(MSG_UBL_LEVEL_BED);
  347. if (!WITHIN(ubl_storage_slot, 0, a - 1))
  348. STATIC_ITEM(MSG_UBL_NO_STORAGE);
  349. else {
  350. EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
  351. ACTION_ITEM(MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  352. ACTION_ITEM(MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  353. }
  354. END_MENU();
  355. }
  356. /**
  357. * UBL LCD "radar" map point editing
  358. */
  359. void _lcd_ubl_map_edit_cmd() {
  360. char ubl_lcd_gcode[50], str[10], str2[10];
  361. dtostrf(bedlevel.get_mesh_x(x_plot), 0, 2, str);
  362. dtostrf(bedlevel.get_mesh_y(y_plot), 0, 2, str2);
  363. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
  364. queue.inject(ubl_lcd_gcode);
  365. }
  366. /**
  367. * UBL LCD Map Movement
  368. */
  369. void ubl_map_move_to_xy() {
  370. const xy_pos_t xy = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) };
  371. // Some printers have unreachable areas in the mesh. Skip the move if unreachable.
  372. if (!position_is_reachable(xy)) return;
  373. #if ENABLED(DELTA)
  374. if (current_position.z > delta_clip_start_height) { // Make sure the delta has fully free motion
  375. destination = current_position;
  376. destination.z = delta_clip_start_height;
  377. prepare_internal_fast_move_to_destination(homing_feedrate(Z_AXIS)); // Set current_position from destination
  378. }
  379. #endif
  380. // Use the built-in manual move handler to move to the mesh point.
  381. ui.manual_move.set_destination(xy);
  382. ui.manual_move.soon(ALL_AXES_ENUM);
  383. }
  384. inline int32_t grid_index(const uint8_t x, const uint8_t y) {
  385. return (GRID_MAX_POINTS_X) * y + x;
  386. }
  387. /**
  388. * UBL LCD "radar" map
  389. */
  390. void ubl_map_screen() {
  391. // static millis_t next_move = 0;
  392. // const millis_t ms = millis();
  393. uint8_t x, y;
  394. if (ui.first_page) {
  395. // On click send "G29 P4 ..." to edit the Z value
  396. if (ui.use_click()) {
  397. _lcd_ubl_map_edit_cmd();
  398. return;
  399. }
  400. ui.defer_status_screen();
  401. #if IS_KINEMATIC
  402. // Index of the mesh point upon entry
  403. const int32_t old_pos_index = grid_index(x_plot, y_plot);
  404. // Direction from new (unconstrained) encoder value
  405. const int8_t step_dir = int32_t(ui.encoderPosition) < old_pos_index ? -1 : 1;
  406. #endif
  407. do {
  408. // Now, keep the encoder position within range
  409. if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = GRID_MAX_POINTS + TERN(TOUCH_SCREEN, ui.encoderPosition, -1);
  410. if (int32_t(ui.encoderPosition) > GRID_MAX_POINTS - 1) ui.encoderPosition = TERN(TOUCH_SCREEN, ui.encoderPosition - GRID_MAX_POINTS, 0);
  411. // Draw the grid point based on the encoder
  412. x = ui.encoderPosition % (GRID_MAX_POINTS_X);
  413. y = ui.encoderPosition / (GRID_MAX_POINTS_X);
  414. // Validate if needed
  415. #if IS_KINEMATIC
  416. const xy_pos_t xy = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
  417. if (position_is_reachable(xy)) break; // Found a valid point
  418. ui.encoderPosition += step_dir; // Test the next point
  419. #endif
  420. } while (ENABLED(IS_KINEMATIC));
  421. // Determine number of points to edit
  422. #if IS_KINEMATIC
  423. n_edit_pts = 9; // TODO: Delta accessible edit points
  424. #else
  425. const bool xc = WITHIN(x, 1, (GRID_MAX_POINTS_X) - 2),
  426. yc = WITHIN(y, 1, (GRID_MAX_POINTS_Y) - 2);
  427. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  428. #endif
  429. // Refresh is also set by encoder movement
  430. //if (int32_t(ui.encoderPosition) != grid_index(x, y))
  431. // ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  432. }
  433. // Draw the grid point based on the encoder
  434. x = ui.encoderPosition % (GRID_MAX_POINTS_X);
  435. y = ui.encoderPosition / (GRID_MAX_POINTS_X);
  436. if (ui.should_draw()) ui.ubl_plot(x, y);
  437. // Add a move if needed to match the grid point
  438. if (x != x_plot || y != y_plot) {
  439. x_plot = x; y_plot = y; // The move is always posted, so update the grid point now
  440. ubl_map_move_to_xy(); // Sets up a "manual move"
  441. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); // Clean up a half drawn box
  442. }
  443. }
  444. /**
  445. * UBL LCD "radar" map homing
  446. */
  447. void _ubl_map_screen_homing() {
  448. ui.defer_status_screen();
  449. _lcd_draw_homing();
  450. if (all_axes_homed()) {
  451. bedlevel.lcd_map_control = true; // Return to the map screen after editing Z
  452. ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
  453. ui.manual_move.menu_scale = 0; // Immediate move
  454. ubl_map_move_to_xy(); // Move to current mesh point
  455. ui.manual_move.menu_scale = 1; // Delayed moves
  456. }
  457. }
  458. /**
  459. * UBL Homing before LCD map
  460. */
  461. void _ubl_goto_map_screen() {
  462. if (planner.movesplanned()) return; // The ACTION_ITEM will do nothing
  463. if (!all_axes_trusted()) {
  464. set_all_unhomed();
  465. queue.inject_P(G28_STR);
  466. }
  467. ui.goto_screen(_ubl_map_screen_homing); // Go to the "Homing" screen
  468. }
  469. /**
  470. * UBL Output map submenu
  471. *
  472. * << Unified Bed Leveling
  473. * Output for Host
  474. * Output for CSV
  475. * Off Printer Backup
  476. */
  477. void _lcd_ubl_output_map() {
  478. START_MENU();
  479. BACK_ITEM(MSG_UBL_LEVEL_BED);
  480. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_HOST, F("G29T0"));
  481. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_CSV, F("G29T1"));
  482. GCODES_ITEM(MSG_UBL_OUTPUT_MAP_BACKUP, F("G29S-1"));
  483. END_MENU();
  484. }
  485. /**
  486. * UBL Tools submenu
  487. *
  488. * << Unified Bed Leveling
  489. * - Build Mesh >>
  490. * - Validate Mesh >>
  491. * - Edit Mesh >>
  492. * - Mesh Leveling >>
  493. */
  494. void _menu_ubl_tools() {
  495. START_MENU();
  496. BACK_ITEM(MSG_UBL_LEVEL_BED);
  497. SUBMENU(MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  498. GCODES_ITEM(MSG_UBL_MANUAL_MESH, F("G29I999\nG29P2BT0"));
  499. #if ENABLED(G26_MESH_VALIDATION)
  500. SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  501. #endif
  502. SUBMENU(MSG_EDIT_MESH, _lcd_ubl_edit_mesh);
  503. SUBMENU(MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  504. END_MENU();
  505. }
  506. #if ENABLED(G26_MESH_VALIDATION)
  507. /**
  508. * UBL Step-By-Step submenu
  509. *
  510. * << Unified Bed Leveling
  511. * 1 Build Cold Mesh
  512. * 2 Smart Fill-in
  513. * - 3 Validate Mesh >>
  514. * 4 Fine Tune All
  515. * - 5 Validate Mesh >>
  516. * 6 Fine Tune All
  517. * 7 Save Bed Mesh
  518. */
  519. void _lcd_ubl_step_by_step() {
  520. START_MENU();
  521. BACK_ITEM(MSG_UBL_LEVEL_BED);
  522. GCODES_ITEM(MSG_UBL_1_BUILD_COLD_MESH, F("G29NP1"));
  523. GCODES_ITEM(MSG_UBL_2_SMART_FILLIN, F("G29P3T0"));
  524. SUBMENU(MSG_UBL_3_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  525. GCODES_ITEM(MSG_UBL_4_FINE_TUNE_ALL, F("G29P4RT"));
  526. SUBMENU(MSG_UBL_5_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  527. GCODES_ITEM(MSG_UBL_6_FINE_TUNE_ALL, F("G29P4RT"));
  528. ACTION_ITEM(MSG_UBL_7_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  529. END_MENU();
  530. }
  531. #endif
  532. #if ENABLED(UBL_MESH_WIZARD)
  533. /**
  534. * UBL Mesh Wizard - One-click mesh creation with or without a probe
  535. */
  536. void _lcd_ubl_mesh_wizard() {
  537. char ubl_lcd_gcode[30];
  538. #if HAS_HEATED_BED && HAS_HOTEND
  539. sprintf_P(ubl_lcd_gcode, PSTR("M1004B%iH%iS%i"), custom_bed_temp, custom_hotend_temp, ubl_storage_slot);
  540. #elif HAS_HOTEND
  541. sprintf_P(ubl_lcd_gcode, PSTR("M1004H%iS%i"), custom_hotend_temp, ubl_storage_slot);
  542. #else
  543. sprintf_P(ubl_lcd_gcode, PSTR("M1004S%i"), ubl_storage_slot);
  544. #endif
  545. queue.inject(ubl_lcd_gcode);
  546. ui.return_to_status();
  547. }
  548. void _menu_ubl_mesh_wizard() {
  549. const int16_t total_slots = settings.calc_num_meshes();
  550. START_MENU();
  551. BACK_ITEM(MSG_UBL_LEVEL_BED);
  552. #if HAS_HOTEND
  553. EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, HEATER_0_MINTEMP + 20, thermalManager.hotend_max_target(0));
  554. #endif
  555. #if HAS_HEATED_BED
  556. EDIT_ITEM(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP + 20, BED_MAX_TARGET);
  557. #endif
  558. EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, total_slots);
  559. ACTION_ITEM(MSG_UBL_MESH_WIZARD, _lcd_ubl_mesh_wizard);
  560. #if ENABLED(G26_MESH_VALIDATION)
  561. SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  562. #endif
  563. ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
  564. END_MENU();
  565. }
  566. #endif
  567. /**
  568. * UBL System submenu
  569. *
  570. * << Motion
  571. * - Manually Build Mesh >>
  572. * - Activate UBL >>
  573. * - Deactivate UBL >>
  574. * - Step-By-Step UBL >>
  575. * - Mesh Storage >>
  576. * - Output Map >>
  577. * - UBL Tools >>
  578. * - Output UBL Info >>
  579. */
  580. void _lcd_ubl_level_bed() {
  581. START_MENU();
  582. BACK_ITEM(MSG_MOTION);
  583. if (planner.leveling_active)
  584. GCODES_ITEM(MSG_UBL_DEACTIVATE_MESH, F("G29D"));
  585. else
  586. GCODES_ITEM(MSG_UBL_ACTIVATE_MESH, F("G29A"));
  587. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  588. editable.decimal = planner.z_fade_height;
  589. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  590. #endif
  591. #if ENABLED(G26_MESH_VALIDATION)
  592. SUBMENU(MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  593. #endif
  594. #if ENABLED(UBL_MESH_WIZARD)
  595. SUBMENU(MSG_UBL_MESH_WIZARD, _menu_ubl_mesh_wizard);
  596. #endif
  597. ACTION_ITEM(MSG_UBL_MESH_EDIT, _ubl_goto_map_screen);
  598. SUBMENU(MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  599. SUBMENU(MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  600. SUBMENU(MSG_UBL_TOOLS, _menu_ubl_tools);
  601. GCODES_ITEM(MSG_UBL_INFO_UBL, F("G29W"));
  602. END_MENU();
  603. }
  604. #endif // HAS_MARLINUI_MENU && AUTO_BED_LEVELING_UBL