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

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