My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

menu_ubl.cpp 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. //
  23. // Unified Bed Leveling Menus
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_LCD_MENU && ENABLED(AUTO_BED_LEVELING_UBL)
  27. #include "menu.h"
  28. #include "../../module/planner.h"
  29. #include "../../module/configuration_store.h"
  30. #include "../../feature/bedlevel/bedlevel.h"
  31. static int16_t ubl_storage_slot = 0,
  32. custom_hotend_temp = 190,
  33. side_points = 3,
  34. ubl_fillin_amount = 5,
  35. ubl_height_amount = 1;
  36. static uint8_t n_edit_pts = 1, x_plot = 0, y_plot = 0;
  37. #if HAS_HEATED_BED
  38. static int16_t custom_bed_temp = 50;
  39. #endif
  40. float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
  41. // separate value that doesn't lose precision.
  42. static int16_t ubl_encoderPosition = 0;
  43. static void _lcd_mesh_fine_tune(PGM_P msg) {
  44. ui.defer_status_screen();
  45. if (ubl.encoder_diff) {
  46. ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
  47. ubl.encoder_diff = 0;
  48. mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005f * 0.5f;
  49. mesh_edit_value = mesh_edit_accumulator;
  50. ui.encoderPosition = 0;
  51. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  52. const int32_t rounded = (int32_t)(mesh_edit_value * 1000);
  53. mesh_edit_value = float(rounded - (rounded % 5L)) / 1000;
  54. }
  55. if (ui.should_draw()) {
  56. draw_edit_screen(msg, ftostr43sign(mesh_edit_value));
  57. #if ENABLED(MESH_EDIT_GFX_OVERLAY)
  58. _lcd_zoffset_overlay_gfx(mesh_edit_value);
  59. #endif
  60. }
  61. }
  62. void _lcd_mesh_edit_NOP() {
  63. ui.defer_status_screen();
  64. }
  65. float lcd_mesh_edit() {
  66. ui.goto_screen(_lcd_mesh_edit_NOP);
  67. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  68. _lcd_mesh_fine_tune(PSTR(MSG_MESH_EDITOR));
  69. return mesh_edit_value;
  70. }
  71. void lcd_mesh_edit_setup(const float &initial) {
  72. mesh_edit_value = mesh_edit_accumulator = initial;
  73. ui.goto_screen(_lcd_mesh_edit_NOP);
  74. }
  75. void _lcd_z_offset_edit() {
  76. _lcd_mesh_fine_tune(PSTR(MSG_UBL_Z_OFFSET));
  77. }
  78. float lcd_z_offset_edit() {
  79. ui.goto_screen(_lcd_z_offset_edit);
  80. return mesh_edit_value;
  81. }
  82. void lcd_z_offset_edit_setup(const float &initial) {
  83. mesh_edit_value = mesh_edit_accumulator = initial;
  84. ui.goto_screen(_lcd_z_offset_edit);
  85. }
  86. /**
  87. * UBL Build Custom Mesh Command
  88. */
  89. void _lcd_ubl_build_custom_mesh() {
  90. char ubl_lcd_gcode[20];
  91. queue.inject_P(PSTR("G28"));
  92. #if HAS_HEATED_BED
  93. sprintf_P(ubl_lcd_gcode, PSTR("M190 S%i"), custom_bed_temp);
  94. lcd_enqueue_one_now(ubl_lcd_gcode);
  95. #endif
  96. sprintf_P(ubl_lcd_gcode, PSTR("M109 S%i"), custom_hotend_temp);
  97. lcd_enqueue_one_now(ubl_lcd_gcode);
  98. queue.inject_P(PSTR("G29 P1"));
  99. }
  100. /**
  101. * UBL Custom Mesh submenu
  102. *
  103. * << Build Mesh
  104. * Hotend Temp: ---
  105. * Bed Temp: ---
  106. * Build Custom Mesh
  107. */
  108. void _lcd_ubl_custom_mesh() {
  109. START_MENU();
  110. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  111. MENU_ITEM_EDIT(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
  112. #if HAS_HEATED_BED
  113. MENU_ITEM_EDIT(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 10));
  114. #endif
  115. MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
  116. END_MENU();
  117. }
  118. /**
  119. * UBL Adjust Mesh Height Command
  120. */
  121. void _lcd_ubl_adjust_height_cmd() {
  122. char ubl_lcd_gcode[16];
  123. const int ind = ubl_height_amount > 0 ? 9 : 10;
  124. strcpy_P(ubl_lcd_gcode, PSTR("G29 P6 C -"));
  125. sprintf_P(&ubl_lcd_gcode[ind], PSTR(".%i"), ABS(ubl_height_amount));
  126. lcd_enqueue_one_now(ubl_lcd_gcode);
  127. }
  128. /**
  129. * UBL Adjust Mesh Height submenu
  130. *
  131. * << Edit Mesh
  132. * Height Amount: ---
  133. * Adjust Mesh Height
  134. * << Info Screen
  135. */
  136. void _menu_ubl_height_adjust() {
  137. START_MENU();
  138. MENU_BACK(MSG_EDIT_MESH);
  139. MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
  140. MENU_ITEM(function, MSG_WATCH, ui.return_to_status);
  141. END_MENU();
  142. }
  143. /**
  144. * UBL Edit Mesh submenu
  145. *
  146. * << UBL Tools
  147. * Fine Tune All
  148. * Fine Tune Closest
  149. * - Adjust Mesh Height >>
  150. * << Info Screen
  151. */
  152. void _lcd_ubl_edit_mesh() {
  153. START_MENU();
  154. MENU_BACK(MSG_UBL_TOOLS);
  155. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  156. MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
  157. MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _menu_ubl_height_adjust);
  158. MENU_ITEM(function, MSG_WATCH, ui.return_to_status);
  159. END_MENU();
  160. }
  161. /**
  162. * UBL Validate Custom Mesh Command
  163. */
  164. void _lcd_ubl_validate_custom_mesh() {
  165. char ubl_lcd_gcode[24];
  166. const int temp =
  167. #if HAS_HEATED_BED
  168. custom_bed_temp
  169. #else
  170. 0
  171. #endif
  172. ;
  173. sprintf_P(ubl_lcd_gcode, PSTR("G26 C B%i H%i P"), temp, custom_hotend_temp);
  174. lcd_enqueue_one_now_P(PSTR("G28"));
  175. lcd_enqueue_one_now(ubl_lcd_gcode);
  176. }
  177. /**
  178. * UBL Validate Mesh submenu
  179. *
  180. * << UBL Tools
  181. * Mesh Validation with Material 1
  182. * Mesh Validation with Material 2
  183. * Validate Custom Mesh
  184. * << Info Screen
  185. */
  186. void _lcd_ubl_validate_mesh() {
  187. START_MENU();
  188. MENU_BACK(MSG_UBL_TOOLS);
  189. #if HAS_HEATED_BED
  190. MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M1, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  191. MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M2, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  192. #else
  193. MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M1, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
  194. MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M2, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
  195. #endif
  196. MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
  197. MENU_ITEM(function, MSG_WATCH, ui.return_to_status);
  198. END_MENU();
  199. }
  200. /**
  201. * UBL Grid Leveling Command
  202. */
  203. void _lcd_ubl_grid_level_cmd() {
  204. char ubl_lcd_gcode[12];
  205. sprintf_P(ubl_lcd_gcode, PSTR("G29 J%i"), side_points);
  206. lcd_enqueue_one_now(ubl_lcd_gcode);
  207. }
  208. /**
  209. * UBL Grid Leveling submenu
  210. *
  211. * << UBL Tools
  212. * Side points: ---
  213. * Level Mesh
  214. */
  215. void _lcd_ubl_grid_level() {
  216. START_MENU();
  217. MENU_BACK(MSG_UBL_TOOLS);
  218. MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
  219. MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
  220. END_MENU();
  221. }
  222. /**
  223. * UBL Mesh Leveling submenu
  224. *
  225. * << UBL Tools
  226. * 3-Point Mesh Leveling
  227. * - Grid Mesh Leveling >>
  228. * << Info Screen
  229. */
  230. void _lcd_ubl_mesh_leveling() {
  231. START_MENU();
  232. MENU_BACK(MSG_UBL_TOOLS);
  233. MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
  234. MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
  235. MENU_ITEM(function, MSG_WATCH, ui.return_to_status);
  236. END_MENU();
  237. }
  238. /**
  239. * UBL Fill-in Amount Mesh Command
  240. */
  241. void _lcd_ubl_fillin_amount_cmd() {
  242. char ubl_lcd_gcode[18];
  243. sprintf_P(ubl_lcd_gcode, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
  244. lcd_enqueue_one_now(ubl_lcd_gcode);
  245. }
  246. /**
  247. * UBL Fill-in Mesh submenu
  248. *
  249. * << Build Mesh
  250. * Fill-in Amount: ---
  251. * Fill-in Mesh
  252. * Smart Fill-in
  253. * Manual Fill-in
  254. * << Info Screen
  255. */
  256. void _menu_ubl_fillin() {
  257. START_MENU();
  258. MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
  259. MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
  260. MENU_ITEM(gcode, MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
  261. MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
  262. MENU_ITEM(function, MSG_WATCH, ui.return_to_status);
  263. END_MENU();
  264. }
  265. void _lcd_ubl_invalidate() {
  266. ubl.invalidate();
  267. SERIAL_ECHOLNPGM("Mesh invalidated.");
  268. }
  269. /**
  270. * UBL Build Mesh submenu
  271. *
  272. * << UBL Tools
  273. * Build Mesh with Material 1
  274. * Build Mesh with Material 2
  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. MENU_BACK(MSG_UBL_TOOLS);
  286. #if HAS_HEATED_BED
  287. MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M1, PSTR(
  288. "G28\n"
  289. "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
  290. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  291. "G29 P1\n"
  292. "M104 S0\n"
  293. "M140 S0"
  294. ));
  295. MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M2, PSTR(
  296. "G28\n"
  297. "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
  298. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  299. "G29 P1\n"
  300. "M104 S0\n"
  301. "M140 S0"
  302. ));
  303. #else
  304. MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M1, PSTR(
  305. "G28\n"
  306. "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
  307. "G29 P1\n"
  308. "M104 S0"
  309. ));
  310. MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M2, PSTR(
  311. "G28\n"
  312. "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
  313. "G29 P1\n"
  314. "M104 S0"
  315. ));
  316. #endif
  317. MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
  318. MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  319. MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
  320. MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
  321. MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
  322. MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
  323. MENU_ITEM(function, MSG_WATCH, ui.return_to_status);
  324. END_MENU();
  325. }
  326. /**
  327. * UBL Load Mesh Command
  328. */
  329. void _lcd_ubl_load_mesh_cmd() {
  330. char ubl_lcd_gcode[25];
  331. sprintf_P(ubl_lcd_gcode, PSTR("G29 L%i"), ubl_storage_slot);
  332. lcd_enqueue_one_now(ubl_lcd_gcode);
  333. sprintf_P(ubl_lcd_gcode, PSTR("M117 " MSG_MESH_LOADED), ubl_storage_slot);
  334. lcd_enqueue_one_now(ubl_lcd_gcode);
  335. }
  336. /**
  337. * UBL Save Mesh Command
  338. */
  339. void _lcd_ubl_save_mesh_cmd() {
  340. char ubl_lcd_gcode[25];
  341. sprintf_P(ubl_lcd_gcode, PSTR("G29 S%i"), ubl_storage_slot);
  342. lcd_enqueue_one_now(ubl_lcd_gcode);
  343. sprintf_P(ubl_lcd_gcode, PSTR("M117 " MSG_MESH_SAVED), ubl_storage_slot);
  344. lcd_enqueue_one_now(ubl_lcd_gcode);
  345. }
  346. /**
  347. * UBL Mesh Storage submenu
  348. *
  349. * << Unified Bed Leveling
  350. * Memory Slot: ---
  351. * Load Bed Mesh
  352. * Save Bed Mesh
  353. */
  354. void _lcd_ubl_storage_mesh() {
  355. int16_t a = settings.calc_num_meshes();
  356. START_MENU();
  357. MENU_BACK(MSG_UBL_LEVEL_BED);
  358. if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
  359. STATIC_ITEM(MSG_UBL_NO_STORAGE);
  360. }
  361. else {
  362. MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
  363. MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
  364. MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  365. }
  366. END_MENU();
  367. }
  368. /**
  369. * UBL LCD "radar" map homing
  370. */
  371. void _lcd_ubl_output_map_lcd();
  372. void _lcd_ubl_map_homing() {
  373. ui.defer_status_screen();
  374. _lcd_draw_homing();
  375. if (all_axes_homed()) {
  376. ubl.lcd_map_control = true; // Return to the map screen
  377. ui.goto_screen(_lcd_ubl_output_map_lcd);
  378. }
  379. }
  380. /**
  381. * UBL LCD "radar" map point editing
  382. */
  383. void _lcd_ubl_map_lcd_edit_cmd() {
  384. char ubl_lcd_gcode[50], str[10], str2[10];
  385. dtostrf(ubl.mesh_index_to_xpos(x_plot), 0, 2, str);
  386. dtostrf(ubl.mesh_index_to_ypos(y_plot), 0, 2, str2);
  387. snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29 P4 X%s Y%s R%i"), str, str2, int(n_edit_pts));
  388. lcd_enqueue_one_now(ubl_lcd_gcode);
  389. }
  390. /**
  391. * UBL LCD Map Movement
  392. */
  393. void ubl_map_move_to_xy() {
  394. REMEMBER(fr, feedrate_mm_s, MMM_TO_MMS(XY_PROBE_SPEED));
  395. set_destination_from_current(); // sync destination at the start
  396. #if ENABLED(DELTA)
  397. if (current_position[Z_AXIS] > delta_clip_start_height) {
  398. destination[Z_AXIS] = delta_clip_start_height;
  399. prepare_move_to_destination();
  400. }
  401. #endif
  402. destination[X_AXIS] = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]);
  403. destination[Y_AXIS] = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
  404. prepare_move_to_destination();
  405. }
  406. /**
  407. * UBL LCD "radar" map
  408. */
  409. void set_current_from_steppers_for_axis(const AxisEnum axis);
  410. void sync_plan_position();
  411. void _lcd_do_nothing() {}
  412. void _lcd_hard_stop() {
  413. const screenFunc_t old_screen = ui.currentScreen;
  414. ui.currentScreen = _lcd_do_nothing;
  415. planner.quick_stop();
  416. ui.currentScreen = old_screen;
  417. set_current_from_steppers_for_axis(ALL_AXES);
  418. sync_plan_position();
  419. }
  420. void _lcd_ubl_output_map_lcd() {
  421. static int16_t step_scaler = 0;
  422. if (ui.use_click()) return _lcd_ubl_map_lcd_edit_cmd();
  423. if (ui.encoderPosition) {
  424. step_scaler += int16_t(ui.encoderPosition);
  425. x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
  426. ui.encoderPosition = 0;
  427. ui.refresh(LCDVIEW_REDRAW_NOW);
  428. }
  429. #if IS_KINEMATIC
  430. #define KEEP_LOOPING true // Loop until a valid point is found
  431. #else
  432. #define KEEP_LOOPING false
  433. #endif
  434. do {
  435. // Encoder to the right (++)
  436. if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
  437. if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
  438. // Encoder to the left (--)
  439. if (x_plot < 0) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
  440. if (y_plot < 0) y_plot = GRID_MAX_POINTS_Y - 1;
  441. #if IS_KINEMATIC
  442. const float x = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]),
  443. y = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
  444. if (position_is_reachable(x, y)) break; // Found a valid point
  445. x_plot += (step_scaler < 0) ? -1 : 1;
  446. #endif
  447. } while(KEEP_LOOPING);
  448. // Determine number of points to edit
  449. #if IS_KINEMATIC
  450. n_edit_pts = 9; //TODO: Delta accessible edit points
  451. #else
  452. const bool xc = WITHIN(x_plot, 1, GRID_MAX_POINTS_X - 2),
  453. yc = WITHIN(y_plot, 1, GRID_MAX_POINTS_Y - 2);
  454. n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
  455. #endif
  456. // Cleanup
  457. if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
  458. if (ui.should_draw()) {
  459. ui.ubl_plot(x_plot, y_plot);
  460. if (planner.movesplanned()) // If the nozzle is already moving, cancel the move.
  461. _lcd_hard_stop();
  462. ubl_map_move_to_xy(); // Move to new location
  463. }
  464. }
  465. /**
  466. * UBL Homing before LCD map
  467. */
  468. void _lcd_ubl_output_map_lcd_cmd() {
  469. if (!all_axes_known()) {
  470. set_all_unhomed();
  471. queue.inject_P(PSTR("G28"));
  472. }
  473. ui.goto_screen(_lcd_ubl_map_homing);
  474. }
  475. /**
  476. * UBL Output map submenu
  477. *
  478. * << Unified Bed Leveling
  479. * Output for Host
  480. * Output for CSV
  481. * Off Printer Backup
  482. * Output Mesh Map
  483. */
  484. void _lcd_ubl_output_map() {
  485. START_MENU();
  486. MENU_BACK(MSG_UBL_LEVEL_BED);
  487. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
  488. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
  489. MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
  490. MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
  491. END_MENU();
  492. }
  493. /**
  494. * UBL Tools submenu
  495. *
  496. * << Unified Bed Leveling
  497. * - Build Mesh >>
  498. * - Validate Mesh >>
  499. * - Edit Mesh >>
  500. * - Mesh Leveling >>
  501. */
  502. void _menu_ubl_tools() {
  503. START_MENU();
  504. MENU_BACK(MSG_UBL_LEVEL_BED);
  505. MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
  506. MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
  507. MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  508. MENU_ITEM(submenu, MSG_EDIT_MESH, _lcd_ubl_edit_mesh);
  509. MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
  510. END_MENU();
  511. }
  512. /**
  513. * UBL Step-By-Step submenu
  514. *
  515. * << Unified Bed Leveling
  516. * 1 Build Cold Mesh
  517. * 2 Smart Fill-in
  518. * - 3 Validate Mesh >>
  519. * 4 Fine Tune All
  520. * - 5 Validate Mesh >>
  521. * 6 Fine Tune All
  522. * 7 Save Bed Mesh
  523. */
  524. void _lcd_ubl_step_by_step() {
  525. START_MENU();
  526. MENU_BACK(MSG_UBL_LEVEL_BED);
  527. MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
  528. MENU_ITEM(gcode, "2 " MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
  529. MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  530. MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  531. MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
  532. MENU_ITEM(gcode, "6 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
  533. MENU_ITEM(function, "7 " MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
  534. END_MENU();
  535. }
  536. /**
  537. * UBL System submenu
  538. *
  539. * << Motion
  540. * - Manually Build Mesh >>
  541. * - Activate UBL >>
  542. * - Deactivate UBL >>
  543. * - Step-By-Step UBL >>
  544. * - Mesh Storage >>
  545. * - Output Map >>
  546. * - UBL Tools >>
  547. * - Output UBL Info >>
  548. */
  549. void _lcd_ubl_level_bed() {
  550. START_MENU();
  551. MENU_BACK(MSG_MOTION);
  552. if (planner.leveling_active)
  553. MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
  554. else
  555. MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
  556. MENU_ITEM(submenu, MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
  557. MENU_ITEM(function, MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);
  558. MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
  559. MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
  560. MENU_ITEM(submenu, MSG_UBL_TOOLS, _menu_ubl_tools);
  561. MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
  562. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  563. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &lcd_z_fade_height, 0, 100, _lcd_set_z_fade_height);
  564. #endif
  565. END_MENU();
  566. }
  567. #endif // HAS_LCD_MENU && AUTO_BED_LEVELING_UBL