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.3KB

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