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

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