My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

menu_bed_leveling.cpp 8.5KB

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