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 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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 || (Y_BED_SIZE) >= 1000 || (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 (axis == Z_AXIS && (FINE_MANUAL_MOVE) > 0.0f && (FINE_MANUAL_MOVE) < 0.1f)
  141. SUBMENU_f(F(STRINGIFY(FINE_MANUAL_MOVE)), MSG_MOVE_N_MM, []{ _goto_manual_move(float(FINE_MANUAL_MOVE)); });
  142. }
  143. END_MENU();
  144. }
  145. #if E_MANUAL
  146. inline void _goto_menu_move_distance_e() {
  147. ui.goto_screen([]{ _menu_move_distance(E_AXIS, []{ lcd_move_e(); }); });
  148. }
  149. inline void _menu_move_distance_e_maybe() {
  150. if (thermalManager.tooColdToExtrude(active_extruder)) {
  151. ui.goto_screen([]{
  152. MenuItem_confirm::select_screen(
  153. GET_TEXT_F(MSG_BUTTON_PROCEED), GET_TEXT_F(MSG_BACK),
  154. _goto_menu_move_distance_e, nullptr,
  155. GET_TEXT_F(MSG_HOTEND_TOO_COLD), (const char *)nullptr, F("!")
  156. );
  157. });
  158. }
  159. else
  160. _goto_menu_move_distance_e();
  161. }
  162. #endif
  163. void menu_move() {
  164. START_MENU();
  165. BACK_ITEM(MSG_MOTION);
  166. #if BOTH(HAS_SOFTWARE_ENDSTOPS, SOFT_ENDSTOPS_MENU_ITEM)
  167. EDIT_ITEM(bool, MSG_LCD_SOFT_ENDSTOPS, &soft_endstop._enabled);
  168. #endif
  169. // Move submenu for each axis
  170. if (NONE(IS_KINEMATIC, NO_MOTION_BEFORE_HOMING) || all_axes_homed()) {
  171. if (TERN1(DELTA, current_position.z <= delta_clip_start_height)) {
  172. SUBMENU_N(X_AXIS, MSG_MOVE_N, []{ _menu_move_distance(X_AXIS, []{ lcd_move_axis(X_AXIS); }); });
  173. #if HAS_Y_AXIS
  174. SUBMENU_N(Y_AXIS, MSG_MOVE_N, []{ _menu_move_distance(Y_AXIS, []{ lcd_move_axis(Y_AXIS); }); });
  175. #endif
  176. }
  177. else {
  178. #if ENABLED(DELTA)
  179. ACTION_ITEM(MSG_FREE_XY, []{ line_to_z(delta_clip_start_height); ui.synchronize(); });
  180. #endif
  181. }
  182. #if HAS_Z_AXIS
  183. #define _AXIS_MOVE(N) SUBMENU_N(N, MSG_MOVE_N, []{ _menu_move_distance(AxisEnum(N), []{ lcd_move_axis(AxisEnum(N)); }); });
  184. REPEAT_S(2, NUM_AXES, _AXIS_MOVE);
  185. #endif
  186. }
  187. else
  188. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  189. #if ANY(SWITCHING_EXTRUDER, SWITCHING_NOZZLE, MAGNETIC_SWITCHING_TOOLHEAD)
  190. #if EXTRUDERS >= 4
  191. switch (active_extruder) {
  192. case 0: GCODES_ITEM_N(1, MSG_SELECT_E, F("T1")); break;
  193. case 1: GCODES_ITEM_N(0, MSG_SELECT_E, F("T0")); break;
  194. case 2: GCODES_ITEM_N(3, MSG_SELECT_E, F("T3")); break;
  195. case 3: GCODES_ITEM_N(2, MSG_SELECT_E, F("T2")); break;
  196. #if EXTRUDERS == 6
  197. case 4: GCODES_ITEM_N(5, MSG_SELECT_E, F("T5")); break;
  198. case 5: GCODES_ITEM_N(4, MSG_SELECT_E, F("T4")); break;
  199. #endif
  200. }
  201. #elif EXTRUDERS == 3
  202. if (active_extruder < 2) {
  203. if (active_extruder)
  204. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  205. else
  206. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  207. }
  208. #else
  209. if (active_extruder)
  210. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  211. else
  212. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  213. #endif
  214. #elif ENABLED(DUAL_X_CARRIAGE)
  215. if (active_extruder)
  216. GCODES_ITEM_N(0, MSG_SELECT_E, F("T0"));
  217. else
  218. GCODES_ITEM_N(1, MSG_SELECT_E, F("T1"));
  219. #endif
  220. #if E_MANUAL
  221. // The current extruder
  222. SUBMENU(MSG_MOVE_E, _menu_move_distance_e_maybe);
  223. #define SUBMENU_MOVE_E(N) SUBMENU_N(N, MSG_MOVE_EN, []{ _menu_move_distance(E_AXIS, []{ lcd_move_e(N); }, N); });
  224. #if EITHER(SWITCHING_EXTRUDER, SWITCHING_NOZZLE)
  225. // ...and the non-switching
  226. #if E_MANUAL == 7 || E_MANUAL == 5 || E_MANUAL == 3
  227. SUBMENU_MOVE_E(E_MANUAL - 1);
  228. #endif
  229. #elif MULTI_E_MANUAL
  230. // Independent extruders with one E stepper per hotend
  231. REPEAT(E_MANUAL, SUBMENU_MOVE_E);
  232. #endif
  233. #endif // E_MANUAL
  234. END_MENU();
  235. }
  236. #define _HOME_ITEM(N) GCODES_ITEM_N(N##_AXIS, MSG_AUTO_HOME_A, F("G28" STR_##N));
  237. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  238. //
  239. // "Motion" > "Homing" submenu
  240. //
  241. void menu_home() {
  242. START_MENU();
  243. BACK_ITEM(MSG_MOTION);
  244. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  245. MAIN_AXIS_MAP(_HOME_ITEM);
  246. END_MENU();
  247. }
  248. #endif
  249. #if ENABLED(AUTO_BED_LEVELING_UBL)
  250. void _lcd_ubl_level_bed();
  251. #elif ENABLED(LCD_BED_LEVELING)
  252. void menu_bed_leveling();
  253. #endif
  254. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  255. void goto_tramming_wizard();
  256. #endif
  257. void menu_motion() {
  258. START_MENU();
  259. //
  260. // ^ Main
  261. //
  262. BACK_ITEM(MSG_MAIN);
  263. //
  264. // Move Axis
  265. //
  266. if (TERN1(DELTA, all_axes_homed()))
  267. SUBMENU(MSG_MOVE_AXIS, menu_move);
  268. //
  269. // Auto Home
  270. //
  271. #if ENABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
  272. SUBMENU(MSG_HOMING, menu_home);
  273. #else
  274. GCODES_ITEM(MSG_AUTO_HOME, FPSTR(G28_STR));
  275. #if ENABLED(INDIVIDUAL_AXIS_HOMING_MENU)
  276. MAIN_AXIS_MAP(_HOME_ITEM);
  277. #endif
  278. #endif
  279. //
  280. // Auto-calibration
  281. //
  282. #if ENABLED(CALIBRATION_GCODE)
  283. GCODES_ITEM(MSG_AUTO_CALIBRATE, F("G425"));
  284. #endif
  285. //
  286. // Auto Z-Align
  287. //
  288. #if EITHER(Z_STEPPER_AUTO_ALIGN, MECHANICAL_GANTRY_CALIBRATION)
  289. GCODES_ITEM(MSG_AUTO_Z_ALIGN, F("G34"));
  290. #endif
  291. //
  292. // Probe Deploy/Stow
  293. //
  294. #if ENABLED(PROBE_DEPLOY_STOW_MENU)
  295. GCODES_ITEM(MSG_MANUAL_DEPLOY, F("M401"));
  296. GCODES_ITEM(MSG_MANUAL_STOW, F("M402"));
  297. #endif
  298. //
  299. // Assisted Bed Tramming
  300. //
  301. #if ENABLED(ASSISTED_TRAMMING_WIZARD)
  302. SUBMENU(MSG_TRAMMING_WIZARD, goto_tramming_wizard);
  303. #endif
  304. //
  305. // Level Bed
  306. //
  307. #if ENABLED(AUTO_BED_LEVELING_UBL)
  308. SUBMENU(MSG_UBL_LEVEL_BED, _lcd_ubl_level_bed);
  309. #elif ENABLED(LCD_BED_LEVELING)
  310. if (!g29_in_progress)
  311. SUBMENU(MSG_BED_LEVELING, menu_bed_leveling);
  312. #elif HAS_LEVELING && DISABLED(SLIM_LCD_MENUS)
  313. #if DISABLED(PROBE_MANUALLY)
  314. GCODES_ITEM(MSG_LEVEL_BED, F("G29N"));
  315. #endif
  316. if (all_axes_homed() && leveling_is_valid()) {
  317. bool show_state = planner.leveling_active;
  318. EDIT_ITEM(bool, MSG_BED_LEVELING, &show_state, _lcd_toggle_bed_leveling);
  319. }
  320. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  321. editable.decimal = planner.z_fade_height;
  322. EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
  323. #endif
  324. #endif
  325. #if ENABLED(LCD_BED_TRAMMING) && DISABLED(LCD_BED_LEVELING)
  326. SUBMENU(MSG_BED_TRAMMING, _lcd_level_bed_corners);
  327. #endif
  328. #if ENABLED(Z_MIN_PROBE_REPEATABILITY_TEST)
  329. GCODES_ITEM(MSG_M48_TEST, F("G28O\nM48 P10"));
  330. #endif
  331. //
  332. // Disable Steppers
  333. //
  334. GCODES_ITEM(MSG_DISABLE_STEPPERS, F("M84"));
  335. END_MENU();
  336. }
  337. #endif // HAS_MARLINUI_MENU