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

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