My Marlin configs for Fabrikator Mini and CTC i3 Pro B
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

menu_motion.cpp 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. // Motion Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_LCD_MENU
  27. #define LARGE_BED_TEST ((X_BED_SIZE) >= 1000 || (Y_BED_SIZE) >= 1000)
  28. #include "menu_item.h"
  29. #include "menu_addon.h"
  30. #include "../../module/motion.h"
  31. #include "../../gcode/parser.h" // for inch support
  32. #if ENABLED(DELTA)
  33. #include "../../module/delta.h"
  34. #endif
  35. #if ENABLED(PREVENT_COLD_EXTRUSION)
  36. #include "../../module/temperature.h"
  37. #endif
  38. #if HAS_LEVELING
  39. #include "../../module/planner.h"
  40. #include "../../feature/bedlevel/bedlevel.h"
  41. #endif
  42. #if ENABLED(MANUAL_E_MOVES_RELATIVE)
  43. float manual_move_e_origin = 0;
  44. #endif
  45. //
  46. // "Motion" > "Move Axis" submenu
  47. //
  48. static void _lcd_move_xyz(PGM_P const name, const AxisEnum axis) {
  49. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  50. if (ui.encoderPosition && !ui.manual_move.processing) {
  51. // Get motion limit from software endstops, if any
  52. float min, max;
  53. soft_endstop.get_manual_axis_limits(axis, min, max);
  54. // Delta limits XY based on the current offset from center
  55. // This assumes the center is 0,0
  56. #if ENABLED(DELTA)
  57. if (axis != Z_AXIS) {
  58. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
  59. min = -max;
  60. }
  61. #endif
  62. // Get the new position
  63. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  64. (void)ui.manual_move.apply_diff(axis, diff, min, max);
  65. ui.manual_move.soon(axis);
  66. ui.refresh(LCDVIEW_REDRAW_NOW);
  67. }
  68. ui.encoderPosition = 0;
  69. if (ui.should_draw()) {
  70. const float pos = ui.manual_move.axis_value(axis);
  71. if (parser.using_inch_units()) {
  72. const float imp_pos = LINEAR_UNIT(pos);
  73. MenuEditItemBase::draw_edit_screen(name, ftostr63(imp_pos));
  74. }
  75. else
  76. MenuEditItemBase::draw_edit_screen(name, ui.manual_move.menu_scale >= 0.1f ? (LARGE_BED_TEST ? ftostr51sign(pos) : ftostr41sign(pos)) : ftostr63(pos));
  77. }
  78. }
  79. void lcd_move_x() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_X), X_AXIS); }
  80. #if HAS_Y_AXIS
  81. void lcd_move_y() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_Y), Y_AXIS); }
  82. #endif
  83. #if HAS_Z_AXIS
  84. void lcd_move_z() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_Z), Z_AXIS); }
  85. #endif
  86. #if LINEAR_AXES >= 4
  87. void lcd_move_i() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_I), I_AXIS); }
  88. #endif
  89. #if LINEAR_AXES >= 5
  90. void lcd_move_j() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_J), J_AXIS); }
  91. #endif
  92. #if LINEAR_AXES >= 6
  93. void lcd_move_k() { _lcd_move_xyz(GET_TEXT(MSG_MOVE_K), K_AXIS); }
  94. #endif
  95. #if E_MANUAL
  96. static void lcd_move_e(TERN_(MULTI_E_MANUAL, const int8_t eindex=active_extruder)) {
  97. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  98. if (ui.encoderPosition) {
  99. if (!ui.manual_move.processing) {
  100. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  101. TERN(IS_KINEMATIC, ui.manual_move.offset, current_position.e) += diff;
  102. ui.manual_move.soon(E_AXIS OPTARG(MULTI_E_MANUAL, eindex));
  103. ui.refresh(LCDVIEW_REDRAW_NOW);
  104. }
  105. ui.encoderPosition = 0;
  106. }
  107. if (ui.should_draw()) {
  108. TERN_(MULTI_E_MANUAL, MenuItemBase::init(eindex));
  109. MenuEditItemBase::draw_edit_screen(
  110. GET_TEXT(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
  111. ftostr41sign(current_position.e
  112. PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset)
  113. MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin)
  114. )
  115. );
  116. } // should_draw
  117. }
  118. #endif // E_MANUAL
  119. //
  120. // "Motion" > "Move Xmm" > "Move XYZ" submenu
  121. //
  122. #ifndef FINE_MANUAL_MOVE
  123. #define FINE_MANUAL_MOVE 0.025
  124. #endif
  125. screenFunc_t _manual_move_func_ptr;
  126. void _goto_manual_move(const_float_t scale) {
  127. ui.defer_status_screen();
  128. ui.manual_move.menu_scale = scale;
  129. ui.goto_screen(_manual_move_func_ptr);
  130. }
  131. void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) {
  132. _manual_move_func_ptr = func;
  133. START_MENU();
  134. if (LCD_HEIGHT >= 4) {
  135. switch (axis) {
  136. case X_AXIS: STATIC_ITEM(MSG_MOVE_X, SS_DEFAULT|SS_INVERT); break;
  137. case Y_AXIS: STATIC_ITEM(MSG_MOVE_Y, SS_DEFAULT|SS_INVERT); break;
  138. case Z_AXIS: STATIC_ITEM(MSG_MOVE_Z, SS_DEFAULT|SS_INVERT); break;
  139. default:
  140. TERN_(MANUAL_E_MOVES_RELATIVE, manual_move_e_origin = current_position.e);
  141. STATIC_ITEM(MSG_MOVE_E, SS_DEFAULT|SS_INVERT);
  142. break;
  143. }
  144. }
  145. BACK_ITEM(MSG_MOVE_AXIS);
  146. if (parser.using_inch_units()) {
  147. if (LARGE_BED_TEST) SUBMENU(MSG_MOVE_10IN, []{ _goto_manual_move(IN_TO_MM(1.000f)); });
  148. SUBMENU(MSG_MOVE_01IN, []{ _goto_manual_move(IN_TO_MM(0.100f)); });
  149. SUBMENU(MSG_MOVE_001IN, []{ _goto_manual_move(IN_TO_MM(0.010f)); });
  150. SUBMENU(MSG_MOVE_0001IN, []{ _goto_manual_move(IN_TO_MM(0.001f)); });
  151. }
  152. else {
  153. if (LARGE_BED_TEST) SUBMENU(MSG_MOVE_100MM, []{ _goto_manual_move(100); });
  154. SUBMENU(MSG_MOVE_10MM, []{ _goto_manual_move(10); });
  155. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move( 1); });
  156. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
  157. if (axis == Z_AXIS && (FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f) {
  158. // Determine digits needed right of decimal
  159. constexpr uint8_t digs = !UNEAR_ZERO((FINE_MANUAL_MOVE) * 1000 - int((FINE_MANUAL_MOVE) * 1000)) ? 4 :
  160. !UNEAR_ZERO((FINE_MANUAL_MOVE) * 100 - int((FINE_MANUAL_MOVE) * 100)) ? 3 : 2;
  161. PGM_P const label = GET_TEXT(MSG_MOVE_N_MM);
  162. char tmp[strlen_P(label) + 10 + 1], numstr[10];
  163. sprintf_P(tmp, label, dtostrf(FINE_MANUAL_MOVE, 1, digs, numstr));
  164. #if DISABLED(HAS_GRAPHICAL_TFT)
  165. SUBMENU_P(NUL_STR, []{ _goto_manual_move(float(FINE_MANUAL_MOVE)); });
  166. MENU_ITEM_ADDON_START(0 + ENABLED(HAS_MARLINUI_HD44780));
  167. lcd_put_u8str(tmp);
  168. MENU_ITEM_ADDON_END();
  169. #else
  170. SUBMENU_P(tmp, []{ _goto_manual_move(float(FINE_MANUAL_MOVE)); });
  171. #endif
  172. }
  173. }
  174. END_MENU();
  175. }
  176. #if E_MANUAL
  177. inline void _goto_menu_move_distance_e() {
  178. ui.goto_screen([]{ _menu_move_distance(E_AXIS, []{ lcd_move_e(); }); });
  179. }
  180. inline void _menu_move_distance_e_maybe() {
  181. #if ENABLED(PREVENT_COLD_EXTRUSION)
  182. const bool too_cold = thermalManager.tooColdToExtrude(active_extruder);
  183. if (too_cold) {
  184. ui.goto_screen([]{
  185. MenuItem_confirm::select_screen(
  186. GET_TEXT(MSG_BUTTON_PROCEED), GET_TEXT(MSG_BACK),
  187. _goto_menu_move_distance_e, ui.goto_previous_screen,
  188. GET_TEXT(MSG_HOTEND_TOO_COLD), (const char *)nullptr, PSTR("!")
  189. );
  190. });
  191. return;
  192. }
  193. #endif
  194. _goto_menu_move_distance_e();
  195. }
  196. #endif // E_MANUAL
  197. void menu_move() {
  198. START_MENU();
  199. BACK_ITEM(MSG_MOTION);
  200. #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
  201. EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled);
  202. #endif
  203. if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
  204. if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
  205. SUBMENU(MSG_MOVE_X, []{ _menu_move_distance(X_AXIS, lcd_move_x); });
  206. #if HAS_Y_AXIS
  207. SUBMENU(MSG_MOVE_Y, []{ _menu_move_distance(Y_AXIS, lcd_move_y); });
  208. #endif
  209. }
  210. #if ENABLED(DELTA)
  211. else
  212. ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); });
  213. #endif
  214. #if HAS_Z_AXIS
  215. SUBMENU(MSG_MOVE_Z, []{ _menu_move_distance(Z_AXIS, lcd_move_z); });
  216. #endif
  217. #if LINEAR_AXES >= 4
  218. SUBMENU(MSG_MOVE_I, []{ _menu_move_distance(I_AXIS, lcd_move_i); });
  219. #endif
  220. #if LINEAR_AXES >= 5
  221. SUBMENU(MSG_MOVE_J, []{ _menu_move_distance(J_AXIS, lcd_move_j); });
  222. #endif
  223. #if LINEAR_AXES >= 6
  224. SUBMENU(MSG_MOVE_K, []{ _menu_move_distance(K_AXIS, lcd_move_k); });
  225. #endif
  226. }
  227. else
  228. GCODES_ITEM(MSG_AUTO_HOME, G28_STR);
  229. #if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD)
  230. #if EXTRUDERS >= 4
  231. switch (active_extruder) {
  232. case 0: GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1")); break;
  233. case 1: GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0")); break;
  234. case 2: GCODES_ITEM_N(3, MSG_SELECT_E, PSTR("T3")); break;
  235. case 3: GCODES_ITEM_N(2, MSG_SELECT_E, PSTR("T2")); break;
  236. #if EXTRUDERS == 6
  237. case 4: GCODES_ITEM_N(5, MSG_SELECT_E, PSTR("T5")); break;
  238. case 5: GCODES_ITEM_N(4, MSG_SELECT_E, PSTR("T4")); break;
  239. #endif
  240. }
  241. #elif EXTRUDERS == 3
  242. if (active_extruder < 2) {
  243. if (active_extruder)
  244. GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
  245. else
  246. GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
  247. }
  248. #else
  249. if (active_extruder)
  250. GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
  251. else
  252. GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
  253. #endif
  254. #elif ENABLED(DUAL_X_CARRIAGE)
  255. if (active_extruder)
  256. GCODES_ITEM_N(0, MSG_SELECT_E, PSTR("T0"));
  257. else
  258. GCODES_ITEM_N(1, MSG_SELECT_E, PSTR("T1"));
  259. #endif
  260. #if E_MANUAL
  261. // The current extruder
  262. SUBMENU(MSG_MOVE_E, []{ _menu_move_distance_e_maybe(); });
  263. #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(MenuItemBase::itemIndex); }, MenuItemBase::itemIndex); });
  264. #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
  265. // ...and the non-switching
  266. #if E_MANUAL == 7 || E_MANUAL == 5 || E_MANUAL == 3
  267. SUBMENU_MOVE_E(E_MANUAL - 1);
  268. #endif
  269. #elif MULTI_E_MANUAL
  270. // Independent extruders with one E-stepper per hotend
  271. LOOP_L_N(n, E_MANUAL) SUBMENU_MOVE_E(n);
  272. #endif
  273. #endif // E_MANUAL
  274. END_MENU();
  275. }
  276. #if ENABLED(AUTO_BED_LEVELING_UBL)
  277. void _lcd_ubl_level_bed();
  278. #elif ENABLED(LCD_BED_LEVELING)
  279. void menu_bed_leveling();
  280. #endif
  281. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  282. void goto_tramming_wizard();
  283. #endif
  284. void menu_motion() {
  285. START_MENU();
  286. //
  287. // ^ Main
  288. //
  289. BACK_ITEM(MSG_MAIN);
  290. //
  291. // Move Axis
  292. //
  293. if (TERN1(DELTA, all_axes_homed()))
  294. SUBMENU(MSG_MOVE_AXIS, menu_move);
  295. //
  296. // Auto Home
  297. //
  298. GCODES_ITEM(MSG_AUTO_HOME, G28_STR);
  299. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  300. GCODES_ITEM(MSG_AUTO_HOME_X, PSTR("G28X"));
  301. #if HAS_Y_AXIS
  302. GCODES_ITEM(MSG_AUTO_HOME_Y, PSTR("G28Y"));
  303. #endif
  304. #if HAS_Z_AXIS
  305. GCODES_ITEM(MSG_AUTO_HOME_Z, PSTR("G28Z"));
  306. #endif
  307. #if LINEAR_AXES >= 4
  308. GCODES_ITEM(MSG_AUTO_HOME_I, PSTR("G28" I_STR));
  309. #endif
  310. #if LINEAR_AXES >= 5
  311. GCODES_ITEM(MSG_AUTO_HOME_J, PSTR("G28" J_STR));
  312. #endif
  313. #if LINEAR_AXES >= 6
  314. GCODES_ITEM(MSG_AUTO_HOME_K, PSTR("G28" K_STR));
  315. #endif
  316. #endif
  317. //
  318. // Auto-calibration
  319. //
  320. #if ENABLED(CALIBRATION_GCODE)
  321. GCODES_ITEM(MSG_AUTO_CALIBRATE, PSTR("G425"));
  322. #endif
  323. //
  324. // Auto Z-Align
  325. //
  326. #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  327. GCODES_ITEM(MSG_AUTO_Z_ALIGN, PSTR("G34"));
  328. #endif
  329. //
  330. // Assisted Bed Tramming
  331. //
  332. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  333. SUBMENU(MSG_TRAMMING_WIZARD, goto_tramming_wizard);
  334. #endif
  335. //
  336. // Level Bed
  337. //
  338. #if ENABLED(AUTO_BED_LEVELING_UBL)
  339. SUBMENU(MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  340. #elif ENABLED(LCD_BED_LEVELING)
  341. if (!g29_in_progress)
  342. SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
  343. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  344. #if DISABLED(PROBE_MANUALLY)
  345. GCODES_ITEM(MSG_LEVEL_BED, PSTR("G29N"));
  346. #endif
  347. if (all_axes_homed() && leveling_is_valid()) {
  348. bool show_state = planner.leveling_active;
  349. EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
  350. }
  351. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  352. editable.decimal = planner.z_fade_height;
  353. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  354. #endif
  355. #endif
  356. #if ENABLED(LEVEL_BED_CORNERS) && DISABLED(LCD_BED_LEVELING)
  357. SUBMENU(MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  358. #endif
  359. #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
  360. GCODES_ITEM(MSG_M48_TEST, PSTR("G28O\nM48 P10"));
  361. #endif
  362. //
  363. // Disable Steppers
  364. //
  365. GCODES_ITEM(MSG_DISABLE_STEPPERS, PSTR("M84"));
  366. END_MENU();
  367. }
  368. #endif // HAS_LCD_MENU