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

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