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.

ultralcd.h 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716
  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. #if HAS_BUZZER
  25. #include "../libs/buzzer.h"
  26. #endif
  27. #if ENABLED(SDSUPPORT)
  28. #include "../sd/cardreader.h"
  29. #endif
  30. #if EITHER(HAS_LCD_MENU, ULTIPANEL_FEEDMULTIPLY)
  31. #define HAS_ENCODER_ACTION 1
  32. #endif
  33. #if ((!HAS_ADC_BUTTONS && IS_NEWPANEL) || BUTTONS_EXIST(EN1, EN2)) && !IS_TFTGLCD_PANEL
  34. #define HAS_ENCODER_WHEEL 1
  35. #endif
  36. #if HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)
  37. #define HAS_DIGITAL_BUTTONS 1
  38. #endif
  39. #if !HAS_ADC_BUTTONS && (IS_RRW_KEYPAD || (HAS_WIRED_LCD && !IS_NEWPANEL))
  40. #define HAS_SHIFT_ENCODER 1
  41. #endif
  42. // I2C buttons must be read in the main thread
  43. #if ANY(LCD_I2C_VIKI, LCD_I2C_PANELOLU2, IS_TFTGLCD_PANEL)
  44. #define HAS_SLOW_BUTTONS 1
  45. #endif
  46. #if E_MANUAL > 1
  47. #define MULTI_MANUAL 1
  48. #endif
  49. #if HAS_WIRED_LCD
  50. #include "../MarlinCore.h"
  51. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  52. #include "../feature/pause.h"
  53. #include "../module/motion.h" // for active_extruder
  54. #endif
  55. enum LCDViewAction : uint8_t {
  56. LCDVIEW_NONE,
  57. LCDVIEW_REDRAW_NOW,
  58. LCDVIEW_CALL_REDRAW_NEXT,
  59. LCDVIEW_CLEAR_CALL_REDRAW,
  60. LCDVIEW_CALL_NO_REDRAW
  61. };
  62. #if HAS_ADC_BUTTONS
  63. uint8_t get_ADC_keyValue();
  64. #endif
  65. #define LCD_UPDATE_INTERVAL TERN(HAS_TOUCH_XPT2046, 50, 100)
  66. #if HAS_LCD_MENU
  67. #include "lcdprint.h"
  68. void _wrap_string(uint8_t &col, uint8_t &row, const char * const string, read_byte_cb_t cb_read_byte, const bool wordwrap=false);
  69. 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); }
  70. 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); }
  71. #if ENABLED(SDSUPPORT)
  72. #include "../sd/cardreader.h"
  73. #endif
  74. typedef void (*screenFunc_t)();
  75. typedef void (*menuAction_t)();
  76. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  77. void lcd_pause_show_message(const PauseMessage message,
  78. const PauseMode mode=PAUSE_MODE_SAME,
  79. const uint8_t extruder=active_extruder);
  80. #endif
  81. #if ENABLED(AUTO_BED_LEVELING_UBL)
  82. void lcd_mesh_edit_setup(const float &initial);
  83. float lcd_mesh_edit();
  84. #endif
  85. #endif // HAS_LCD_MENU
  86. #endif // HAS_WIRED_LCD
  87. #if IS_RRW_KEYPAD
  88. #define BTN_OFFSET 0 // Bit offset into buttons for shift register values
  89. #define BLEN_KEYPAD_F3 0
  90. #define BLEN_KEYPAD_F2 1
  91. #define BLEN_KEYPAD_F1 2
  92. #define BLEN_KEYPAD_DOWN 3
  93. #define BLEN_KEYPAD_RIGHT 4
  94. #define BLEN_KEYPAD_MIDDLE 5
  95. #define BLEN_KEYPAD_UP 6
  96. #define BLEN_KEYPAD_LEFT 7
  97. #define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1)
  98. #define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2)
  99. #define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3)
  100. #define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN)
  101. #define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT)
  102. #define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE)
  103. #define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP)
  104. #define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT)
  105. #define RRK(B) (keypad_buttons & (B))
  106. #ifdef EN_C
  107. #define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE))
  108. #else
  109. #define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE)
  110. #endif
  111. #endif // IS_RRW_KEYPAD
  112. #if HAS_DIGITAL_BUTTONS
  113. // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
  114. #define BLEN_A 0
  115. #define BLEN_B 1
  116. #define EN_A _BV(BLEN_A)
  117. #define EN_B _BV(BLEN_B)
  118. #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
  119. #if BUTTON_EXISTS(ENC) || HAS_TOUCH_XPT2046
  120. #define BLEN_C 2
  121. #define EN_C _BV(BLEN_C)
  122. #endif
  123. #if ENABLED(LCD_I2C_VIKI)
  124. #include <LiquidTWI2.h>
  125. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  126. // button and encoder bit positions within 'buttons'
  127. #define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
  128. #define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
  129. #define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
  130. #define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
  131. #define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
  132. #if BUTTON_EXISTS(ENC) // The pause/stop/restart button is connected to BTN_ENC when used
  133. #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
  134. #define BUTTON_CLICK() (buttons & (B_MI|B_RI|B_ST)) // Pause/stop also acts as click until a proper pause/stop is implemented.
  135. #else
  136. #define BUTTON_CLICK() (buttons & (B_MI|B_RI))
  137. #endif
  138. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  139. #elif ENABLED(LCD_I2C_PANELOLU2)
  140. #if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
  141. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  142. #define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
  143. #define BUTTON_CLICK() (buttons & B_MI)
  144. #endif
  145. #endif
  146. #else
  147. #undef BUTTON_EXISTS
  148. #define BUTTON_EXISTS(...) false
  149. // Shift register bits correspond to buttons:
  150. #define BL_LE 7 // Left
  151. #define BL_UP 6 // Up
  152. #define BL_MI 5 // Middle
  153. #define BL_DW 4 // Down
  154. #define BL_RI 3 // Right
  155. #define BL_ST 2 // Red Button
  156. #define B_LE _BV(BL_LE)
  157. #define B_UP _BV(BL_UP)
  158. #define B_MI _BV(BL_MI)
  159. #define B_DW _BV(BL_DW)
  160. #define B_RI _BV(BL_RI)
  161. #define B_ST _BV(BL_ST)
  162. #ifndef BUTTON_CLICK
  163. #define BUTTON_CLICK() (buttons & (B_MI|B_ST))
  164. #endif
  165. #endif
  166. #if BUTTON_EXISTS(BACK) || EITHER(HAS_TOUCH_XPT2046, IS_TFTGLCD_PANEL)
  167. #define BLEN_D 3
  168. #define EN_D _BV(BLEN_D)
  169. #define LCD_BACK_CLICKED() (buttons & EN_D)
  170. #else
  171. #define LCD_BACK_CLICKED() false
  172. #endif
  173. #ifndef BUTTON_CLICK
  174. #ifdef EN_C
  175. #define BUTTON_CLICK() (buttons & EN_C)
  176. #else
  177. #define BUTTON_CLICK() false
  178. #endif
  179. #endif
  180. #if HAS_MARLINUI_U8GLIB
  181. enum MarlinFont : uint8_t {
  182. FONT_STATUSMENU = 1,
  183. FONT_EDIT,
  184. FONT_MENU
  185. };
  186. #else
  187. enum HD44780CharSet : uint8_t {
  188. CHARSET_MENU,
  189. CHARSET_INFO,
  190. CHARSET_BOOT
  191. };
  192. #endif
  193. #if PREHEAT_COUNT
  194. typedef struct {
  195. TERN_(HAS_HOTEND, uint16_t hotend_temp);
  196. TERN_(HAS_HEATED_BED, uint16_t bed_temp );
  197. TERN_(HAS_FAN, uint16_t fan_speed );
  198. } preheat_t;
  199. #endif
  200. #if HAS_LCD_MENU
  201. // Manual Movement class
  202. class ManualMove {
  203. public:
  204. static millis_t start_time;
  205. static float menu_scale;
  206. TERN_(IS_KINEMATIC, static float offset);
  207. #if IS_KINEMATIC
  208. static bool processing;
  209. #else
  210. static bool constexpr processing = false;
  211. #endif
  212. #if MULTI_MANUAL
  213. static int8_t e_index;
  214. #else
  215. static int8_t constexpr e_index = 0;
  216. #endif
  217. static uint8_t axis;
  218. static void task();
  219. static void soon(AxisEnum axis
  220. #if MULTI_MANUAL
  221. , const int8_t eindex=-1
  222. #endif
  223. );
  224. };
  225. #endif
  226. ////////////////////////////////////////////
  227. //////////// MarlinUI Singleton ////////////
  228. ////////////////////////////////////////////
  229. class MarlinUI {
  230. public:
  231. MarlinUI() {
  232. TERN_(HAS_LCD_MENU, currentScreen = status_screen);
  233. }
  234. #if HAS_BUZZER
  235. static void buzz(const long duration, const uint16_t freq);
  236. #endif
  237. FORCE_INLINE static void chirp() {
  238. TERN_(HAS_CHIRP, buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ));
  239. }
  240. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  241. static void update_indicators();
  242. #endif
  243. // LCD implementations
  244. static void clear_lcd();
  245. #if ENABLED(SDSUPPORT)
  246. static void media_changed(const uint8_t old_stat, const uint8_t stat);
  247. #endif
  248. #if ENABLED(DWIN_CREALITY_LCD)
  249. static void refresh();
  250. #else
  251. FORCE_INLINE static void refresh() {
  252. TERN_(HAS_WIRED_LCD, refresh(LCDVIEW_CLEAR_CALL_REDRAW));
  253. }
  254. #endif
  255. #if HAS_WIRED_LCD
  256. static bool detected();
  257. static void init_lcd();
  258. #else
  259. static inline bool detected() { return true; }
  260. static inline void init_lcd() {}
  261. #endif
  262. #if HAS_PRINT_PROGRESS
  263. #if HAS_PRINT_PROGRESS_PERMYRIAD
  264. typedef uint16_t progress_t;
  265. #define PROGRESS_SCALE 100U
  266. #define PROGRESS_MASK 0x7FFF
  267. #else
  268. typedef uint8_t progress_t;
  269. #define PROGRESS_SCALE 1U
  270. #define PROGRESS_MASK 0x7F
  271. #endif
  272. #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
  273. static progress_t progress_override;
  274. static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
  275. static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
  276. static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
  277. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  278. static uint32_t remaining_time;
  279. FORCE_INLINE static void set_remaining_time(const uint32_t r) { remaining_time = r; }
  280. FORCE_INLINE static uint32_t get_remaining_time() { return remaining_time; }
  281. FORCE_INLINE static void reset_remaining_time() { set_remaining_time(0); }
  282. #endif
  283. #endif
  284. static progress_t _get_progress();
  285. #if HAS_PRINT_PROGRESS_PERMYRIAD
  286. FORCE_INLINE static uint16_t get_progress_permyriad() { return _get_progress(); }
  287. #endif
  288. static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
  289. #else
  290. static constexpr uint8_t get_progress_percent() { return 0; }
  291. #endif
  292. #if HAS_DISPLAY
  293. static void init();
  294. static void update();
  295. static void set_alert_status_P(PGM_P const message);
  296. static char status_message[];
  297. static bool has_status();
  298. static uint8_t alert_level; // Higher levels block lower levels
  299. static inline void reset_alert_level() { alert_level = 0; }
  300. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  301. static uint8_t status_scroll_offset;
  302. static void advance_status_scroll();
  303. static char* status_and_len(uint8_t &len);
  304. #endif
  305. static void abort_print();
  306. static void pause_print();
  307. static void resume_print();
  308. #if HAS_WIRED_LCD
  309. static millis_t next_button_update_ms;
  310. static LCDViewAction lcdDrawUpdate;
  311. FORCE_INLINE static bool should_draw() { return bool(lcdDrawUpdate); }
  312. FORCE_INLINE static void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
  313. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  314. static void draw_custom_bootscreen(const uint8_t frame=0);
  315. static void show_custom_bootscreen();
  316. #endif
  317. #if ENABLED(SHOW_BOOTSCREEN)
  318. #ifndef BOOTSCREEN_TIMEOUT
  319. #define BOOTSCREEN_TIMEOUT 2500
  320. #endif
  321. static void draw_marlin_bootscreen(const bool line2=false);
  322. static void show_marlin_bootscreen();
  323. static void show_bootscreen();
  324. #endif
  325. #if HAS_MARLINUI_U8GLIB
  326. static void set_font(const MarlinFont font_nr);
  327. #else
  328. static void set_custom_characters(const HD44780CharSet screen_charset=CHARSET_INFO);
  329. #if ENABLED(LCD_PROGRESS_BAR)
  330. static millis_t progress_bar_ms; // Start time for the current progress bar cycle
  331. static void draw_progress_bar(const uint8_t percent);
  332. #if PROGRESS_MSG_EXPIRE > 0
  333. static millis_t expire_status_ms; // = 0
  334. FORCE_INLINE static void reset_progress_bar_timeout() { expire_status_ms = 0; }
  335. #endif
  336. #endif
  337. #endif
  338. static uint8_t lcd_status_update_delay;
  339. #if HAS_LCD_CONTRAST
  340. static int16_t contrast;
  341. static void set_contrast(const int16_t value);
  342. FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
  343. #endif
  344. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  345. static millis_t next_filament_display;
  346. #endif
  347. static void quick_feedback(const bool clear_buttons=true);
  348. #if HAS_BUZZER
  349. static void completion_feedback(const bool good=true);
  350. #else
  351. static inline void completion_feedback(const bool=true) {}
  352. #endif
  353. #if DISABLED(LIGHTWEIGHT_UI)
  354. static void draw_status_message(const bool blink);
  355. #endif
  356. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  357. static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
  358. #endif
  359. #if HAS_TOUCH_XPT2046
  360. static bool on_edit_screen;
  361. static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
  362. #endif
  363. static void status_screen();
  364. #endif
  365. #if HAS_MARLINUI_U8GLIB
  366. static bool drawing_screen, first_page;
  367. #else
  368. static constexpr bool drawing_screen = false, first_page = true;
  369. #endif
  370. static bool get_blink();
  371. static void kill_screen(PGM_P const lcd_error, PGM_P const lcd_component);
  372. static void draw_kill_screen();
  373. static void set_status(const char* const message, const bool persist=false);
  374. static void set_status_P(PGM_P const message, const int8_t level=0);
  375. static void status_printf_P(const uint8_t level, PGM_P const fmt, ...);
  376. static void reset_status(const bool no_welcome=false);
  377. #else // No LCD
  378. // Send status to host as a notification
  379. static void set_status(const char* message, const bool=false);
  380. static void set_status_P(PGM_P message, const int8_t=0);
  381. static void status_printf_P(const uint8_t, PGM_P message, ...);
  382. static inline void init() {}
  383. static inline void update() {}
  384. static inline void return_to_status() {}
  385. static inline void set_alert_status_P(PGM_P const) {}
  386. static inline void reset_status(const bool=false) {}
  387. static inline void reset_alert_level() {}
  388. static constexpr bool has_status() { return false; }
  389. #endif
  390. #if ENABLED(SDSUPPORT)
  391. #if BOTH(SCROLL_LONG_FILENAMES, HAS_LCD_MENU)
  392. #define MARLINUI_SCROLL_NAME 1
  393. #endif
  394. #if MARLINUI_SCROLL_NAME
  395. static uint8_t filename_scroll_pos, filename_scroll_max;
  396. #endif
  397. static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
  398. #endif
  399. #if PREHEAT_COUNT
  400. static preheat_t material_preset[PREHEAT_COUNT];
  401. static PGM_P get_preheat_label(const uint8_t m);
  402. #endif
  403. #if HAS_LCD_MENU
  404. #if LCD_TIMEOUT_TO_STATUS
  405. static millis_t return_to_status_ms;
  406. #endif
  407. #if HAS_TOUCH_XPT2046
  408. static uint8_t touch_buttons;
  409. static uint8_t repeat_delay;
  410. #endif
  411. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  412. static bool encoderRateMultiplierEnabled;
  413. static millis_t lastEncoderMovementMillis;
  414. static void enable_encoder_multiplier(const bool onoff);
  415. #define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
  416. #else
  417. #define ENCODER_RATE_MULTIPLY(F) NOOP
  418. #endif
  419. // Manual Movement
  420. static ManualMove manual_move;
  421. // Select Screen (modal NO/YES style dialog)
  422. static bool selection;
  423. static void set_selection(const bool sel) { selection = sel; }
  424. static bool update_selection();
  425. static bool lcd_clicked;
  426. static bool use_click();
  427. static void synchronize(PGM_P const msg=nullptr);
  428. static screenFunc_t currentScreen;
  429. static bool screen_changed;
  430. static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
  431. static void save_previous_screen();
  432. // goto_previous_screen and go_back may also be used as menu item callbacks
  433. static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
  434. static inline void goto_previous_screen() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, false)); }
  435. static inline void go_back() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, true)); }
  436. static void return_to_status();
  437. static inline bool on_status_screen() { return currentScreen == status_screen; }
  438. FORCE_INLINE static void run_current_screen() { (*currentScreen)(); }
  439. #if ENABLED(LIGHTWEIGHT_UI)
  440. static void lcd_in_status(const bool inStatus);
  441. #endif
  442. FORCE_INLINE static void defer_status_screen(const bool defer=true) {
  443. #if LCD_TIMEOUT_TO_STATUS > 0
  444. defer_return_to_status = defer;
  445. #else
  446. UNUSED(defer);
  447. #endif
  448. }
  449. static inline void goto_previous_screen_no_defer() {
  450. defer_status_screen(false);
  451. goto_previous_screen();
  452. }
  453. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  454. static void reselect_last_file();
  455. #endif
  456. #if ENABLED(AUTO_BED_LEVELING_UBL)
  457. static void ubl_plot(const uint8_t x_plot, const uint8_t y_plot);
  458. #endif
  459. static void draw_select_screen_prompt(PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr);
  460. #elif HAS_WIRED_LCD
  461. static constexpr bool lcd_clicked = false;
  462. static constexpr bool on_status_screen() { return true; }
  463. FORCE_INLINE static void run_current_screen() { status_screen(); }
  464. #endif
  465. //
  466. // EEPROM: Reset / Init / Load / Store
  467. //
  468. #if HAS_LCD_MENU
  469. static void reset_settings();
  470. #endif
  471. #if ENABLED(EEPROM_SETTINGS)
  472. #if HAS_LCD_MENU
  473. static void init_eeprom();
  474. static void load_settings();
  475. static void store_settings();
  476. #endif
  477. #if DISABLED(EEPROM_AUTO_INIT)
  478. static void eeprom_alert(const uint8_t msgid);
  479. static inline void eeprom_alert_crc() { eeprom_alert(0); }
  480. static inline void eeprom_alert_index() { eeprom_alert(1); }
  481. static inline void eeprom_alert_version() { eeprom_alert(2); }
  482. #endif
  483. #endif
  484. //
  485. // Special handling if a move is underway
  486. //
  487. #if EITHER(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION) || (ENABLED(LCD_BED_LEVELING) && EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))
  488. #define LCD_HAS_WAIT_FOR_MOVE 1
  489. static bool wait_for_move;
  490. #else
  491. static constexpr bool wait_for_move = false;
  492. #endif
  493. //
  494. // Block interaction while under external control
  495. //
  496. #if HAS_LCD_MENU && EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  497. static bool external_control;
  498. FORCE_INLINE static void capture() { external_control = true; }
  499. FORCE_INLINE static void release() { external_control = false; }
  500. #if ENABLED(AUTO_BED_LEVELING_UBL)
  501. static void external_encoder();
  502. #endif
  503. #else
  504. static constexpr bool external_control = false;
  505. #endif
  506. #if HAS_ENCODER_ACTION
  507. static volatile uint8_t buttons;
  508. #if IS_RRW_KEYPAD
  509. static volatile uint8_t keypad_buttons;
  510. static bool handle_keypad();
  511. #endif
  512. #if HAS_SLOW_BUTTONS
  513. static volatile uint8_t slow_buttons;
  514. static uint8_t read_slow_buttons();
  515. #endif
  516. static void update_buttons();
  517. static inline bool button_pressed() { return BUTTON_CLICK() || TERN(TOUCH_SCREEN, touch_pressed(), false); }
  518. #if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  519. static void wait_for_release();
  520. #endif
  521. static uint32_t encoderPosition;
  522. #define ENCODERBASE (TERN(REVERSE_ENCODER_DIRECTION, -1, +1))
  523. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  524. static int8_t encoderDirection;
  525. #else
  526. static constexpr int8_t encoderDirection = ENCODERBASE;
  527. #endif
  528. FORCE_INLINE static void encoder_direction_normal() {
  529. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  530. encoderDirection = ENCODERBASE;
  531. #endif
  532. }
  533. FORCE_INLINE static void encoder_direction_menus() {
  534. TERN_(REVERSE_MENU_DIRECTION, encoderDirection = -(ENCODERBASE));
  535. }
  536. FORCE_INLINE static void encoder_direction_select() {
  537. TERN_(REVERSE_SELECT_DIRECTION, encoderDirection = -(ENCODERBASE));
  538. }
  539. #else
  540. static inline void update_buttons() {}
  541. #endif
  542. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  543. static void touch_calibration();
  544. #endif
  545. #if HAS_GRAPHICAL_TFT
  546. static void move_axis_screen();
  547. #endif
  548. private:
  549. #if HAS_DISPLAY
  550. static void finish_status(const bool persist);
  551. #endif
  552. #if HAS_WIRED_LCD
  553. #if HAS_LCD_MENU && LCD_TIMEOUT_TO_STATUS > 0
  554. static bool defer_return_to_status;
  555. #else
  556. static constexpr bool defer_return_to_status = false;
  557. #endif
  558. static void draw_status_screen();
  559. #if HAS_GRAPHICAL_TFT
  560. static void tft_idle();
  561. #if ENABLED(TOUCH_SCREEN)
  562. static bool touch_pressed();
  563. #endif
  564. #endif
  565. #endif
  566. };
  567. extern MarlinUI ui;
  568. #define LCD_MESSAGEPGM_P(x) ui.set_status_P(x)
  569. #define LCD_ALERTMESSAGEPGM_P(x) ui.set_alert_status_P(x)
  570. #define LCD_MESSAGEPGM(x) LCD_MESSAGEPGM_P(GET_TEXT(x))
  571. #define LCD_ALERTMESSAGEPGM(x) LCD_ALERTMESSAGEPGM_P(GET_TEXT(x))