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_bed_leveling.cpp 8.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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. // Bed Leveling Menus
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if ENABLED(LCD_BED_LEVELING)
  27. #include "menu.h"
  28. #include "../../module/planner.h"
  29. #include "../../feature/bedlevel/bedlevel.h"
  30. #if HAS_BED_PROBE && DISABLED(BABYSTEP_ZPROBE_OFFSET)
  31. #include "../../module/probe.h"
  32. #endif
  33. #if EITHER(PROBE_MANUALLY, MESH_BED_LEVELING)
  34. #include "../../module/motion.h"
  35. #include "../../gcode/queue.h"
  36. //
  37. // Motion > Level Bed handlers
  38. //
  39. static uint8_t manual_probe_index;
  40. // LCD probed points are from defaults
  41. constexpr uint8_t total_probe_points = (
  42. #if ENABLED(AUTO_BED_LEVELING_3POINT)
  43. 3
  44. #elif ABL_GRID || ENABLED(MESH_BED_LEVELING)
  45. GRID_MAX_POINTS
  46. #endif
  47. );
  48. bool MarlinUI::wait_for_bl_move; // = false
  49. //
  50. // Bed leveling is done. Wait for G29 to complete.
  51. // A flag is used so that this can release control
  52. // and allow the command queue to be processed.
  53. //
  54. // When G29 finishes the last move:
  55. // - Raise Z to the "manual probe height"
  56. // - Don't return until done.
  57. //
  58. // ** This blocks the command queue! **
  59. //
  60. void _lcd_level_bed_done() {
  61. if (!ui.wait_for_bl_move) {
  62. #if MANUAL_PROBE_HEIGHT > 0 && DISABLED(MESH_BED_LEVELING)
  63. // Display "Done" screen and wait for moves to complete
  64. line_to_z(MANUAL_PROBE_HEIGHT);
  65. ui.synchronize(GET_TEXT(MSG_LEVEL_BED_DONE));
  66. #endif
  67. ui.goto_previous_screen_no_defer();
  68. #if HAS_BUZZER
  69. ui.completion_feedback();
  70. #endif
  71. }
  72. if (ui.should_draw()) draw_menu_item_static(LCD_HEIGHT >= 4 ? 1 : 0, GET_TEXT(MSG_LEVEL_BED_DONE));
  73. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  74. }
  75. void _lcd_level_goto_next_point();
  76. //
  77. // Step 7: Get the Z coordinate, click goes to the next point or exits
  78. //
  79. void _lcd_level_bed_get_z() {
  80. if (ui.use_click()) {
  81. //
  82. // Save the current Z position and move
  83. //
  84. // If done...
  85. if (++manual_probe_index >= total_probe_points) {
  86. //
  87. // The last G29 records the point and enables bed leveling
  88. //
  89. ui.wait_for_bl_move = true;
  90. ui.goto_screen(_lcd_level_bed_done);
  91. #if ENABLED(MESH_BED_LEVELING)
  92. queue.inject_P(PSTR("G29 S2"));
  93. #elif ENABLED(PROBE_MANUALLY)
  94. queue.inject_P(PSTR("G29 V1"));
  95. #endif
  96. }
  97. else
  98. _lcd_level_goto_next_point();
  99. return;
  100. }
  101. //
  102. // Encoder knob or keypad buttons adjust the Z position
  103. //
  104. if (ui.encoderPosition) {
  105. const float z = current_position.z + float(int16_t(ui.encoderPosition)) * (MESH_EDIT_Z_STEP);
  106. line_to_z(constrain(z, -(LCD_PROBE_Z_RANGE) * 0.5f, (LCD_PROBE_Z_RANGE) * 0.5f));
  107. ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
  108. ui.encoderPosition = 0;
  109. }
  110. //
  111. // Draw on first display, then only on Z change
  112. //
  113. if (ui.should_draw()) {
  114. const float v = current_position.z;
  115. draw_edit_screen(GET_TEXT(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001f : 0.0001f), '+'));
  116. }
  117. }
  118. //
  119. // Step 6: Display "Next point: 1 / 9" while waiting for move to finish
  120. //
  121. void _lcd_level_bed_moving() {
  122. if (ui.should_draw()) {
  123. char msg[10];
  124. sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
  125. draw_edit_screen(GET_TEXT(MSG_LEVEL_BED_NEXT_POINT), msg);
  126. }
  127. ui.refresh(LCDVIEW_CALL_NO_REDRAW);
  128. if (!ui.wait_for_bl_move) ui.goto_screen(_lcd_level_bed_get_z);
  129. }
  130. //
  131. // Step 5: Initiate a move to the next point
  132. //
  133. void _lcd_level_goto_next_point() {
  134. ui.goto_screen(_lcd_level_bed_moving);
  135. // G29 Records Z, moves, and signals when it pauses
  136. ui.wait_for_bl_move = true;
  137. #if ENABLED(MESH_BED_LEVELING)
  138. queue.inject_P(manual_probe_index ? PSTR("G29 S2") : PSTR("G29 S1"));
  139. #elif ENABLED(PROBE_MANUALLY)
  140. queue.inject_P(PSTR("G29 V1"));
  141. #endif
  142. }
  143. //
  144. // Step 4: Display "Click to Begin", wait for click
  145. // Move to the first probe position
  146. //
  147. void _lcd_level_bed_homing_done() {
  148. if (ui.should_draw()) draw_edit_screen(GET_TEXT(MSG_LEVEL_BED_WAITING));
  149. if (ui.use_click()) {
  150. manual_probe_index = 0;
  151. _lcd_level_goto_next_point();
  152. }
  153. }
  154. //
  155. // Step 3: Display "Homing XYZ" - Wait for homing to finish
  156. //
  157. void _lcd_level_bed_homing() {
  158. _lcd_draw_homing();
  159. if (all_axes_homed()) ui.goto_screen(_lcd_level_bed_homing_done);
  160. }
  161. #if ENABLED(PROBE_MANUALLY)
  162. extern bool g29_in_progress;
  163. #endif
  164. //
  165. // Step 2: Continue Bed Leveling...
  166. //
  167. void _lcd_level_bed_continue() {
  168. ui.defer_status_screen();
  169. set_all_unhomed();
  170. ui.goto_screen(_lcd_level_bed_homing);
  171. queue.inject_P(PSTR("G28"));
  172. }
  173. #endif // PROBE_MANUALLY || MESH_BED_LEVELING
  174. #if ENABLED(MESH_EDIT_MENU)
  175. inline void refresh_planner() {
  176. set_current_from_steppers_for_axis(ALL_AXES);
  177. sync_plan_position();
  178. }
  179. void menu_edit_mesh() {
  180. static uint8_t xind, yind; // =0
  181. START_MENU();
  182. BACK_ITEM(MSG_BED_LEVELING);
  183. EDIT_ITEM(uint8, MSG_MESH_X, &xind, 0, GRID_MAX_POINTS_X - 1);
  184. EDIT_ITEM(uint8, MSG_MESH_Y, &yind, 0, GRID_MAX_POINTS_Y - 1);
  185. EDIT_ITEM_FAST(float43, MSG_MESH_EDIT_Z, &Z_VALUES(xind, yind), -(LCD_PROBE_Z_RANGE) * 0.5, (LCD_PROBE_Z_RANGE) * 0.5, refresh_planner);
  186. END_MENU();
  187. }
  188. #endif // MESH_EDIT_MENU
  189. /**
  190. * Step 1: Bed Level entry-point
  191. *
  192. * << Motion
  193. * Auto Home (if homing needed)
  194. * Leveling On/Off (if data exists, and homed)
  195. * Fade Height: --- (Req: ENABLE_LEVELING_FADE_HEIGHT)
  196. * Mesh Z Offset: --- (Req: MESH_BED_LEVELING)
  197. * Z Probe Offset: --- (Req: HAS_BED_PROBE, Opt: BABYSTEP_ZPROBE_OFFSET)
  198. * Level Bed >
  199. * Level Corners > (if homed)
  200. * Load Settings (Req: EEPROM_SETTINGS)
  201. * Save Settings (Req: EEPROM_SETTINGS)
  202. */
  203. void menu_bed_leveling() {
  204. START_MENU();
  205. BACK_ITEM(MSG_MOTION);
  206. const bool is_homed = all_axes_known();
  207. // Auto Home if not using manual probing
  208. #if NONE(PROBE_MANUALLY, MESH_BED_LEVELING)
  209. if (!is_homed) GCODES_ITEM(MSG_AUTO_HOME, PSTR("G28"));
  210. #endif
  211. // Level Bed
  212. #if EITHER(PROBE_MANUALLY, MESH_BED_LEVELING)
  213. // Manual leveling uses a guided procedure
  214. SUBMENU(MSG_LEVEL_BED, _lcd_level_bed_continue);
  215. #else
  216. // Automatic leveling can just run the G-code
  217. GCODES_ITEM(MSG_LEVEL_BED, is_homed ? PSTR("G29") : PSTR("G28\nG29"));
  218. #endif
  219. #if ENABLED(MESH_EDIT_MENU)
  220. if (leveling_is_valid())
  221. SUBMENU(MSG_EDIT_MESH, menu_edit_mesh);
  222. #endif
  223. // Homed and leveling is valid? Then leveling can be toggled.
  224. if (is_homed && leveling_is_valid()) {
  225. bool show_state = planner.leveling_active;
  226. EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
  227. }
  228. // Z Fade Height
  229. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  230. // Shadow for editing the fade height
  231. editable.decimal = planner.z_fade_height;
  232. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, [](){ set_z_fade_height(editable.decimal); });
  233. #endif
  234. //
  235. // Mesh Bed Leveling Z-Offset
  236. //
  237. #if ENABLED(MESH_BED_LEVELING)
  238. EDIT_ITEM(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
  239. #endif
  240. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  241. SUBMENU(MSG_ZPROBE_ZOFFSET, lcd_babystep_zoffset);
  242. #elif HAS_BED_PROBE
  243. EDIT_ITEM(float52, MSG_ZPROBE_ZOFFSET, &probe_offset.z, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
  244. #endif
  245. #if ENABLED(LEVEL_BED_CORNERS)
  246. SUBMENU(MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  247. #endif
  248. #if ENABLED(EEPROM_SETTINGS)
  249. ACTION_ITEM(MSG_LOAD_EEPROM, lcd_load_settings);
  250. ACTION_ITEM(MSG_STORE_EEPROM, lcd_store_settings);
  251. #endif
  252. END_MENU();
  253. }
  254. #endif // LCD_BED_LEVELING