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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  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. #elif HAS_DISPLAY_SLEEP
  239. #define SLEEP_TIMEOUT_MIN 0
  240. #define SLEEP_TIMEOUT_MAX 99
  241. static uint8_t sleep_timeout_minutes;
  242. static millis_t screen_timeout_millis;
  243. static void refresh_screen_timeout();
  244. static void sleep_on();
  245. static void sleep_off();
  246. #endif
  247. #if HAS_DWIN_E3V2_BASIC
  248. static void refresh();
  249. #else
  250. FORCE_INLINE static void refresh() {
  251. TERN_(HAS_WIRED_LCD, refresh(LCDVIEW_CLEAR_CALL_REDRAW));
  252. }
  253. #endif
  254. #if HAS_PRINT_PROGRESS
  255. #if HAS_PRINT_PROGRESS_PERMYRIAD
  256. typedef uint16_t progress_t;
  257. #define PROGRESS_SCALE 100U
  258. #define PROGRESS_MASK 0x7FFF
  259. #else
  260. typedef uint8_t progress_t;
  261. #define PROGRESS_SCALE 1U
  262. #define PROGRESS_MASK 0x7F
  263. #endif
  264. #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
  265. static progress_t progress_override;
  266. static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
  267. static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
  268. static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
  269. #endif
  270. #if ENABLED(SHOW_REMAINING_TIME)
  271. static uint32_t _calculated_remaining_time() {
  272. const duration_t elapsed = print_job_timer.duration();
  273. const progress_t progress = _get_progress();
  274. return progress ? elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress : 0;
  275. }
  276. #if ENABLED(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 ?: _calculated_remaining_time(); }
  280. FORCE_INLINE static void reset_remaining_time() { set_remaining_time(0); }
  281. #else
  282. FORCE_INLINE static uint32_t get_remaining_time() { return _calculated_remaining_time(); }
  283. #endif
  284. #endif
  285. static progress_t _get_progress();
  286. #if HAS_PRINT_PROGRESS_PERMYRIAD
  287. FORCE_INLINE static uint16_t get_progress_permyriad() { return _get_progress(); }
  288. #endif
  289. static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
  290. #else
  291. static constexpr uint8_t get_progress_percent() { return 0; }
  292. #endif
  293. #if HAS_STATUS_MESSAGE
  294. #if EITHER(HAS_WIRED_LCD, DWIN_LCD_PROUI)
  295. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  296. #define MAX_MESSAGE_LENGTH _MAX(LONG_FILENAME_LENGTH, MAX_LANG_CHARSIZE * 2 * (LCD_WIDTH))
  297. #else
  298. #define MAX_MESSAGE_LENGTH (MAX_LANG_CHARSIZE * (LCD_WIDTH))
  299. #endif
  300. #else
  301. #define MAX_MESSAGE_LENGTH 63
  302. #endif
  303. static char status_message[];
  304. static uint8_t alert_level; // Higher levels block lower levels
  305. #if HAS_STATUS_MESSAGE_TIMEOUT
  306. static millis_t status_message_expire_ms; // Reset some status messages after a timeout
  307. #endif
  308. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  309. static uint8_t status_scroll_offset;
  310. static void advance_status_scroll();
  311. static char* status_and_len(uint8_t &len);
  312. #endif
  313. static bool has_status();
  314. static void reset_status(const bool no_welcome=false);
  315. static void set_alert_status(FSTR_P const fstr);
  316. static void reset_alert_level() { alert_level = 0; }
  317. static statusResetFunc_t status_reset_callback;
  318. static void set_status_reset_fn(const statusResetFunc_t fn=nullptr) { status_reset_callback = fn; }
  319. #else
  320. static constexpr bool has_status() { return false; }
  321. static void reset_status(const bool=false) {}
  322. static void set_alert_status(FSTR_P const) {}
  323. static void reset_alert_level() {}
  324. static void set_status_reset_fn(const statusResetFunc_t=nullptr) {}
  325. #endif
  326. static void set_status(const char * const cstr, const bool persist=false);
  327. static void set_status(FSTR_P const fstr, const int8_t level=0);
  328. static void status_printf(int8_t level, FSTR_P const fmt, ...);
  329. #if HAS_DISPLAY
  330. static void update();
  331. static void abort_print();
  332. static void pause_print();
  333. static void resume_print();
  334. static void flow_fault();
  335. #if BOTH(HAS_MARLINUI_MENU, PSU_CONTROL)
  336. static void poweroff();
  337. #endif
  338. #if EITHER(HAS_WIRED_LCD, DWIN_CREALITY_LCD_JYERSUI)
  339. static bool get_blink();
  340. #endif
  341. #if HAS_WIRED_LCD
  342. static millis_t next_button_update_ms;
  343. static LCDViewAction lcdDrawUpdate;
  344. FORCE_INLINE static bool should_draw() { return bool(lcdDrawUpdate); }
  345. FORCE_INLINE static void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
  346. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  347. static void draw_custom_bootscreen(const uint8_t frame=0);
  348. static void show_custom_bootscreen();
  349. #endif
  350. #if ENABLED(SHOW_BOOTSCREEN)
  351. #ifndef BOOTSCREEN_TIMEOUT
  352. #define BOOTSCREEN_TIMEOUT 2500
  353. #endif
  354. static void draw_marlin_bootscreen(const bool line2=false);
  355. static void show_marlin_bootscreen();
  356. static void show_bootscreen();
  357. static void bootscreen_completion(const millis_t sofar);
  358. #endif
  359. #if HAS_MARLINUI_U8GLIB
  360. static void set_font(const MarlinFont font_nr);
  361. #elif IS_DWIN_MARLINUI
  362. static void set_font(const uint8_t font_nr);
  363. #endif
  364. #if HAS_MARLINUI_HD44780
  365. static void set_custom_characters(const HD44780CharSet screen_charset=CHARSET_INFO);
  366. #endif
  367. #if ENABLED(LCD_PROGRESS_BAR) && !HAS_MARLINUI_U8GLIB
  368. static millis_t progress_bar_ms; // Start time for the current progress bar cycle
  369. static void draw_progress_bar(const uint8_t percent);
  370. #if PROGRESS_MSG_EXPIRE > 0
  371. static millis_t expire_status_ms; // = 0
  372. FORCE_INLINE static void reset_progress_bar_timeout() { expire_status_ms = 0; }
  373. #endif
  374. #endif
  375. static uint8_t lcd_status_update_delay;
  376. #if HAS_LCD_CONTRAST
  377. static uint8_t contrast;
  378. static void _set_contrast(); // Implementation-specific
  379. static void set_contrast(const uint8_t value);
  380. FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
  381. #endif
  382. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  383. static millis_t next_filament_display;
  384. #endif
  385. #if HAS_TOUCH_SLEEP
  386. static void wakeup_screen();
  387. #endif
  388. static void quick_feedback(const bool clear_buttons=true);
  389. #if HAS_BUZZER
  390. static void completion_feedback(const bool good=true);
  391. #else
  392. static void completion_feedback(const bool=true) { TERN_(HAS_TOUCH_SLEEP, wakeup_screen()); }
  393. #endif
  394. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  395. static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
  396. #endif
  397. #if HAS_TOUCH_BUTTONS
  398. static bool on_edit_screen;
  399. static void screen_click(const uint8_t row, const uint8_t col, const uint8_t x, const uint8_t y);
  400. #endif
  401. static void status_screen();
  402. #endif
  403. #if HAS_MARLINUI_U8GLIB
  404. static bool drawing_screen, first_page;
  405. #else
  406. static constexpr bool drawing_screen = false, first_page = true;
  407. #endif
  408. #if IS_DWIN_MARLINUI
  409. static bool did_first_redraw;
  410. static bool old_is_printing;
  411. #endif
  412. #if EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  413. static void zoffset_overlay(const int8_t dir);
  414. static void zoffset_overlay(const_float_t zvalue);
  415. #endif
  416. static void draw_kill_screen();
  417. static void kill_screen(FSTR_P const lcd_error, FSTR_P const lcd_component);
  418. #if DISABLED(LIGHTWEIGHT_UI)
  419. static void draw_status_message(const bool blink);
  420. #endif
  421. #else // No LCD
  422. static void update() {}
  423. static void return_to_status() {}
  424. static void kill_screen(FSTR_P const, FSTR_P const) {}
  425. #endif
  426. #if ENABLED(SDSUPPORT)
  427. #if BOTH(SCROLL_LONG_FILENAMES, HAS_MARLINUI_MENU)
  428. #define MARLINUI_SCROLL_NAME 1
  429. #endif
  430. #if MARLINUI_SCROLL_NAME
  431. static uint8_t filename_scroll_pos, filename_scroll_max;
  432. #endif
  433. static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
  434. #endif
  435. #if HAS_PREHEAT
  436. enum PreheatTarget : uint8_t { PT_HOTEND, PT_BED, PT_FAN, PT_CHAMBER, PT_ALL = 0xFF };
  437. static preheat_t material_preset[PREHEAT_COUNT];
  438. static PGM_P get_preheat_label(const uint8_t m);
  439. static void apply_preheat(const uint8_t m, const uint8_t pmask, const uint8_t e=active_extruder);
  440. static void preheat_set_fan(const uint8_t m) { TERN_(HAS_FAN, apply_preheat(m, _BV(PT_FAN))); }
  441. static void preheat_hotend(const uint8_t m, const uint8_t e=active_extruder) { TERN_(HAS_HOTEND, apply_preheat(m, _BV(PT_HOTEND))); }
  442. static void preheat_hotend_and_fan(const uint8_t m, const uint8_t e=active_extruder) { preheat_hotend(m, e); preheat_set_fan(m); }
  443. static void preheat_bed(const uint8_t m) { TERN_(HAS_HEATED_BED, apply_preheat(m, _BV(PT_BED))); }
  444. static void preheat_all(const uint8_t m) { apply_preheat(m, PT_ALL); }
  445. #endif
  446. static void reset_status_timeout(const millis_t ms) {
  447. TERN(SCREENS_CAN_TIME_OUT, return_to_status_ms = ms + LCD_TIMEOUT_TO_STATUS, UNUSED(ms));
  448. }
  449. #if HAS_MARLINUI_MENU
  450. #if HAS_TOUCH_BUTTONS
  451. static uint8_t touch_buttons;
  452. static uint8_t repeat_delay;
  453. #else
  454. static constexpr uint8_t touch_buttons = 0;
  455. #endif
  456. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  457. static bool encoderRateMultiplierEnabled;
  458. static millis_t lastEncoderMovementMillis;
  459. static void enable_encoder_multiplier(const bool onoff);
  460. #define ENCODER_RATE_MULTIPLY(F) (ui.encoderRateMultiplierEnabled = F)
  461. #else
  462. #define ENCODER_RATE_MULTIPLY(F) NOOP
  463. #endif
  464. // Manual Movement
  465. static ManualMove manual_move;
  466. // Select Screen (modal NO/YES style dialog)
  467. static bool selection;
  468. static void set_selection(const bool sel) { selection = sel; }
  469. static bool update_selection();
  470. static void synchronize(PGM_P const msg=nullptr);
  471. static screenFunc_t currentScreen;
  472. static bool screen_changed;
  473. static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
  474. static void push_current_screen();
  475. // goto_previous_screen and go_back may also be used as menu item callbacks
  476. static void _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, const bool is_back));
  477. static void goto_previous_screen() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, false)); }
  478. static void go_back() { _goto_previous_screen(TERN_(TURBO_BACK_MENU_ITEM, true)); }
  479. static void return_to_status();
  480. static bool on_status_screen() { return currentScreen == status_screen; }
  481. FORCE_INLINE static void run_current_screen() { (*currentScreen)(); }
  482. #if ENABLED(LIGHTWEIGHT_UI)
  483. static void lcd_in_status(const bool inStatus);
  484. #endif
  485. FORCE_INLINE static bool screen_is_sticky() {
  486. return TERN1(SCREENS_CAN_TIME_OUT, defer_return_to_status);
  487. }
  488. FORCE_INLINE static void defer_status_screen(const bool defer=true) {
  489. TERN(SCREENS_CAN_TIME_OUT, defer_return_to_status = defer, UNUSED(defer));
  490. }
  491. static void goto_previous_screen_no_defer() {
  492. defer_status_screen(false);
  493. goto_previous_screen();
  494. }
  495. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  496. static void reselect_last_file();
  497. #endif
  498. #if ENABLED(AUTO_BED_LEVELING_UBL)
  499. static void ubl_plot(const uint8_t x_plot, const uint8_t y_plot);
  500. #endif
  501. #if ENABLED(AUTO_BED_LEVELING_UBL)
  502. static void ubl_mesh_edit_start(const_float_t initial);
  503. static float ubl_mesh_value();
  504. #endif
  505. static void draw_select_screen_prompt(PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr);
  506. #else
  507. static constexpr bool on_status_screen() { return true; }
  508. #if HAS_WIRED_LCD
  509. FORCE_INLINE static void run_current_screen() { status_screen(); }
  510. #endif
  511. #endif
  512. #if EITHER(HAS_MARLINUI_MENU, EXTENSIBLE_UI)
  513. static bool lcd_clicked;
  514. static bool use_click() {
  515. const bool click = lcd_clicked;
  516. lcd_clicked = false;
  517. return click;
  518. }
  519. #else
  520. static constexpr bool lcd_clicked = false;
  521. static bool use_click() { return false; }
  522. #endif
  523. #if ENABLED(ADVANCED_PAUSE_FEATURE) && ANY(HAS_MARLINUI_MENU, EXTENSIBLE_UI, DWIN_LCD_PROUI, DWIN_CREALITY_LCD_JYERSUI)
  524. static void pause_show_message(const PauseMessage message, const PauseMode mode=PAUSE_MODE_SAME, const uint8_t extruder=active_extruder);
  525. #else
  526. static void _pause_show_message() {}
  527. #define pause_show_message(...) _pause_show_message()
  528. #endif
  529. //
  530. // EEPROM: Reset / Init / Load / Store
  531. //
  532. #if HAS_MARLINUI_MENU
  533. static void reset_settings();
  534. #endif
  535. #if ENABLED(EEPROM_SETTINGS)
  536. #if HAS_MARLINUI_MENU
  537. static void init_eeprom();
  538. static void load_settings();
  539. static void store_settings();
  540. #endif
  541. #if DISABLED(EEPROM_AUTO_INIT)
  542. static void eeprom_alert(const uint8_t msgid);
  543. static void eeprom_alert_crc() { eeprom_alert(0); }
  544. static void eeprom_alert_index() { eeprom_alert(1); }
  545. static void eeprom_alert_version() { eeprom_alert(2); }
  546. #endif
  547. #endif
  548. //
  549. // Special handling if a move is underway
  550. //
  551. #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))
  552. #define LCD_HAS_WAIT_FOR_MOVE 1
  553. static bool wait_for_move;
  554. #else
  555. static constexpr bool wait_for_move = false;
  556. #endif
  557. //
  558. // Block interaction while under external control
  559. //
  560. #if HAS_MARLINUI_MENU && EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  561. static bool external_control;
  562. FORCE_INLINE static void capture() { external_control = true; }
  563. FORCE_INLINE static void release() { external_control = false; }
  564. #if ENABLED(AUTO_BED_LEVELING_UBL)
  565. static void external_encoder();
  566. #endif
  567. #else
  568. static constexpr bool external_control = false;
  569. #endif
  570. #if HAS_ENCODER_ACTION
  571. static volatile uint8_t buttons;
  572. #if IS_RRW_KEYPAD
  573. static volatile uint8_t keypad_buttons;
  574. static bool handle_keypad();
  575. #endif
  576. #if HAS_SLOW_BUTTONS
  577. static volatile uint8_t slow_buttons;
  578. static uint8_t read_slow_buttons();
  579. #endif
  580. static void update_buttons();
  581. #if HAS_ENCODER_NOISE
  582. #ifndef ENCODER_SAMPLES
  583. #define ENCODER_SAMPLES 10
  584. #endif
  585. /**
  586. * Some printers may have issues with EMI noise especially using a motherboard with 3.3V logic levels
  587. * it may cause the logical LOW to float into the undefined region and register as a logical HIGH
  588. * causing it to erroneously register as if someone clicked the button and in worst case make the
  589. * printer unusable in practice.
  590. */
  591. static bool hw_button_pressed() {
  592. LOOP_L_N(s, ENCODER_SAMPLES) {
  593. if (!BUTTON_CLICK()) return false;
  594. safe_delay(1);
  595. }
  596. return true;
  597. }
  598. #else
  599. static bool hw_button_pressed() { return BUTTON_CLICK(); }
  600. #endif
  601. static bool button_pressed() { return hw_button_pressed() || TERN0(TOUCH_SCREEN, touch_pressed()); }
  602. #if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  603. static void wait_for_release();
  604. #endif
  605. static uint32_t encoderPosition;
  606. #define ENCODERBASE (TERN(REVERSE_ENCODER_DIRECTION, -1, +1))
  607. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  608. static int8_t encoderDirection;
  609. #else
  610. static constexpr int8_t encoderDirection = ENCODERBASE;
  611. #endif
  612. FORCE_INLINE static void encoder_direction_normal() {
  613. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  614. encoderDirection = ENCODERBASE;
  615. #endif
  616. }
  617. FORCE_INLINE static void encoder_direction_menus() {
  618. TERN_(REVERSE_MENU_DIRECTION, encoderDirection = -(ENCODERBASE));
  619. }
  620. FORCE_INLINE static void encoder_direction_select() {
  621. TERN_(REVERSE_SELECT_DIRECTION, encoderDirection = -(ENCODERBASE));
  622. }
  623. #else
  624. static void update_buttons() {}
  625. #endif
  626. #if ENABLED(TOUCH_SCREEN_CALIBRATION)
  627. static void touch_calibration_screen();
  628. #endif
  629. #if HAS_GRAPHICAL_TFT
  630. static void move_axis_screen();
  631. #endif
  632. private:
  633. #if SCREENS_CAN_TIME_OUT
  634. static millis_t return_to_status_ms;
  635. static bool defer_return_to_status;
  636. #else
  637. static constexpr bool defer_return_to_status = false;
  638. #endif
  639. #if HAS_STATUS_MESSAGE
  640. static void finish_status(const bool persist);
  641. #endif
  642. #if HAS_WIRED_LCD
  643. static void draw_status_screen();
  644. #if HAS_GRAPHICAL_TFT
  645. static void tft_idle();
  646. #if ENABLED(TOUCH_SCREEN)
  647. static bool touch_pressed();
  648. #endif
  649. #endif
  650. #endif
  651. };
  652. extern MarlinUI ui;
  653. #define LCD_MESSAGE_F(S) ui.set_status(F(S))
  654. #define LCD_MESSAGE(M) ui.set_status(GET_TEXT_F(M))
  655. #define LCD_ALERTMESSAGE_F(S) ui.set_alert_status(F(S))
  656. #define LCD_ALERTMESSAGE(M) ui.set_alert_status(GET_TEXT_F(M))