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.cpp 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. #include "../../inc/MarlinConfigPre.h"
  23. #if ENABLED(ULTIPANEL)
  24. #include "menu.h"
  25. #include "../ultralcd.h"
  26. #include "../../module/planner.h"
  27. #include "../../module/motion.h"
  28. #include "../../module/probe.h"
  29. #include "../../module/printcounter.h"
  30. #include "../../gcode/gcode.h"
  31. #include "../../gcode/queue.h"
  32. #include "../../module/configuration_store.h"
  33. #include "../../module/tool_change.h"
  34. #include "../../Marlin.h"
  35. #include <stdarg.h>
  36. #if ENABLED(SDSUPPORT)
  37. #include "../../sd/cardreader.h"
  38. #endif
  39. #if HAS_LEVELING
  40. #include "../../feature/bedlevel/bedlevel.h"
  41. #endif
  42. ////////////////////////////////////////////
  43. ///////////// Global Variables /////////////
  44. ////////////////////////////////////////////
  45. // Buttons
  46. volatile uint8_t buttons;
  47. #if ENABLED(REPRAPWORLD_KEYPAD)
  48. volatile uint8_t buttons_reprapworld_keypad;
  49. #endif
  50. // Menu Navigation
  51. int8_t encoderTopLine;
  52. typedef struct {
  53. screenFunc_t menu_function;
  54. uint32_t encoder_position;
  55. } menuPosition;
  56. menuPosition screen_history[6];
  57. uint8_t screen_history_depth = 0;
  58. bool screen_changed, defer_return_to_status;
  59. // Value Editing
  60. PGM_P editLabel;
  61. void *editValue;
  62. int32_t minEditValue, maxEditValue;
  63. screenFunc_t callbackFunc;
  64. bool liveEdit;
  65. bool no_reentry = false;
  66. // Initialized by settings.load()
  67. int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2];
  68. uint8_t lcd_preheat_fan_speed[2];
  69. ////////////////////////////////////////////
  70. //////// Menu Navigation & History /////////
  71. ////////////////////////////////////////////
  72. void lcd_status_screen();
  73. void lcd_return_to_status() { lcd_goto_screen(lcd_status_screen); }
  74. void lcd_save_previous_screen() {
  75. if (screen_history_depth < COUNT(screen_history)) {
  76. screen_history[screen_history_depth].menu_function = currentScreen;
  77. screen_history[screen_history_depth].encoder_position = encoderPosition;
  78. ++screen_history_depth;
  79. }
  80. }
  81. void lcd_goto_previous_menu() {
  82. if (screen_history_depth > 0) {
  83. --screen_history_depth;
  84. lcd_goto_screen(
  85. screen_history[screen_history_depth].menu_function,
  86. screen_history[screen_history_depth].encoder_position
  87. );
  88. }
  89. else
  90. lcd_return_to_status();
  91. }
  92. void lcd_goto_previous_menu_no_defer() {
  93. defer_return_to_status = false;
  94. lcd_goto_previous_menu();
  95. }
  96. ////////////////////////////////////////////
  97. /////////////// Menu Actions ///////////////
  98. ////////////////////////////////////////////
  99. void _menu_action_back() { lcd_goto_previous_menu(); }
  100. void menu_action_submenu(screenFunc_t func) { lcd_save_previous_screen(); lcd_goto_screen(func); }
  101. void menu_action_gcode(PGM_P pgcode) { enqueue_and_echo_commands_P(pgcode); }
  102. void menu_action_function(screenFunc_t func) { (*func)(); }
  103. #if ENABLED(SDSUPPORT)
  104. void menu_action_sdfile(CardReader &theCard) {
  105. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  106. last_sdfile_encoderPosition = encoderPosition; // Save which file was selected for later use
  107. #endif
  108. card.openAndPrintFile(theCard.filename);
  109. lcd_return_to_status();
  110. lcd_reset_status();
  111. }
  112. void menu_action_sddirectory(CardReader &theCard) {
  113. card.chdir(theCard.filename);
  114. encoderTopLine = 0;
  115. encoderPosition = 2 * ENCODER_STEPS_PER_MENU_ITEM;
  116. screen_changed = true;
  117. #if HAS_GRAPHICAL_LCD
  118. drawing_screen = false;
  119. #endif
  120. lcd_refresh();
  121. }
  122. #endif // SDSUPPORT
  123. ////////////////////////////////////////////
  124. /////////// Menu Editing Actions ///////////
  125. ////////////////////////////////////////////
  126. /**
  127. * Functions for editing single values
  128. *
  129. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
  130. *
  131. * For example, DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1) expands into these functions:
  132. *
  133. * bool _menu_edit_int3();
  134. * void menu_edit_int3(); // edit int16_t (interactively)
  135. * void menu_edit_callback_int3(); // edit int16_t (interactively) with callback on completion
  136. * void _menu_action_setting_edit_int3(PGM_P const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  137. * void menu_action_setting_edit_int3(PGM_P const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
  138. * void menu_action_setting_edit_callback_int3(PGM_P const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback, const bool live); // edit int16_t with callback
  139. *
  140. * You can then use one of the menu macros to present the edit interface:
  141. * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
  142. *
  143. * This expands into a more primitive menu item:
  144. * MENU_ITEM(setting_edit_int3, MSG_SPEED, PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  145. *
  146. * ...which calls:
  147. * menu_action_setting_edit_int3(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
  148. */
  149. #define DEFINE_MENU_EDIT_TYPE(TYPE, NAME, STRFUNC, SCALE) \
  150. bool _menu_edit_ ## NAME() { \
  151. ENCODER_DIRECTION_NORMAL(); \
  152. if ((int32_t)encoderPosition < 0) encoderPosition = 0; \
  153. if ((int32_t)encoderPosition > maxEditValue) encoderPosition = maxEditValue; \
  154. if (lcdDrawUpdate) \
  155. lcd_implementation_drawedit(editLabel, STRFUNC(((TYPE)((int32_t)encoderPosition + minEditValue)) * (1.0f / SCALE))); \
  156. if (lcd_clicked || (liveEdit && lcdDrawUpdate)) { \
  157. TYPE value = ((TYPE)((int32_t)encoderPosition + minEditValue)) * (1.0f / SCALE); \
  158. if (editValue != NULL) *((TYPE*)editValue) = value; \
  159. if (callbackFunc && (liveEdit || lcd_clicked)) (*callbackFunc)(); \
  160. if (lcd_clicked) lcd_goto_previous_menu(); \
  161. } \
  162. return use_click(); \
  163. } \
  164. void menu_edit_ ## NAME() { _menu_edit_ ## NAME(); } \
  165. void _menu_action_setting_edit_ ## NAME(PGM_P const pstr, TYPE* const ptr, const TYPE minValue, const TYPE maxValue) { \
  166. lcd_save_previous_screen(); \
  167. lcd_refresh(); \
  168. \
  169. editLabel = pstr; \
  170. editValue = ptr; \
  171. minEditValue = minValue * SCALE; \
  172. maxEditValue = maxValue * SCALE - minEditValue; \
  173. encoderPosition = (*ptr) * SCALE - minEditValue; \
  174. } \
  175. void menu_action_setting_edit_callback_ ## NAME(PGM_P const pstr, TYPE * const ptr, const TYPE minValue, const TYPE maxValue, const screenFunc_t callback/*=NULL*/, const bool live/*=false*/) { \
  176. _menu_action_setting_edit_ ## NAME(pstr, ptr, minValue, maxValue); \
  177. currentScreen = menu_edit_ ## NAME; \
  178. callbackFunc = callback; \
  179. liveEdit = live; \
  180. } \
  181. typedef void NAME##_void
  182. DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
  183. DEFINE_MENU_EDIT_TYPE(int16_t, int4, itostr4sign, 1);
  184. DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
  185. DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1);
  186. DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52, 100);
  187. DEFINE_MENU_EDIT_TYPE(float, float43, ftostr43sign, 1000);
  188. DEFINE_MENU_EDIT_TYPE(float, float5, ftostr5rj, 0.01f);
  189. DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10);
  190. DEFINE_MENU_EDIT_TYPE(float, float52sign, ftostr52sign, 100);
  191. DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100);
  192. DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01f);
  193. void menu_action_setting_edit_bool(PGM_P pstr, bool* ptr) { UNUSED(pstr); *ptr ^= true; lcd_refresh(); }
  194. void menu_action_setting_edit_callback_bool(PGM_P pstr, bool* ptr, screenFunc_t callback) {
  195. menu_action_setting_edit_bool(pstr, ptr);
  196. (*callback)();
  197. }
  198. ////////////////////////////////////////////
  199. ///////////////// Menu Tree ////////////////
  200. ////////////////////////////////////////////
  201. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  202. float lcd_z_fade_height;
  203. void _lcd_set_z_fade_height() { set_z_fade_height(lcd_z_fade_height); }
  204. #endif
  205. bool printer_busy() { return planner.movesplanned() || IS_SD_PRINTING(); }
  206. #if HAS_CHARACTER_LCD && (ENABLED(LCD_PROGRESS_BAR) || ENABLED(LCD_PROGRESS_BAR_TEST) || ENABLED(AUTO_BED_LEVELING_UBL))
  207. void lcd_set_custom_characters(
  208. #if ENABLED(LCD_PROGRESS_BAR) || ENABLED(SHOW_BOOTSCREEN)
  209. const uint8_t screen_charset=CHARSET_INFO
  210. #endif
  211. );
  212. #endif
  213. /**
  214. * General function to go directly to a screen
  215. */
  216. void lcd_goto_screen(screenFunc_t screen, const uint32_t encoder/*=0*/) {
  217. if (currentScreen != screen) {
  218. #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
  219. // Shadow for editing the fade height
  220. lcd_z_fade_height = planner.z_fade_height;
  221. #endif
  222. #if ENABLED(DOUBLECLICK_FOR_Z_BABYSTEPPING) && ENABLED(BABYSTEPPING)
  223. static millis_t doubleclick_expire_ms = 0;
  224. // Going to menu_main from status screen? Remember first click time.
  225. // Going back to status screen within a very short time? Go to Z babystepping.
  226. if (screen == menu_main) {
  227. if (currentScreen == lcd_status_screen)
  228. doubleclick_expire_ms = millis() + DOUBLECLICK_MAX_INTERVAL;
  229. }
  230. else if (screen == lcd_status_screen && currentScreen == menu_main && PENDING(millis(), doubleclick_expire_ms)) {
  231. if (printer_busy()) {
  232. screen =
  233. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  234. lcd_babystep_zoffset
  235. #else
  236. lcd_babystep_z
  237. #endif
  238. ;
  239. }
  240. #if ENABLED(MOVE_Z_WHEN_IDLE)
  241. else {
  242. move_menu_scale = MOVE_Z_IDLE_MULTIPLICATOR;
  243. screen = lcd_move_z;
  244. }
  245. #endif
  246. }
  247. #endif
  248. currentScreen = screen;
  249. encoderPosition = encoder;
  250. if (screen == lcd_status_screen) {
  251. defer_return_to_status = false;
  252. #if ENABLED(AUTO_BED_LEVELING_UBL)
  253. ubl.lcd_map_control = false;
  254. #endif
  255. screen_history_depth = 0;
  256. }
  257. lcd_implementation_clear();
  258. // Re-initialize custom characters that may be re-used
  259. #if HAS_CHARACTER_LCD && ENABLED(AUTO_BED_LEVELING_UBL)
  260. if (!ubl.lcd_map_control) {
  261. lcd_set_custom_characters(
  262. #if ENABLED(LCD_PROGRESS_BAR)
  263. screen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU
  264. #endif
  265. );
  266. }
  267. #elif ENABLED(LCD_PROGRESS_BAR)
  268. lcd_set_custom_characters(screen == lcd_status_screen ? CHARSET_INFO : CHARSET_MENU);
  269. #endif
  270. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  271. screen_changed = true;
  272. #if HAS_GRAPHICAL_LCD
  273. drawing_screen = false;
  274. #endif
  275. }
  276. }
  277. ////////////////////////////////////////////
  278. ///////////// Manual Movement //////////////
  279. ////////////////////////////////////////////
  280. //
  281. // Display the synchronize screen until moves are
  282. // finished, and don't return to the caller until
  283. // done. ** This blocks the command queue! **
  284. //
  285. static PGM_P sync_message;
  286. void _lcd_synchronize() {
  287. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
  288. if (no_reentry) return;
  289. // Make this the current handler till all moves are done
  290. no_reentry = true;
  291. const screenFunc_t old_screen = currentScreen;
  292. lcd_goto_screen(_lcd_synchronize);
  293. planner.synchronize(); // idle() is called until moves complete
  294. no_reentry = false;
  295. lcd_goto_screen(old_screen);
  296. }
  297. // Display the synchronize screen with a custom message
  298. // ** This blocks the command queue! **
  299. void lcd_synchronize(PGM_P const msg/*=NULL*/) {
  300. static const char moving[] PROGMEM = MSG_MOVING;
  301. sync_message = msg ? msg : moving;
  302. _lcd_synchronize();
  303. }
  304. /**
  305. * Scrolling for menus and other line-based screens
  306. *
  307. * encoderLine is the position based on the encoder
  308. * encoderTopLine is the top menu line to display
  309. * _lcdLineNr is the index of the LCD line (e.g., 0-3)
  310. * _menuLineNr is the menu item to draw and process
  311. * _thisItemNr is the index of each MENU_ITEM or STATIC_ITEM
  312. * screen_items is the total number of items in the menu (after one call)
  313. */
  314. int8_t encoderLine, screen_items;
  315. void scroll_screen(const uint8_t limit, const bool is_menu) {
  316. ENCODER_DIRECTION_MENUS();
  317. ENCODER_RATE_MULTIPLY(false);
  318. if (encoderPosition > 0x8000) encoderPosition = 0;
  319. if (first_page) {
  320. encoderLine = encoderPosition / (ENCODER_STEPS_PER_MENU_ITEM);
  321. screen_changed = false;
  322. }
  323. if (screen_items > 0 && encoderLine >= screen_items - limit) {
  324. encoderLine = MAX(0, screen_items - limit);
  325. encoderPosition = encoderLine * (ENCODER_STEPS_PER_MENU_ITEM);
  326. }
  327. if (is_menu) {
  328. NOMORE(encoderTopLine, encoderLine);
  329. if (encoderLine >= encoderTopLine + LCD_HEIGHT)
  330. encoderTopLine = encoderLine - LCD_HEIGHT + 1;
  331. }
  332. else
  333. encoderTopLine = encoderLine;
  334. }
  335. void lcd_completion_feedback(const bool good/*=true*/) {
  336. if (good) {
  337. lcd_buzz(100, 659);
  338. lcd_buzz(100, 698);
  339. }
  340. else lcd_buzz(20, 440);
  341. }
  342. inline void line_to_current_z() {
  343. planner.buffer_line(current_position, MMM_TO_MMS(manual_feedrate_mm_m[Z_AXIS]), active_extruder);
  344. }
  345. void line_to_z(const float &z) {
  346. current_position[Z_AXIS] = z;
  347. line_to_current_z();
  348. }
  349. #if ENABLED(CUSTOM_USER_MENUS)
  350. #ifdef USER_SCRIPT_DONE
  351. #define _DONE_SCRIPT "\n" USER_SCRIPT_DONE
  352. #else
  353. #define _DONE_SCRIPT ""
  354. #endif
  355. void _lcd_user_gcode(PGM_P const cmd) {
  356. enqueue_and_echo_commands_P(cmd);
  357. #if ENABLED(USER_SCRIPT_AUDIBLE_FEEDBACK)
  358. lcd_completion_feedback();
  359. #endif
  360. #if ENABLED(USER_SCRIPT_RETURN)
  361. lcd_return_to_status();
  362. #endif
  363. }
  364. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  365. void lcd_user_gcode_1() { _lcd_user_gcode(PSTR(USER_GCODE_1 _DONE_SCRIPT)); }
  366. #endif
  367. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  368. void lcd_user_gcode_2() { _lcd_user_gcode(PSTR(USER_GCODE_2 _DONE_SCRIPT)); }
  369. #endif
  370. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  371. void lcd_user_gcode_3() { _lcd_user_gcode(PSTR(USER_GCODE_3 _DONE_SCRIPT)); }
  372. #endif
  373. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  374. void lcd_user_gcode_4() { _lcd_user_gcode(PSTR(USER_GCODE_4 _DONE_SCRIPT)); }
  375. #endif
  376. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  377. void lcd_user_gcode_5() { _lcd_user_gcode(PSTR(USER_GCODE_5 _DONE_SCRIPT)); }
  378. #endif
  379. void _menu_user() {
  380. START_MENU();
  381. MENU_BACK(MSG_MAIN);
  382. #if defined(USER_DESC_1) && defined(USER_GCODE_1)
  383. MENU_ITEM(function, USER_DESC_1, lcd_user_gcode_1);
  384. #endif
  385. #if defined(USER_DESC_2) && defined(USER_GCODE_2)
  386. MENU_ITEM(function, USER_DESC_2, lcd_user_gcode_2);
  387. #endif
  388. #if defined(USER_DESC_3) && defined(USER_GCODE_3)
  389. MENU_ITEM(function, USER_DESC_3, lcd_user_gcode_3);
  390. #endif
  391. #if defined(USER_DESC_4) && defined(USER_GCODE_4)
  392. MENU_ITEM(function, USER_DESC_4, lcd_user_gcode_4);
  393. #endif
  394. #if defined(USER_DESC_5) && defined(USER_GCODE_5)
  395. MENU_ITEM(function, USER_DESC_5, lcd_user_gcode_5);
  396. #endif
  397. END_MENU();
  398. }
  399. #endif
  400. #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
  401. void lcd_babystep_zoffset() {
  402. if (use_click()) { return lcd_goto_previous_menu_no_defer(); }
  403. defer_return_to_status = true;
  404. #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
  405. const bool do_probe = (active_extruder == 0);
  406. #else
  407. constexpr bool do_probe = true;
  408. #endif
  409. ENCODER_DIRECTION_NORMAL();
  410. if (encoderPosition) {
  411. const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
  412. encoderPosition = 0;
  413. const float diff = planner.steps_to_mm[Z_AXIS] * babystep_increment,
  414. new_probe_offset = zprobe_zoffset + diff,
  415. new_offs =
  416. #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
  417. do_probe ? new_probe_offset : hotend_offset[Z_AXIS][active_extruder] - diff
  418. #else
  419. new_probe_offset
  420. #endif
  421. ;
  422. if (WITHIN(new_offs, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
  423. thermalManager.babystep_axis(Z_AXIS, babystep_increment);
  424. if (do_probe) zprobe_zoffset = new_offs;
  425. #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
  426. else hotend_offset[Z_AXIS][active_extruder] = new_offs;
  427. #endif
  428. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  429. }
  430. }
  431. if (lcdDrawUpdate) {
  432. #if ENABLED(BABYSTEP_HOTEND_Z_OFFSET)
  433. if (!do_probe)
  434. lcd_implementation_drawedit(PSTR(MSG_IDEX_Z_OFFSET), ftostr43sign(hotend_offset[Z_AXIS][active_extruder]));
  435. else
  436. #endif
  437. lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
  438. #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY)
  439. if (do_probe) _lcd_zoffset_overlay_gfx(zprobe_zoffset);
  440. #endif
  441. }
  442. }
  443. #endif // BABYSTEP_ZPROBE_OFFSET
  444. /**
  445. * Watch temperature callbacks
  446. */
  447. #if HAS_TEMP_HOTEND
  448. #if WATCH_HOTENDS
  449. #define _WATCH_FUNC(N) thermalManager.start_watching_heater(N)
  450. #else
  451. #define _WATCH_FUNC(N) NOOP
  452. #endif
  453. void watch_temp_callback_E0() { _WATCH_FUNC(0); }
  454. #if HOTENDS > 1
  455. void watch_temp_callback_E1() { _WATCH_FUNC(1); }
  456. #if HOTENDS > 2
  457. void watch_temp_callback_E2() { _WATCH_FUNC(2); }
  458. #if HOTENDS > 3
  459. void watch_temp_callback_E3() { _WATCH_FUNC(3); }
  460. #if HOTENDS > 4
  461. void watch_temp_callback_E4() { _WATCH_FUNC(4); }
  462. #if HOTENDS > 5
  463. void watch_temp_callback_E5() { _WATCH_FUNC(5); }
  464. #endif // HOTENDS > 5
  465. #endif // HOTENDS > 4
  466. #endif // HOTENDS > 3
  467. #endif // HOTENDS > 2
  468. #endif // HOTENDS > 1
  469. #endif // HAS_TEMP_HOTEND
  470. void watch_temp_callback_bed() {
  471. #if WATCH_THE_BED
  472. thermalManager.start_watching_bed();
  473. #endif
  474. }
  475. #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(PID_AUTOTUNE_MENU) || ENABLED(ADVANCED_PAUSE_FEATURE)
  476. void lcd_enqueue_command(const char * const cmd) {
  477. no_reentry = true;
  478. enqueue_and_echo_command_now(cmd);
  479. no_reentry = false;
  480. }
  481. void lcd_enqueue_commands_P(PGM_P const cmd) {
  482. no_reentry = true;
  483. enqueue_and_echo_commands_now_P(cmd);
  484. no_reentry = false;
  485. }
  486. #endif
  487. #if ENABLED(EEPROM_SETTINGS)
  488. void lcd_store_settings() { lcd_completion_feedback(settings.save()); }
  489. void lcd_load_settings() { lcd_completion_feedback(settings.load()); }
  490. #endif
  491. void _lcd_draw_homing() {
  492. constexpr uint8_t line = (LCD_HEIGHT - 1) / 2;
  493. if (lcdDrawUpdate) lcd_implementation_drawmenu_static(line, PSTR(MSG_LEVEL_BED_HOMING));
  494. lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
  495. }
  496. #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
  497. void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }
  498. #endif
  499. #if ENABLED(DELTA_CALIBRATION_MENU) || ENABLED(DELTA_AUTO_CALIBRATION)
  500. void _man_probe_pt(const float &rx, const float &ry) {
  501. do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
  502. do_blocking_move_to_xy(rx, ry);
  503. lcd_synchronize();
  504. move_menu_scale = MAX(PROBE_MANUALLY_STEP, MIN_STEPS_PER_SEGMENT / float(DEFAULT_XYZ_STEPS_PER_UNIT));
  505. lcd_goto_screen(lcd_move_z);
  506. }
  507. #endif // DELTA_CALIBRATION_MENU || DELTA_AUTO_CALIBRATION
  508. #if ENABLED(DELTA_AUTO_CALIBRATION)
  509. float lcd_probe_pt(const float &rx, const float &ry) {
  510. _man_probe_pt(rx, ry);
  511. KEEPALIVE_STATE(PAUSED_FOR_USER);
  512. defer_return_to_status = true;
  513. wait_for_user = true;
  514. while (wait_for_user) idle();
  515. KEEPALIVE_STATE(IN_HANDLER);
  516. lcd_goto_previous_menu_no_defer();
  517. return current_position[Z_AXIS];
  518. }
  519. #endif // DELTA_AUTO_CALIBRATION
  520. #if ENABLED(DELTA_CALIBRATION_MENU)
  521. void _lcd_calibrate_homing() {
  522. _lcd_draw_homing();
  523. if (all_axes_homed()) lcd_goto_previous_menu();
  524. }
  525. void _lcd_delta_calibrate_home() {
  526. enqueue_and_echo_commands_P(PSTR("G28"));
  527. lcd_goto_screen(_lcd_calibrate_homing);
  528. }
  529. void _goto_tower_x() { _man_probe_pt(cos(RADIANS(210)) * delta_calibration_radius, sin(RADIANS(210)) * delta_calibration_radius); }
  530. void _goto_tower_y() { _man_probe_pt(cos(RADIANS(330)) * delta_calibration_radius, sin(RADIANS(330)) * delta_calibration_radius); }
  531. void _goto_tower_z() { _man_probe_pt(cos(RADIANS( 90)) * delta_calibration_radius, sin(RADIANS( 90)) * delta_calibration_radius); }
  532. void _goto_center() { _man_probe_pt(0,0); }
  533. #endif // DELTA_CALIBRATION_MENU
  534. #if ENABLED(DELTA_CALIBRATION_MENU) || ENABLED(DELTA_AUTO_CALIBRATION)
  535. void _recalc_delta_settings() {
  536. #if HAS_LEVELING
  537. reset_bed_level(); // After changing kinematics bed-level data is no longer valid
  538. #endif
  539. recalc_delta_settings();
  540. }
  541. void lcd_delta_settings() {
  542. START_MENU();
  543. MENU_BACK(MSG_DELTA_CALIBRATE);
  544. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_HEIGHT, &delta_height, delta_height - 10, delta_height + 10, _recalc_delta_settings);
  545. MENU_ITEM_EDIT_CALLBACK(float43, "Ex", &delta_endstop_adj[A_AXIS], -5, 5, _recalc_delta_settings);
  546. MENU_ITEM_EDIT_CALLBACK(float43, "Ey", &delta_endstop_adj[B_AXIS], -5, 5, _recalc_delta_settings);
  547. MENU_ITEM_EDIT_CALLBACK(float43, "Ez", &delta_endstop_adj[C_AXIS], -5, 5, _recalc_delta_settings);
  548. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_RADIUS, &delta_radius, delta_radius - 5, delta_radius + 5, _recalc_delta_settings);
  549. MENU_ITEM_EDIT_CALLBACK(float43, "Tx", &delta_tower_angle_trim[A_AXIS], -5, 5, _recalc_delta_settings);
  550. MENU_ITEM_EDIT_CALLBACK(float43, "Ty", &delta_tower_angle_trim[B_AXIS], -5, 5, _recalc_delta_settings);
  551. MENU_ITEM_EDIT_CALLBACK(float43, "Tz", &delta_tower_angle_trim[C_AXIS], -5, 5, _recalc_delta_settings);
  552. MENU_ITEM_EDIT_CALLBACK(float52sign, MSG_DELTA_DIAG_ROD, &delta_diagonal_rod, delta_diagonal_rod - 5, delta_diagonal_rod + 5, _recalc_delta_settings);
  553. END_MENU();
  554. }
  555. void menu_delta_calibrate() {
  556. START_MENU();
  557. MENU_BACK(MSG_MAIN);
  558. #if ENABLED(DELTA_AUTO_CALIBRATION)
  559. MENU_ITEM(gcode, MSG_DELTA_AUTO_CALIBRATE, PSTR("G33"));
  560. MENU_ITEM(gcode, MSG_DELTA_HEIGHT_CALIBRATE, PSTR("G33 S P1"));
  561. MENU_ITEM(gcode, MSG_DELTA_Z_OFFSET_CALIBRATE, PSTR("G33 P-1"));
  562. #if ENABLED(EEPROM_SETTINGS)
  563. MENU_ITEM(function, MSG_STORE_EEPROM, lcd_store_settings);
  564. MENU_ITEM(function, MSG_LOAD_EEPROM, lcd_load_settings);
  565. #endif
  566. #endif
  567. MENU_ITEM(submenu, MSG_DELTA_SETTINGS, lcd_delta_settings);
  568. #if ENABLED(DELTA_CALIBRATION_MENU)
  569. MENU_ITEM(submenu, MSG_AUTO_HOME, _lcd_delta_calibrate_home);
  570. if (all_axes_homed()) {
  571. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_X, _goto_tower_x);
  572. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Y, _goto_tower_y);
  573. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_Z, _goto_tower_z);
  574. MENU_ITEM(submenu, MSG_DELTA_CALIBRATE_CENTER, _goto_center);
  575. }
  576. #endif
  577. END_MENU();
  578. }
  579. #endif // DELTA_CALIBRATION_MENU || DELTA_AUTO_CALIBRATION
  580. #if ENABLED(SDSUPPORT)
  581. #if !PIN_EXISTS(SD_DETECT)
  582. void lcd_sd_refresh() {
  583. card.initsd();
  584. encoderTopLine = 0;
  585. }
  586. #endif
  587. void lcd_sd_updir() {
  588. encoderPosition = card.updir() ? ENCODER_STEPS_PER_MENU_ITEM : 0;
  589. encoderTopLine = 0;
  590. screen_changed = true;
  591. lcd_refresh();
  592. }
  593. /**
  594. *
  595. * "Print from SD" submenu
  596. *
  597. */
  598. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  599. uint32_t last_sdfile_encoderPosition = 0xFFFF;
  600. void lcd_reselect_last_file() {
  601. if (last_sdfile_encoderPosition == 0xFFFF) return;
  602. #if HAS_GRAPHICAL_LCD
  603. // Some of this is a hack to force the screen update to work.
  604. // TODO: Fix the real issue that causes this!
  605. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  606. lcd_synchronize();
  607. safe_delay(50);
  608. lcd_synchronize();
  609. lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
  610. drawing_screen = screen_changed = true;
  611. #endif
  612. lcd_goto_screen(menu_sdcard, last_sdfile_encoderPosition);
  613. defer_return_to_status = true;
  614. last_sdfile_encoderPosition = 0xFFFF;
  615. #if HAS_GRAPHICAL_LCD
  616. lcd_update();
  617. #endif
  618. }
  619. #endif
  620. void menu_sdcard() {
  621. ENCODER_DIRECTION_MENUS();
  622. const uint16_t fileCnt = card.get_num_Files();
  623. START_MENU();
  624. MENU_BACK(MSG_MAIN);
  625. card.getWorkDirName();
  626. if (card.filename[0] == '/') {
  627. #if !PIN_EXISTS(SD_DETECT)
  628. MENU_ITEM(function, LCD_STR_REFRESH MSG_REFRESH, lcd_sd_refresh);
  629. #endif
  630. }
  631. else {
  632. MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
  633. }
  634. for (uint16_t i = 0; i < fileCnt; i++) {
  635. if (_menuLineNr == _thisItemNr) {
  636. const uint16_t nr =
  637. #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
  638. fileCnt - 1 -
  639. #endif
  640. i;
  641. #if ENABLED(SDCARD_SORT_ALPHA)
  642. card.getfilename_sorted(nr);
  643. #else
  644. card.getfilename(nr);
  645. #endif
  646. if (card.filenameIsDir)
  647. MENU_ITEM(sddirectory, MSG_CARD_MENU, card);
  648. else
  649. MENU_ITEM(sdfile, MSG_CARD_MENU, card);
  650. }
  651. else {
  652. MENU_ITEM_DUMMY();
  653. }
  654. }
  655. END_MENU();
  656. }
  657. #endif // SDSUPPORT
  658. #endif // ULTIPANEL