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_motion.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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_MARLINUI_MENU
  27. #define LARGE_AREA_TEST ((X_BED_SIZE) >= 1000 || TERN0(HAS_Y_AXIS, (Y_BED_SIZE) >= 1000) || TERN0(HAS_Z_AXIS, (Z_MAX_POS) >= 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. #include "../../module/temperature.h"
  33. #if ENABLED(DELTA)
  34. #include "../../module/delta.h"
  35. #endif
  36. #if HAS_LEVELING
  37. #include "../../module/planner.h"
  38. #include "../../feature/bedlevel/bedlevel.h"
  39. #endif
  40. //
  41. // "Motion" > "Move Axis" submenu
  42. //
  43. void lcd_move_axis(const AxisEnum axis) {
  44. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  45. if (ui.encoderPosition && !ui.manual_move.processing) {
  46. // Get motion limit from software endstops, if any
  47. float min, max;
  48. soft_endstop.get_manual_axis_limits(axis, min, max);
  49. // Delta limits XY based on the current offset from center
  50. // This assumes the center is 0,0
  51. #if ENABLED(DELTA)
  52. if (axis != Z_AXIS) {
  53. max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
  54. min = -max;
  55. }
  56. #endif
  57. // Get the new position
  58. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  59. (void)ui.manual_move.apply_diff(axis, diff, min, max);
  60. ui.manual_move.soon(axis);
  61. ui.refresh(LCDVIEW_REDRAW_NOW);
  62. }
  63. ui.encoderPosition = 0;
  64. if (ui.should_draw()) {
  65. MenuEditItemBase::itemIndex = axis;
  66. const float pos = ui.manual_move.axis_value(axis);
  67. if (parser.using_inch_units()) {
  68. const float imp_pos = LINEAR_UNIT(pos);
  69. MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_N), ftostr63(imp_pos));
  70. }
  71. else
  72. MenuEditItemBase::draw_edit_screen(GET_TEXT_F(MSG_MOVE_N), ui.manual_move.menu_scale >= 0.1f ? (LARGE_AREA_TEST ? ftostr51sign(pos) : ftostr41sign(pos)) : ftostr63(pos));
  73. }
  74. }
  75. #if E_MANUAL
  76. static void lcd_move_e(TERN_(MULTI_E_MANUAL, const int8_t eindex=active_extruder)) {
  77. if (ui.use_click()) return ui.goto_previous_screen_no_defer();
  78. if (ui.encoderPosition) {
  79. if (!ui.manual_move.processing) {
  80. const float diff = float(int32_t(ui.encoderPosition)) * ui.manual_move.menu_scale;
  81. TERN(IS_KINEMATIC, ui.manual_move.offset, current_position.e) += diff;
  82. ui.manual_move.soon(E_AXIS OPTARG(MULTI_E_MANUAL, eindex));
  83. ui.refresh(LCDVIEW_REDRAW_NOW);
  84. }
  85. ui.encoderPosition = 0;
  86. }
  87. if (ui.should_draw()) {
  88. TERN_(MULTI_E_MANUAL, MenuItemBase::init(eindex));
  89. MenuEditItemBase::draw_edit_screen(
  90. GET_TEXT_F(TERN(MULTI_E_MANUAL, MSG_MOVE_EN, MSG_MOVE_E)),
  91. ftostr41sign(current_position.e
  92. PLUS_TERN0(IS_KINEMATIC, ui.manual_move.offset)
  93. MINUS_TERN0(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin)
  94. )
  95. );
  96. } // should_draw
  97. }
  98. #endif // E_MANUAL
  99. #if EITHER(PROBE_OFFSET_WIZARD, X_AXIS_TWIST_COMPENSATION)
  100. void _goto_manual_move_z(const_float_t scale) {
  101. ui.manual_move.menu_scale = scale;
  102. ui.goto_screen([]{ lcd_move_axis(Z_AXIS); });
  103. }
  104. #endif
  105. //
  106. // "Motion" > "Move Xmm" > "Move XYZ" submenu
  107. //
  108. #ifndef FINE_MANUAL_MOVE
  109. #define FINE_MANUAL_MOVE 0.025
  110. #endif
  111. void _goto_manual_move(const_float_t scale) {
  112. ui.defer_status_screen();
  113. ui.manual_move.menu_scale = scale;
  114. ui.goto_screen(ui.manual_move.screen_ptr);
  115. thermalManager.set_menu_cold_override(true);
  116. }
  117. void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int8_t eindex=active_extruder) {
  118. ui.manual_move.screen_ptr = func;
  119. START_MENU();
  120. if (LCD_HEIGHT >= 4) {
  121. if (axis < NUM_AXES)
  122. STATIC_ITEM_N(axis, MSG_MOVE_N, SS_DEFAULT|SS_INVERT);
  123. else {
  124. TERN_(MANUAL_E_MOVES_RELATIVE, ui.manual_move.e_origin = current_position.e);
  125. STATIC_ITEM_N(eindex, MSG_MOVE_EN, SS_DEFAULT|SS_INVERT);
  126. }
  127. }
  128. BACK_ITEM(MSG_MOVE_AXIS);
  129. if (parser.using_inch_units()) {
  130. if (LARGE_AREA_TEST) SUBMENU(MSG_MOVE_1IN, []{ _goto_manual_move(IN_TO_MM(1.000f)); });
  131. SUBMENU(MSG_MOVE_01IN, []{ _goto_manual_move(IN_TO_MM(0.100f)); });
  132. SUBMENU(MSG_MOVE_001IN, []{ _goto_manual_move(IN_TO_MM(0.010f)); });
  133. SUBMENU(MSG_MOVE_0001IN, []{ _goto_manual_move(IN_TO_MM(0.001f)); });
  134. }
  135. else {
  136. if (LARGE_AREA_TEST) SUBMENU(MSG_MOVE_100MM, []{ _goto_manual_move(100); });
  137. SUBMENU(MSG_MOVE_10MM, []{ _goto_manual_move(10); });
  138. SUBMENU(MSG_MOVE_1MM, []{ _goto_manual_move( 1); });
  139. SUBMENU(MSG_MOVE_01MM, []{ _goto_manual_move( 0.1f); });
  140. #if HAS_Z_AXIS
  141. if (axis == Z_AXIS && (FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f)
  142. SUBMENU_f(F(STRINGIFY(FINE_MANUAL_MOVE)), MSG_MOVE_N_MM, []{ _goto_manual_move(float(FINE_MANUAL_MOVE)); });
  143. #endif
  144. }
  145. END_MENU();
  146. }
  147. #if E_MANUAL
  148. inline void _goto_menu_move_distance_e() {
  149. ui.goto_screen([]{ _menu_move_distance(E_AXIS, []{ lcd_move_e(); }); });
  150. }
  151. inline void _menu_move_distance_e_maybe() {
  152. if (thermalManager.tooColdToExtrude(active_extruder)) {
  153. ui.goto_screen([]{
  154. MenuItem_confirm::select_screen(
  155. GET_TEXT_F(MSG_BUTTON_PROCEED), GET_TEXT_F(MSG_BACK),
  156. _goto_menu_move_distance_e, nullptr,
  157. GET_TEXT_F(MSG_HOTEND_TOO_COLD), (const char *)nullptr, F("!")
  158. );
  159. });
  160. }
  161. else
  162. _goto_menu_move_distance_e();
  163. }
  164. #endif
  165. void menu_move() {
  166. START_MENU();
  167. BACK_ITEM(MSG_MOTION);
  168. #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
  169. EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled);
  170. #endif
  171. // Move submenu for each axis
  172. if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
  173. if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
  174. SUBMENU_N(X_AXIS, MSG_MOVE_N, []{ _menu_move_distance(X_AXIS, []{ lcd_move_axis(X_AXIS); }); });
  175. #if HAS_Y_AXIS
  176. SUBMENU_N(Y_AXIS, MSG_MOVE_N, []{ _menu_move_distance(Y_AXIS, []{ lcd_move_axis(Y_AXIS); }); });
  177. #endif
  178. }
  179. else {
  180. #if ENABLED(DELTA)
  181. ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); });
  182. #endif
  183. }
  184. #if HAS_Z_AXIS
  185. #define _AXIS_MOVE(N) SUBMENU_N(N, MSG_MOVE_N, []{ _menu_move_distance(AxisEnum(N), []{ lcd_move_axis(AxisEnum(N)); }); });
  186. REPEAT_S(2, NUM_AXES, _AXIS_MOVE);
  187. #endif
  188. }
  189. else
  190. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  191. #if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD)
  192. #if EXTRUDERS >= 4
  193. switch (active_extruder) {
  194. case 0: GCODES_ITEM_N(1, MSG_SELECT_E, F("T1")); break;
  195. case 1: GCODES_ITEM_N(0, MSG_SELECT_E, F("T0")); break;
  196. case 2: GCODES_ITEM_N(3, MSG_SELECT_E, F("T3")); break;
  197. case 3: GCODES_ITEM_N(2, MSG_SELECT_E, F("T2")); break;
  198. #if EXTRUDERS == 6
  199. case 4: GCODES_ITEM_N(5, MSG_SELECT_E, F("T5")); break;
  200. case 5: GCODES_ITEM_N(4, MSG_SELECT_E, F("T4")); break;
  201. #endif
  202. }
  203. #elif EXTRUDERS == 3
  204. if (active_extruder < 2) {
  205. if (active_extruder)
  206. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  207. else
  208. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  209. }
  210. #else
  211. if (active_extruder)
  212. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  213. else
  214. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  215. #endif
  216. #elif ENABLED(DUAL_X_CARRIAGE)
  217. if (active_extruder)
  218. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  219. else
  220. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  221. #endif
  222. #if E_MANUAL
  223. // The current extruder
  224. SUBMENU(MSG_MOVE_E, _menu_move_distance_e_maybe);
  225. #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(N); }, N); });
  226. #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
  227. // ...and the non-switching
  228. #if E_MANUAL == 7 || E_MANUAL == 5 || E_MANUAL == 3
  229. SUBMENU_MOVE_E(E_MANUAL - 1);
  230. #endif
  231. #elif MULTI_E_MANUAL
  232. // Independent extruders with one E stepper per hotend
  233. REPEAT(E_MANUAL, SUBMENU_MOVE_E);
  234. #endif
  235. #endif // E_MANUAL
  236. END_MENU();
  237. }
  238. #define _HOME_ITEM(N) GCODES_ITEM_N(N##_AXIS, MSG_AUTO_HOME_A, F("G28" STR_##N));
  239. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  240. //
  241. // "Motion" > "Homing" submenu
  242. //
  243. void menu_home() {
  244. START_MENU();
  245. BACK_ITEM(MSG_MOTION);
  246. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  247. MAIN_AXIS_MAP(_HOME_ITEM);
  248. END_MENU();
  249. }
  250. #endif
  251. #if ENABLED(AUTO_BED_LEVELING_UBL)
  252. void _lcd_ubl_level_bed();
  253. #elif ENABLED(LCD_BED_LEVELING)
  254. void menu_bed_leveling();
  255. #endif
  256. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  257. void goto_tramming_wizard();
  258. #endif
  259. void menu_motion() {
  260. START_MENU();
  261. //
  262. // ^ Main
  263. //
  264. BACK_ITEM(MSG_MAIN);
  265. //
  266. // Move Axis
  267. //
  268. if (TERN1(DELTA, all_axes_homed()))
  269. SUBMENU(MSG_MOVE_AXIS, menu_move);
  270. //
  271. // Auto Home
  272. //
  273. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  274. SUBMENU(MSG_HOMING, menu_home);
  275. #else
  276. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  277. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  278. MAIN_AXIS_MAP(_HOME_ITEM);
  279. #endif
  280. #endif
  281. //
  282. // Auto-calibration
  283. //
  284. #if ENABLED(CALIBRATION_GCODE)
  285. GCODES_ITEM(MSG_AUTO_CALIBRATE, F("G425"));
  286. #endif
  287. //
  288. // Auto Z-Align
  289. //
  290. #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  291. GCODES_ITEM(MSG_AUTO_Z_ALIGN, F("G34"));
  292. #endif
  293. //
  294. // Probe Deploy/Stow
  295. //
  296. #if ENABLED(PROBE_DEPLOY_STOW_MENU)
  297. GCODES_ITEM(MSG_MANUAL_DEPLOY, F("M401"));
  298. GCODES_ITEM(MSG_MANUAL_STOW, F("M402"));
  299. #endif
  300. //
  301. // Assisted Bed Tramming
  302. //
  303. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  304. SUBMENU(MSG_TRAMMING_WIZARD, goto_tramming_wizard);
  305. #endif
  306. //
  307. // Level Bed
  308. //
  309. #if ENABLED(AUTO_BED_LEVELING_UBL)
  310. SUBMENU(MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  311. #elif ENABLED(LCD_BED_LEVELING)
  312. if (!g29_in_progress)
  313. SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
  314. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  315. #if DISABLED(PROBE_MANUALLY)
  316. GCODES_ITEM(MSG_LEVEL_BED, F("G29N"));
  317. #endif
  318. if (all_axes_homed() && leveling_is_valid()) {
  319. bool show_state = planner.leveling_active;
  320. EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
  321. }
  322. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  323. editable.decimal = planner.z_fade_height;
  324. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  325. #endif
  326. #endif
  327. #if ENABLED(LCD_BED_TRAMMING) && DISABLED(LCD_BED_LEVELING)
  328. SUBMENU(MSG_BED_TRAMMING, _lcd_level_bed_corners);
  329. #endif
  330. #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
  331. GCODES_ITEM(MSG_M48_TEST, F("G28O\nM48 P10"));
  332. #endif
  333. //
  334. // Disable Steppers
  335. //
  336. GCODES_ITEM(MSG_DISABLE_STEPPERS, F("M84"));
  337. END_MENU();
  338. }
  339. #endif // HAS_MARLINUI_MENU