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.

marlinui.h 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701
  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. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. #include "../module/motion.h"
  25. #include "buttons.h"
  26. #if HAS_BUZZER
  27. #include "../libs/buzzer.h"
  28. #endif
  29. #if ENABLED(SDSUPPORT)
  30. #include "../sd/cardreader.h"
  31. #endif
  32. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  33. #include "tft_io/touch_calibration.h"
  34. #endif
  35. #if ANY(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY, SOFT_RESET_ON_KILL)
  36. #define HAS_ENCODER_ACTION 1
  37. #endif
  38. #if HAS_STATUS_MESSAGE
  39. #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U)
  40. #endif
  41. #if E_MANUAL > 1
  42. #define MULTI_E_MANUAL 1
  43. #endif
  44. #if HAS_DISPLAY
  45. #include "../module/printcounter.h"
  46. #endif
  47. #if ENABLED(ADVANCED_PAUSE_FEATURE) && EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
  48. #include "../feature/pause.h"
  49. #include "../module/motion.h" // for active_extruder
  50. #endif
  51. #define START_OF_UTF8_CHAR(C) (((C) & 0xC0u) != 0x80U)
  52. #if HAS_WIRED_LCD
  53. enum LCDViewAction : uint8_t {
  54. LCDVIEW_NONE,
  55. LCDVIEW_REDRAW_NOW,
  56. LCDVIEW_CALL_REDRAW_NEXT,
  57. LCDVIEW_CLEAR_CALL_REDRAW,
  58. LCDVIEW_CALL_NO_REDRAW
  59. };
  60. #if HAS_ADC_BUTTONS
  61. uint8_t get_ADC_keyValue();
  62. #endif
  63. #define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_BUTTONS, 50, 100)
  64. #if HAS_LCD_MENU
  65. #include "lcdprint.h"
  66. #if !HAS_GRAPHICAL_TFT
  67. void _wrap_string(uint8_t &col, uint8_t &row, const char * const string, read_byte_cb_t cb_read_byte, const bool wordwrap=false);
  68. inline void wrap_string_P(uint8_t &col, uint8_t &row, PGM_P const pstr, const bool wordwrap=false) { _wrap_string(col, row, pstr, read_byte_rom, wordwrap); }
  69. inline void wrap_string(uint8_t &col, uint8_t &row, const char * const string, const bool wordwrap=false) { _wrap_string(col, row, string, read_byte_ram, wordwrap); }
  70. #endif
  71. typedef void (*screenFunc_t)();
  72. typedef void (*menuAction_t)();
  73. #endif // HAS_LCD_MENU
  74. #endif // HAS_WIRED_LCD
  75. #if HAS_MARLINUI_U8GLIB
  76. enum MarlinFont : uint8_t {
  77. FONT_STATUSMENU = 1,
  78. FONT_EDIT,
  79. FONT_MENU
  80. };
  81. #else
  82. enum HD44780CharSet : uint8_t {
  83. CHARSET_MENU,
  84. CHARSET_INFO,
  85. CHARSET_BOOT
  86. };
  87. #endif
  88. #if PREHEAT_COUNT
  89. typedef struct {
  90. #if HAS_HOTEND
  91. celsius_t hotend_temp;
  92. #endif
  93. #if HAS_HEATED_BED
  94. celsius_t bed_temp;
  95. #endif
  96. #if HAS_FAN
  97. uint16_t fan_speed;
  98. #endif
  99. } preheat_t;
  100. #endif
  101. #if HAS_LCD_MENU
  102. // Manual Movement class
  103. class ManualMove {
  104. private:
  105. static AxisEnum axis;
  106. #if MULTI_E_MANUAL
  107. static int8_t e_index;
  108. #else
  109. static int8_t constexpr e_index = 0;
  110. #endif
  111. static millis_t start_time;
  112. #if IS_KINEMATIC
  113. static xyze_pos_t all_axes_destination;
  114. #endif
  115. public:
  116. static float menu_scale;
  117. #if IS_KINEMATIC
  118. static float offset;
  119. #endif
  120. template <typename T>
  121. void set_destination(const T& dest) {
  122. #if IS_KINEMATIC
  123. // Moves are segmented, so the entire move is not submitted at once.
  124. // Using a separate variable prevents corrupting the in-progress move.
  125. all_axes_destination = current_position;
  126. all_axes_destination.set(dest);
  127. #else
  128. // Moves are submitted as single line to the planner using buffer_line.
  129. current_position.set(dest);
  130. #endif
  131. }
  132. float axis_value(const AxisEnum axis) {
  133. return NATIVE_TO_LOGICAL(processing ? destination[axis] : SUM_TERN(IS_KINEMATIC, current_position[axis], offset), axis);
  134. }
  135. bool apply_diff(const AxisEnum axis, const_float_t diff, const_float_t min, const_float_t max) {
  136. #if IS_KINEMATIC
  137. float &valref = offset;
  138. const float rmin = min - current_position[axis], rmax = max - current_position[axis];
  139. #else
  140. float &valref = current_position[axis];
  141. const float rmin = min, rmax = max;
  142. #endif
  143. valref += diff;
  144. const float pre = valref;
  145. if (min != max) {
  146. if (diff < 0)
  147. NOLESS(valref, rmin);
  148. else
  149. NOMORE(valref, rmax);
  150. }
  151. return pre != valref;
  152. }
  153. #if IS_KINEMATIC
  154. static bool processing;
  155. #else
  156. static bool constexpr processing = false;
  157. #endif
  158. static void task();
  159. static void soon(const AxisEnum axis OPTARG(MULTI_E_MANUAL, const int8_t eindex=active_extruder));
  160. };
  161. #endif
  162. ////////////////////////////////////////////
  163. //////////// MarlinUI Singleton ////////////
  164. ////////////////////////////////////////////
  165. class MarlinUI {
  166. public:
  167. MarlinUI() {
  168. TERN_(HAS_LCD_MENU, currentScreen = status_screen);
  169. }
  170. #if HAS_MULTI_LANGUAGE
  171. static uint8_t language;
  172. static void set_language(const uint8_t lang);
  173. #endif
  174. #if HAS_MARLINUI_U8GLIB
  175. static void update_language_font();
  176. #endif
  177. #if ENABLED(SOUND_MENU_ITEM)
  178. static bool buzzer_enabled; // Initialized by settings.load()
  179. #else
  180. static constexpr bool buzzer_enabled = true;
  181. #endif
  182. #if HAS_BUZZER
  183. static void buzz(const long duration, const uint16_t freq);
  184. #endif
  185. FORCE_INLINE static void chirp() {
  186. TERN_(HAS_CHIRP, buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
  187. }
  188. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  189. static void update_indicators();
  190. #endif
  191. // LCD implementations
  192. static void clear_lcd();
  193. #if BOTH(HAS_LCD_MENU, TOUCH_SCREEN_CALIBRATION)
  194. static void check_touch_calibration() {
  195. if (touch_calibration.need_calibration()) currentScreen = touch_calibration_screen;
  196. }
  197. #endif
  198. #if ENABLED(SDSUPPORT)
  199. #define MEDIA_MENU_GATEWAY TERN(PASSWORD_ON_SD_PRINT_MENU, password.media_gatekeeper, menu_media)
  200. static void media_changed(const uint8_t old_stat, const uint8_t stat);
  201. #endif
  202. #if ENABLED(DWIN_CREALITY_LCD)
  203. static void refresh();
  204. #else
  205. FORCE_INLINE static void refresh() {
  206. TERN_(HAS_WIRED_LCD, refresh(LCDVIEW_CLEAR_CALL_REDRAW));
  207. }
  208. #endif
  209. #if HAS_WIRED_LCD
  210. static bool detected();
  211. static void init_lcd();
  212. #else
  213. static inline bool detected() { return true; }
  214. static inline void init_lcd() {}
  215. #endif
  216. #if HAS_PRINT_PROGRESS
  217. #if HAS_PRINT_PROGRESS_PERMYRIAD
  218. typedef uint16_t progress_t;
  219. #define PROGRESS_SCALE 100U
  220. #define PROGRESS_MASK 0x7FFF
  221. #else
  222. typedef uint8_t progress_t;
  223. #define PROGRESS_SCALE 1U
  224. #define PROGRESS_MASK 0x7F
  225. #endif
  226. #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
  227. static progress_t progress_override;
  228. static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
  229. static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
  230. static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
  231. #if ENABLED(SHOW_REMAINING_TIME)
  232. static inline uint32_t _calculated_remaining_time() {
  233. const duration_t elapsed = print_job_timer.duration();
  234. const progress_t progress = _get_progress();
  235. return progress ? elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress : 0;
  236. }
  237. #if ENABLED(USE_M73_REMAINING_TIME)
  238. static uint32_t remaining_time;
  239. FORCE_INLINE static void set_remaining_time(const uint32_t r) { remaining_time = r; }
  240. FORCE_INLINE static uint32_t get_remaining_time() { return remaining_time ?: _calculated_remaining_time(); }
  241. FORCE_INLINE static void reset_remaining_time() { set_remaining_time(0); }
  242. #else
  243. FORCE_INLINE static uint32_t get_remaining_time() { return _calculated_remaining_time(); }
  244. #endif
  245. #endif
  246. #endif
  247. static progress_t _get_progress();
  248. #if HAS_PRINT_PROGRESS_PERMYRIAD
  249. FORCE_INLINE static uint16_t get_progress_permyriad() { return _get_progress(); }
  250. #endif
  251. static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
  252. #else
  253. static constexpr uint8_t get_progress_percent() { return 0; }
  254. #endif
  255. #if HAS_STATUS_MESSAGE
  256. #if HAS_WIRED_LCD
  257. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  258. #define MAX_MESSAGE_LENGTH _MAX(LONG_FILENAME_LENGTH, MAX_LANG_CHARSIZE * 2 * (LCD_WIDTH))
  259. #else
  260. #define MAX_MESSAGE_LENGTH (MAX_LANG_CHARSIZE * (LCD_WIDTH))
  261. #endif
  262. #else
  263. #define MAX_MESSAGE_LENGTH 63
  264. #endif
  265. static char status_message[];
  266. static uint8_t alert_level; // Higher levels block lower levels
  267. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  268. static uint8_t status_scroll_offset;
  269. static void advance_status_scroll();
  270. static char* status_and_len(uint8_t &len);
  271. #endif
  272. static bool has_status();
  273. static void reset_status(const bool no_welcome=false);
  274. static void set_status(const char * const message, const bool persist=false);
  275. static void set_status_P(PGM_P const message, const int8_t level=0);
  276. static void status_printf_P(const uint8_t level, PGM_P const fmt, ...);
  277. static void set_alert_status_P(PGM_P const message);
  278. static inline void reset_alert_level() { alert_level = 0; }
  279. #else
  280. static constexpr bool has_status() { return false; }
  281. static inline void reset_status(const bool=false) {}
  282. static void set_status(const char *message, const bool=false);
  283. static void set_status_P(PGM_P message, const int8_t=0);
  284. static void status_printf_P(const uint8_t, PGM_P message, ...);
  285. static inline void set_alert_status_P(PGM_P const) {}
  286. static inline void reset_alert_level() {}
  287. #endif
  288. #if HAS_DISPLAY
  289. static void init();
  290. static void update();
  291. static void abort_print();
  292. static void pause_print();
  293. static void resume_print();
  294. static void flow_fault();
  295. #if BOTH(PSU_CONTROL, PS_OFF_CONFIRM)
  296. static void poweroff();
  297. #endif
  298. #if HAS_WIRED_LCD
  299. static millis_t next_button_update_ms;
  300. static LCDViewAction lcdDrawUpdate;
  301. FORCE_INLINE static bool should_draw() { return bool(lcdDrawUpdate); }
  302. FORCE_INLINE static void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
  303. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  304. static void draw_custom_bootscreen(const uint8_t frame=0);
  305. static void show_custom_bootscreen();
  306. #endif
  307. #if ENABLED(SHOW_BOOTSCREEN)
  308. #ifndef BOOTSCREEN_TIMEOUT
  309. #define BOOTSCREEN_TIMEOUT 2500
  310. #endif
  311. static void draw_marlin_bootscreen(const bool line2=false);
  312. static void show_marlin_bootscreen();
  313. static void show_bootscreen();
  314. static void bootscreen_completion(const millis_t sofar);
  315. #endif
  316. #if HAS_MARLINUI_U8GLIB
  317. static void set_font(const MarlinFont font_nr);
  318. #else
  319. static void set_custom_characters(const HD44780CharSet screen_charset=CHARSET_INFO);
  320. #if ENABLED(LCD_PROGRESS_BAR)
  321. static millis_t progress_bar_ms; // Start time for the current progress bar cycle
  322. static void draw_progress_bar(const uint8_t percent);
  323. #if PROGRESS_MSG_EXPIRE > 0
  324. static millis_t expire_status_ms; // = 0
  325. FORCE_INLINE static void reset_progress_bar_timeout() { expire_status_ms = 0; }
  326. #endif
  327. #endif
  328. #endif
  329. static uint8_t lcd_status_update_delay;
  330. #if HAS_LCD_CONTRAST
  331. static int16_t contrast;
  332. static void set_contrast(const int16_t value);
  333. FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
  334. #endif
  335. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  336. static millis_t next_filament_display;
  337. #endif
  338. static void quick_feedback(const bool clear_buttons=true);
  339. #if HAS_BUZZER
  340. static void completion_feedback(const bool good=true);
  341. #else
  342. static inline void completion_feedback(const bool=true) {}
  343. #endif
  344. #if DISABLED(LIGHTWEIGHT_UI)
  345. static void draw_status_message(const bool blink);
  346. #endif
  347. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  348. static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
  349. #endif
  350. #if HAS_TOUCH_BUTTONS
  351. static bool on_edit_screen;
  352. static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
  353. #endif
  354. static void status_screen();
  355. #endif
  356. #if HAS_MARLINUI_U8GLIB
  357. static bool drawing_screen, first_page;
  358. #else
  359. static constexpr bool drawing_screen = false, first_page = true;
  360. #endif
  361. static bool get_blink();
  362. static void kill_screen(PGM_P const lcd_error, PGM_P const lcd_component);
  363. static void draw_kill_screen();
  364. #else // No LCD
  365. static inline void init() {}
  366. static inline void update() {}
  367. static inline void return_to_status() {}
  368. #endif
  369. #if ENABLED(SDSUPPORT)
  370. #if BOTH(SCROLL_LONG_FILENAMES, HAS_LCD_MENU)
  371. #define MARLINUI_SCROLL_NAME 1
  372. #endif
  373. #if MARLINUI_SCROLL_NAME
  374. static uint8_t filename_scroll_pos, filename_scroll_max;
  375. #endif
  376. static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
  377. #endif
  378. #if PREHEAT_COUNT
  379. static preheat_t material_preset[PREHEAT_COUNT];
  380. static PGM_P get_preheat_label(const uint8_t m);
  381. #endif
  382. #if SCREENS_CAN_TIME_OUT
  383. static inline void reset_status_timeout(const millis_t ms) { return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS; }
  384. #else
  385. static inline void reset_status_timeout(const millis_t) {}
  386. #endif
  387. #if HAS_LCD_MENU
  388. #if HAS_TOUCH_BUTTONS
  389. static uint8_t touch_buttons;
  390. static uint8_t repeat_delay;
  391. #else
  392. static constexpr uint8_t touch_buttons = 0;
  393. #endif
  394. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  395. static bool encoderRateMultiplierEnabled;
  396. static millis_t lastEncoderMovementMillis;
  397. static void enable_encoder_multiplier(const bool onoff);
  398. #define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
  399. #else
  400. #define ENCODER_RATE_MULTIPLY(F) NOOP
  401. #endif
  402. // Manual Movement
  403. static ManualMove manual_move;
  404. // Select Screen (modal NO/YES style dialog)
  405. static bool selection;
  406. static void set_selection(const bool sel) { selection = sel; }
  407. static bool update_selection();
  408. static void synchronize(PGM_P const msg=nullptr);
  409. static screenFunc_t currentScreen;
  410. static bool screen_changed;
  411. static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
  412. static void push_current_screen();
  413. // goto_previous_screen and go_back may also be used as menu item callbacks
  414. static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
  415. static inline void goto_previous_screen() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, false)); }
  416. static inline void go_back() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, true)); }
  417. static void return_to_status();
  418. static inline bool on_status_screen() { return currentScreen == status_screen; }
  419. FORCE_INLINE static void run_current_screen() { (*currentScreen)(); }
  420. #if ENABLED(LIGHTWEIGHT_UI)
  421. static void lcd_in_status(const bool inStatus);
  422. #endif
  423. FORCE_INLINE static bool screen_is_sticky() {
  424. return TERN1(SCREENS_CAN_TIME_OUT, defer_return_to_status);
  425. }
  426. FORCE_INLINE static void defer_status_screen(const bool defer=true) {
  427. TERN(SCREENS_CAN_TIME_OUT, defer_return_to_status = defer, UNUSED(defer));
  428. }
  429. static inline void goto_previous_screen_no_defer() {
  430. defer_status_screen(false);
  431. goto_previous_screen();
  432. }
  433. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  434. static void reselect_last_file();
  435. #endif
  436. #if ENABLED(AUTO_BED_LEVELING_UBL)
  437. static void ubl_plot(const uint8_t x_plot, const uint8_t y_plot);
  438. #endif
  439. #if ENABLED(AUTO_BED_LEVELING_UBL)
  440. static void ubl_mesh_edit_start(const_float_t initial);
  441. static float ubl_mesh_value();
  442. #endif
  443. static void draw_select_screen_prompt(PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr);
  444. #else
  445. static constexpr bool on_status_screen() { return true; }
  446. #if HAS_WIRED_LCD
  447. FORCE_INLINE static void run_current_screen() { status_screen(); }
  448. #endif
  449. #endif
  450. #if EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
  451. static bool lcd_clicked;
  452. static inline bool use_click() {
  453. const bool click = lcd_clicked;
  454. lcd_clicked = false;
  455. return click;
  456. }
  457. #else
  458. static constexpr bool lcd_clicked = false;
  459. static inline bool use_click() { return false; }
  460. #endif
  461. #if ENABLED(ADVANCED_PAUSE_FEATURE) && EITHER(HAS_LCD_MENU, EXTENSIBLE_UI)
  462. static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder);
  463. #else
  464. static inline void _pause_show_message() {}
  465. #define pause_show_message(...) _pause_show_message()
  466. #endif
  467. //
  468. // EEPROM: Reset / Init / Load / Store
  469. //
  470. #if HAS_LCD_MENU
  471. static void reset_settings();
  472. #endif
  473. #if ENABLED(EEPROM_SETTINGS)
  474. #if HAS_LCD_MENU
  475. static void init_eeprom();
  476. static void load_settings();
  477. static void store_settings();
  478. #endif
  479. #if DISABLED(EEPROM_AUTO_INIT)
  480. static void eeprom_alert(const uint8_t msgid);
  481. static inline void eeprom_alert_crc() { eeprom_alert(0); }
  482. static inline void eeprom_alert_index() { eeprom_alert(1); }
  483. static inline void eeprom_alert_version() { eeprom_alert(2); }
  484. #endif
  485. #endif
  486. //
  487. // Special handling if a move is underway
  488. //
  489. #if ANY(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION, PROBE_OFFSET_WIZARD) || (ENABLED(LCD_BED_LEVELING) && EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))
  490. #define LCD_HAS_WAIT_FOR_MOVE 1
  491. static bool wait_for_move;
  492. #else
  493. static constexpr bool wait_for_move = false;
  494. #endif
  495. //
  496. // Block interaction while under external control
  497. //
  498. #if HAS_LCD_MENU && EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  499. static bool external_control;
  500. FORCE_INLINE static void capture() { external_control = true; }
  501. FORCE_INLINE static void release() { external_control = false; }
  502. #if ENABLED(AUTO_BED_LEVELING_UBL)
  503. static void external_encoder();
  504. #endif
  505. #else
  506. static constexpr bool external_control = false;
  507. #endif
  508. #if HAS_ENCODER_ACTION
  509. static volatile uint8_t buttons;
  510. #if IS_RRW_KEYPAD
  511. static volatile uint8_t keypad_buttons;
  512. static bool handle_keypad();
  513. #endif
  514. #if HAS_SLOW_BUTTONS
  515. static volatile uint8_t slow_buttons;
  516. static uint8_t read_slow_buttons();
  517. #endif
  518. static void update_buttons();
  519. static inline bool button_pressed() { return BUTTON_CLICK() || TERN(TOUCH_SCREEN, touch_pressed(), false); }
  520. #if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  521. static void wait_for_release();
  522. #endif
  523. static uint32_t encoderPosition;
  524. #define ENCODERBASE (TERN(REVERSE_ENCODER_DIRECTION, -1, +1))
  525. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  526. static int8_t encoderDirection;
  527. #else
  528. static constexpr int8_t encoderDirection = ENCODERBASE;
  529. #endif
  530. FORCE_INLINE static void encoder_direction_normal() {
  531. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  532. encoderDirection = ENCODERBASE;
  533. #endif
  534. }
  535. FORCE_INLINE static void encoder_direction_menus() {
  536. TERN_(REVERSE_MENU_DIRECTION, encoderDirection = -(ENCODERBASE));
  537. }
  538. FORCE_INLINE static void encoder_direction_select() {
  539. TERN_(REVERSE_SELECT_DIRECTION, encoderDirection = -(ENCODERBASE));
  540. }
  541. #else
  542. static inline void update_buttons() {}
  543. #endif
  544. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  545. static void touch_calibration_screen();
  546. #endif
  547. #if HAS_GRAPHICAL_TFT
  548. static void move_axis_screen();
  549. #endif
  550. private:
  551. #if SCREENS_CAN_TIME_OUT
  552. static millis_t return_to_status_ms;
  553. static bool defer_return_to_status;
  554. #else
  555. static constexpr bool defer_return_to_status = false;
  556. #endif
  557. #if HAS_STATUS_MESSAGE
  558. static void finish_status(const bool persist);
  559. #endif
  560. #if HAS_WIRED_LCD
  561. static void draw_status_screen();
  562. #if HAS_GRAPHICAL_TFT
  563. static void tft_idle();
  564. #if ENABLED(TOUCH_SCREEN)
  565. static bool touch_pressed();
  566. #endif
  567. #endif
  568. #endif
  569. };
  570. extern MarlinUI ui;
  571. #define LCD_MESSAGEPGM_P(x) ui.set_status_P(x)
  572. #define LCD_ALERTMESSAGEPGM_P(x) ui.set_alert_status_P(x)
  573. #define LCD_MESSAGEPGM(x) LCD_MESSAGEPGM_P(GET_TEXT(x))
  574. #define LCD_ALERTMESSAGEPGM(x) LCD_ALERTMESSAGEPGM_P(GET_TEXT(x))