My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

menu_motion.cpp 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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. // Motion Menu
  24. //
  25. #include "../../inc/MarlinConfigPre.h"
  26. #if HAS_LCD_MENU
  27. #include "menu.h"
  28. #include "../../module/motion.h"
  29. #if ENABLED(DELTA)
  30. #include "../../module/delta.h"
  31. #endif
  32. #if ENABLED(PREVENT_COLD_EXTRUSION)
  33. #include "../../module/temperature.h"
  34. #endif
  35. #if HAS_LEVELING
  36. #include "../../module/planner.h"
  37. #include "../../feature/bedlevel/bedlevel.h"
  38. #endif
  39. extern millis_t manual_move_start_time;
  40. extern int8_t manual_move_axis;
  41. #if ENABLED(DUAL_X_CARRIAGE) || E_MANUAL > 1
  42. extern int8_t manual_move_e_index;
  43. #endif
  44. #if ENABLED(MANUAL_E_MOVES_RELATIVE)
  45. float manual_move_e_origin = 0;
  46. #endif
  47. #if IS_KINEMATIC
  48. extern float manual_move_offset;
  49. #endif
  50. //
  51. // Tell lcd_update() to start a move to current_position" after a short delay.
  52. //
  53. inline void manual_move_to_current(AxisEnum axis
  54. #if E_MANUAL > 1
  55. , const int8_t eindex=-1
  56. #endif
  57. ) {
  58. #if ENABLED(DUAL_X_CARRIAGE) || E_MANUAL > 1
  59. #if E_MANUAL > 1
  60. if (axis == E_AXIS)
  61. #endif
  62. manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
  63. #endif
  64. manual_move_start_time = millis() + (move_menu_scale < 0.99f ? 0UL : 250UL); // delay for bigger moves
  65. manual_move_axis = (int8_t)axis;
  66. }
  67. //
  68. // "Motion" > "Move Axis" submenu
  69. //
  70. static void _lcd_move_xyz(PGM_P name, AxisEnum axis) {
  71. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  72. ENCODER_DIRECTION_NORMAL();
  73. if (encoderPosition && !processing_manual_move) {
  74. // Start with no limits to movement
  75. float min = current_position[axis] - 1000,
  76. max = current_position[axis] + 1000;
  77. // Limit to software endstops, if enabled
  78. #if HAS_SOFTWARE_ENDSTOPS
  79. if (soft_endstops_enabled) switch (axis) {
  80. case X_AXIS:
  81. #if ENABLED(MIN_SOFTWARE_ENDSTOP_X)
  82. min = soft_endstop_min[X_AXIS];
  83. #endif
  84. #if ENABLED(MAX_SOFTWARE_ENDSTOP_X)
  85. max = soft_endstop_max[X_AXIS];
  86. #endif
  87. break;
  88. case Y_AXIS:
  89. #if ENABLED(MIN_SOFTWARE_ENDSTOP_Y)
  90. min = soft_endstop_min[Y_AXIS];
  91. #endif
  92. #if ENABLED(MAX_SOFTWARE_ENDSTOP_Y)
  93. max = soft_endstop_max[Y_AXIS];
  94. #endif
  95. break;
  96. case Z_AXIS:
  97. #if ENABLED(MIN_SOFTWARE_ENDSTOP_Z)
  98. min = soft_endstop_min[Z_AXIS];
  99. #endif
  100. #if ENABLED(MAX_SOFTWARE_ENDSTOP_Z)
  101. max = soft_endstop_max[Z_AXIS];
  102. #endif
  103. default: break;
  104. }
  105. #endif // HAS_SOFTWARE_ENDSTOPS
  106. // Delta limits XY based on the current offset from center
  107. // This assumes the center is 0,0
  108. #if ENABLED(DELTA)
  109. if (axis != Z_AXIS) {
  110. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
  111. min = -max;
  112. }
  113. #endif
  114. // Get the new position
  115. const float diff = float((int32_t)encoderPosition) * move_menu_scale;
  116. #if IS_KINEMATIC
  117. manual_move_offset += diff;
  118. if ((int32_t)encoderPosition < 0)
  119. NOLESS(manual_move_offset, min - current_position[axis]);
  120. else
  121. NOMORE(manual_move_offset, max - current_position[axis]);
  122. #else
  123. current_position[axis] += diff;
  124. if ((int32_t)encoderPosition < 0)
  125. NOLESS(current_position[axis], min);
  126. else
  127. NOMORE(current_position[axis], max);
  128. #endif
  129. manual_move_to_current(axis);
  130. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  131. }
  132. encoderPosition = 0;
  133. if (lcdDrawUpdate) {
  134. const float pos = NATIVE_TO_LOGICAL(processing_manual_move ? destination[axis] : current_position[axis]
  135. #if IS_KINEMATIC
  136. + manual_move_offset
  137. #endif
  138. , axis);
  139. lcd_implementation_drawedit(name, move_menu_scale >= 0.1f ? ftostr41sign(pos) : ftostr43sign(pos));
  140. }
  141. }
  142. void lcd_move_x() { _lcd_move_xyz(PSTR(MSG_MOVE_X), X_AXIS); }
  143. void lcd_move_y() { _lcd_move_xyz(PSTR(MSG_MOVE_Y), Y_AXIS); }
  144. void lcd_move_z() { _lcd_move_xyz(PSTR(MSG_MOVE_Z), Z_AXIS); }
  145. static void _lcd_move_e(
  146. #if E_MANUAL > 1
  147. const int8_t eindex=-1
  148. #endif
  149. ) {
  150. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  151. ENCODER_DIRECTION_NORMAL();
  152. if (encoderPosition) {
  153. if (!processing_manual_move) {
  154. const float diff = float((int32_t)encoderPosition) * move_menu_scale;
  155. #if IS_KINEMATIC
  156. manual_move_offset += diff;
  157. #else
  158. current_position[E_AXIS] += diff;
  159. #endif
  160. manual_move_to_current(E_AXIS
  161. #if E_MANUAL > 1
  162. , eindex
  163. #endif
  164. );
  165. lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
  166. }
  167. encoderPosition = 0;
  168. }
  169. if (lcdDrawUpdate) {
  170. PGM_P pos_label;
  171. #if E_MANUAL == 1
  172. pos_label = PSTR(MSG_MOVE_E);
  173. #else
  174. switch (eindex) {
  175. default: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E1); break;
  176. case 1: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E2); break;
  177. #if E_MANUAL > 2
  178. case 2: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E3); break;
  179. #if E_MANUAL > 3
  180. case 3: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E4); break;
  181. #if E_MANUAL > 4
  182. case 4: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E5); break;
  183. #if E_MANUAL > 5
  184. case 5: pos_label = PSTR(MSG_MOVE_E MSG_MOVE_E6); break;
  185. #endif // E_MANUAL > 5
  186. #endif // E_MANUAL > 4
  187. #endif // E_MANUAL > 3
  188. #endif // E_MANUAL > 2
  189. }
  190. #endif // E_MANUAL > 1
  191. lcd_implementation_drawedit(pos_label, ftostr41sign(current_position[E_AXIS]
  192. #if IS_KINEMATIC
  193. + manual_move_offset
  194. #endif
  195. #if ENABLED(MANUAL_E_MOVES_RELATIVE)
  196. - manual_move_e_origin
  197. #endif
  198. ));
  199. }
  200. }
  201. inline void lcd_move_e() { _lcd_move_e(); }
  202. #if E_MANUAL > 1
  203. inline void lcd_move_e0() { _lcd_move_e(0); }
  204. inline void lcd_move_e1() { _lcd_move_e(1); }
  205. #if E_MANUAL > 2
  206. inline void lcd_move_e2() { _lcd_move_e(2); }
  207. #if E_MANUAL > 3
  208. inline void lcd_move_e3() { _lcd_move_e(3); }
  209. #if E_MANUAL > 4
  210. inline void lcd_move_e4() { _lcd_move_e(4); }
  211. #if E_MANUAL > 5
  212. inline void lcd_move_e5() { _lcd_move_e(5); }
  213. #endif // E_MANUAL > 5
  214. #endif // E_MANUAL > 4
  215. #endif // E_MANUAL > 3
  216. #endif // E_MANUAL > 2
  217. #endif // E_MANUAL > 1
  218. //
  219. // "Motion" > "Move Xmm" > "Move XYZ" submenu
  220. //
  221. screenFunc_t _manual_move_func_ptr;
  222. void _goto_manual_move(const float scale) {
  223. defer_return_to_status = true;
  224. move_menu_scale = scale;
  225. lcd_goto_screen(_manual_move_func_ptr);
  226. }
  227. void menu_move_10mm() { _goto_manual_move(10); }
  228. void menu_move_1mm() { _goto_manual_move( 1); }
  229. void menu_move_01mm() { _goto_manual_move( 0.1f); }
  230. void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=-1) {
  231. _manual_move_func_ptr = func;
  232. START_MENU();
  233. if (LCD_HEIGHT >= 4) {
  234. switch (axis) {
  235. case X_AXIS:
  236. STATIC_ITEM(MSG_MOVE_X, true, true); break;
  237. case Y_AXIS:
  238. STATIC_ITEM(MSG_MOVE_Y, true, true); break;
  239. case Z_AXIS:
  240. STATIC_ITEM(MSG_MOVE_Z, true, true); break;
  241. default:
  242. #if ENABLED(MANUAL_E_MOVES_RELATIVE)
  243. manual_move_e_origin = current_position[E_AXIS];
  244. #endif
  245. STATIC_ITEM(MSG_MOVE_E, true, true);
  246. break;
  247. }
  248. }
  249. #if ENABLED(PREVENT_COLD_EXTRUSION)
  250. if (axis == E_AXIS && thermalManager.tooColdToExtrude(eindex >= 0 ? eindex : active_extruder))
  251. MENU_BACK(MSG_HOTEND_TOO_COLD);
  252. else
  253. #endif
  254. {
  255. MENU_BACK(MSG_MOVE_AXIS);
  256. MENU_ITEM(submenu, MSG_MOVE_10MM, menu_move_10mm);
  257. MENU_ITEM(submenu, MSG_MOVE_1MM, menu_move_1mm);
  258. MENU_ITEM(submenu, MSG_MOVE_01MM, menu_move_01mm);
  259. }
  260. END_MENU();
  261. }
  262. void lcd_move_get_x_amount() { _menu_move_distance(X_AXIS, lcd_move_x); }
  263. void lcd_move_get_y_amount() { _menu_move_distance(Y_AXIS, lcd_move_y); }
  264. void lcd_move_get_z_amount() { _menu_move_distance(Z_AXIS, lcd_move_z); }
  265. void lcd_move_get_e_amount() { _menu_move_distance(E_AXIS, lcd_move_e, -1); }
  266. #if E_MANUAL > 1
  267. void lcd_move_get_e0_amount() { _menu_move_distance(E_AXIS, lcd_move_e0, 0); }
  268. void lcd_move_get_e1_amount() { _menu_move_distance(E_AXIS, lcd_move_e1, 1); }
  269. #if E_MANUAL > 2
  270. void lcd_move_get_e2_amount() { _menu_move_distance(E_AXIS, lcd_move_e2, 2); }
  271. #if E_MANUAL > 3
  272. void lcd_move_get_e3_amount() { _menu_move_distance(E_AXIS, lcd_move_e3, 3); }
  273. #if E_MANUAL > 4
  274. void lcd_move_get_e4_amount() { _menu_move_distance(E_AXIS, lcd_move_e4, 4); }
  275. #if E_MANUAL > 5
  276. void lcd_move_get_e5_amount() { _menu_move_distance(E_AXIS, lcd_move_e5, 5); }
  277. #endif // E_MANUAL > 5
  278. #endif // E_MANUAL > 4
  279. #endif // E_MANUAL > 3
  280. #endif // E_MANUAL > 2
  281. #endif // E_MANUAL > 1
  282. #if ENABLED(DELTA)
  283. void lcd_lower_z_to_clip_height() {
  284. line_to_z(delta_clip_start_height);
  285. lcd_synchronize();
  286. }
  287. #endif
  288. void menu_move() {
  289. START_MENU();
  290. MENU_BACK(MSG_MOTION);
  291. #if HAS_SOFTWARE_ENDSTOPS && ENABLED(SOFT_ENDSTOPS_MENU_ITEM)
  292. MENU_ITEM_EDIT(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstops_enabled);
  293. #endif
  294. if (
  295. #if IS_KINEMATIC || ENABLED(NO_MOTION_BEFORE_HOMING)
  296. all_axes_homed()
  297. #else
  298. true
  299. #endif
  300. ) {
  301. if (
  302. #if ENABLED(DELTA)
  303. current_position[Z_AXIS] <= delta_clip_start_height
  304. #else
  305. true
  306. #endif
  307. ) {
  308. MENU_ITEM(submenu, MSG_MOVE_X, lcd_move_get_x_amount);
  309. MENU_ITEM(submenu, MSG_MOVE_Y, lcd_move_get_y_amount);
  310. }
  311. #if ENABLED(DELTA)
  312. else
  313. MENU_ITEM(function, MSG_FREE_XY, lcd_lower_z_to_clip_height);
  314. #endif
  315. MENU_ITEM(submenu, MSG_MOVE_Z, lcd_move_get_z_amount);
  316. }
  317. else
  318. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  319. #if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
  320. #if EXTRUDERS == 6
  321. switch (active_extruder) {
  322. case 0: MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1")); break;
  323. case 1: MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0")); break;
  324. case 2: MENU_ITEM(gcode, MSG_SELECT " " MSG_E4, PSTR("T3")); break;
  325. case 3: MENU_ITEM(gcode, MSG_SELECT " " MSG_E3, PSTR("T2")); break;
  326. case 4: MENU_ITEM(gcode, MSG_SELECT " " MSG_E6, PSTR("T5")); break;
  327. case 5: MENU_ITEM(gcode, MSG_SELECT " " MSG_E5, PSTR("T4")); break;
  328. }
  329. #elif EXTRUDERS == 5 || EXTRUDERS == 4
  330. switch (active_extruder) {
  331. case 0: MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1")); break;
  332. case 1: MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0")); break;
  333. case 2: MENU_ITEM(gcode, MSG_SELECT " " MSG_E4, PSTR("T3")); break;
  334. case 3: MENU_ITEM(gcode, MSG_SELECT " " MSG_E3, PSTR("T2")); break;
  335. }
  336. #elif EXTRUDERS == 3
  337. if (active_extruder < 2) {
  338. if (active_extruder)
  339. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  340. else
  341. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  342. }
  343. #else
  344. if (active_extruder)
  345. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  346. else
  347. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  348. #endif
  349. #elif ENABLED(DUAL_X_CARRIAGE)
  350. if (active_extruder)
  351. MENU_ITEM(gcode, MSG_SELECT " " MSG_E1, PSTR("T0"));
  352. else
  353. MENU_ITEM(gcode, MSG_SELECT " " MSG_E2, PSTR("T1"));
  354. #endif
  355. #if ENABLED(SWITCHING_EXTRUDER) || ENABLED(SWITCHING_NOZZLE)
  356. // Only the current...
  357. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  358. // ...and the non-switching
  359. #if E_MANUAL == 5
  360. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  361. #elif E_MANUAL == 3
  362. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  363. #endif
  364. #else
  365. // Independent extruders with one E-stepper per hotend
  366. MENU_ITEM(submenu, MSG_MOVE_E, lcd_move_get_e_amount);
  367. #if E_MANUAL > 1
  368. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E1, lcd_move_get_e0_amount);
  369. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E2, lcd_move_get_e1_amount);
  370. #if E_MANUAL > 2
  371. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E3, lcd_move_get_e2_amount);
  372. #if E_MANUAL > 3
  373. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E4, lcd_move_get_e3_amount);
  374. #if E_MANUAL > 4
  375. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E5, lcd_move_get_e4_amount);
  376. #if E_MANUAL > 5
  377. MENU_ITEM(submenu, MSG_MOVE_E MSG_MOVE_E6, lcd_move_get_e5_amount);
  378. #endif // E_MANUAL > 5
  379. #endif // E_MANUAL > 4
  380. #endif // E_MANUAL > 3
  381. #endif // E_MANUAL > 2
  382. #endif // E_MANUAL > 1
  383. #endif
  384. END_MENU();
  385. }
  386. void _lcd_ubl_level_bed();
  387. void menu_bed_leveling();
  388. void menu_motion() {
  389. START_MENU();
  390. //
  391. // ^ Main
  392. //
  393. MENU_BACK(MSG_MAIN);
  394. //
  395. // Move Axis
  396. //
  397. #if ENABLED(DELTA)
  398. if (all_axes_homed())
  399. #endif
  400. MENU_ITEM(submenu, MSG_MOVE_AXIS, menu_move);
  401. //
  402. // Auto Home
  403. //
  404. MENU_ITEM(gcode, MSG_AUTO_HOME, PSTR("G28"));
  405. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  406. MENU_ITEM(gcode, MSG_AUTO_HOME_X, PSTR("G28 X"));
  407. MENU_ITEM(gcode, MSG_AUTO_HOME_Y, PSTR("G28 Y"));
  408. MENU_ITEM(gcode, MSG_AUTO_HOME_Z, PSTR("G28 Z"));
  409. #endif
  410. //
  411. // Auto Z-Align
  412. //
  413. #if ENABLED(Z_STEPPER_AUTO_ALIGN)
  414. MENU_ITEM(gcode, MSG_AUTO_Z_ALIGN, PSTR("G34"));
  415. #endif
  416. //
  417. // TMC Z Calibration
  418. //
  419. #if ENABLED(TMC_Z_CALIBRATION)
  420. MENU_ITEM(gcode, MSG_TMC_Z_CALIBRATION, PSTR("G28\nM915"));
  421. #endif
  422. //
  423. // Level Bed
  424. //
  425. #if ENABLED(AUTO_BED_LEVELING_UBL)
  426. MENU_ITEM(submenu, MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  427. #elif ENABLED(LCD_BED_LEVELING)
  428. if (!g29_in_progress) MENU_ITEM(submenu, MSG_BED_LEVELING, menu_bed_leveling);
  429. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  430. #if DISABLED(PROBE_MANUALLY)
  431. MENU_ITEM(gcode, MSG_LEVEL_BED, PSTR("G28\nG29"));
  432. #endif
  433. if (leveling_is_valid()) {
  434. bool new_level_state = planner.leveling_active;
  435. MENU_ITEM_EDIT_CALLBACK(bool, MSG_BED_LEVELING, &new_level_state, _lcd_toggle_bed_leveling);
  436. }
  437. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  438. MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &lcd_z_fade_height, 0, 100, _lcd_set_z_fade_height);
  439. #endif
  440. #endif
  441. #if ENABLED(LEVEL_BED_CORNERS) && DISABLED(LCD_BED_LEVELING)
  442. MENU_ITEM(function, MSG_LEVEL_CORNERS, _lcd_level_bed_corners);
  443. #endif
  444. //
  445. // Disable Steppers
  446. //
  447. MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84"));
  448. END_MENU();
  449. }
  450. #endif // HAS_LCD_MENU