My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd.h 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include "../inc/MarlinConfig.h"
  24. #if HAS_BUZZER
  25. #include "../libs/buzzer.h"
  26. #endif
  27. #if HAS_LCD_MENU || ENABLED(ULTIPANEL_FEEDMULTIPLY)
  28. #define HAS_ENCODER_ACTION 1
  29. #endif
  30. #if (!HAS_ADC_BUTTONS && ENABLED(NEWPANEL)) || BUTTONS_EXIST(EN1, EN2)
  31. #define HAS_ENCODER_WHEEL 1
  32. #endif
  33. #if HAS_ENCODER_WHEEL || ANY_BUTTON(ENC, BACK, UP, DWN, LFT, RT)
  34. #define HAS_DIGITAL_BUTTONS 1
  35. #endif
  36. #if !HAS_ADC_BUTTONS && (ENABLED(REPRAPWORLD_KEYPAD) || (HAS_SPI_LCD && DISABLED(NEWPANEL)))
  37. #define HAS_SHIFT_ENCODER 1
  38. #endif
  39. // I2C buttons must be read in the main thread
  40. #define HAS_SLOW_BUTTONS EITHER(LCD_I2C_VIKI, LCD_I2C_PANELOLU2)
  41. #if HAS_SPI_LCD
  42. #include "../MarlinCore.h"
  43. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  44. #include "../feature/pause.h"
  45. #include "../module/motion.h" // for active_extruder
  46. #endif
  47. enum LCDViewAction : uint8_t {
  48. LCDVIEW_NONE,
  49. LCDVIEW_REDRAW_NOW,
  50. LCDVIEW_CALL_REDRAW_NEXT,
  51. LCDVIEW_CLEAR_CALL_REDRAW,
  52. LCDVIEW_CALL_NO_REDRAW
  53. };
  54. #if HAS_ADC_BUTTONS
  55. uint8_t get_ADC_keyValue();
  56. #endif
  57. #if ENABLED(TOUCH_BUTTONS)
  58. #define LCD_UPDATE_INTERVAL 50
  59. #else
  60. #define LCD_UPDATE_INTERVAL 100
  61. #endif
  62. #if HAS_LCD_MENU
  63. #if HAS_GRAPHICAL_LCD
  64. #define SETCURSOR(col, row) lcd_moveto(col * (MENU_FONT_WIDTH), (row + 1) * (MENU_FONT_HEIGHT))
  65. #define SETCURSOR_RJ(len, row) lcd_moveto(LCD_PIXEL_WIDTH - (len) * (MENU_FONT_WIDTH), (row + 1) * (MENU_FONT_HEIGHT))
  66. #else
  67. #define SETCURSOR(col, row) lcd_moveto(col, row)
  68. #define SETCURSOR_RJ(len, row) lcd_moveto(LCD_WIDTH - (len), row)
  69. #endif
  70. #include "lcdprint.h"
  71. void _wrap_string(uint8_t &col, uint8_t &row, const char * const string, read_byte_cb_t cb_read_byte, const bool wordwrap=false);
  72. 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); }
  73. 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); }
  74. #if ENABLED(SDSUPPORT)
  75. #include "../sd/cardreader.h"
  76. #endif
  77. typedef void (*screenFunc_t)();
  78. typedef void (*menuAction_t)();
  79. // Manual Movement
  80. extern float move_menu_scale;
  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
  92. // REPRAPWORLD_KEYPAD (and ADC_KEYPAD)
  93. #if ENABLED(REPRAPWORLD_KEYPAD)
  94. #define BTN_OFFSET 0 // Bit offset into buttons for shift register values
  95. #define BLEN_KEYPAD_F3 0
  96. #define BLEN_KEYPAD_F2 1
  97. #define BLEN_KEYPAD_F1 2
  98. #define BLEN_KEYPAD_DOWN 3
  99. #define BLEN_KEYPAD_RIGHT 4
  100. #define BLEN_KEYPAD_MIDDLE 5
  101. #define BLEN_KEYPAD_UP 6
  102. #define BLEN_KEYPAD_LEFT 7
  103. #define EN_KEYPAD_F1 _BV(BTN_OFFSET + BLEN_KEYPAD_F1)
  104. #define EN_KEYPAD_F2 _BV(BTN_OFFSET + BLEN_KEYPAD_F2)
  105. #define EN_KEYPAD_F3 _BV(BTN_OFFSET + BLEN_KEYPAD_F3)
  106. #define EN_KEYPAD_DOWN _BV(BTN_OFFSET + BLEN_KEYPAD_DOWN)
  107. #define EN_KEYPAD_RIGHT _BV(BTN_OFFSET + BLEN_KEYPAD_RIGHT)
  108. #define EN_KEYPAD_MIDDLE _BV(BTN_OFFSET + BLEN_KEYPAD_MIDDLE)
  109. #define EN_KEYPAD_UP _BV(BTN_OFFSET + BLEN_KEYPAD_UP)
  110. #define EN_KEYPAD_LEFT _BV(BTN_OFFSET + BLEN_KEYPAD_LEFT)
  111. #define RRK(B) (keypad_buttons & (B))
  112. #ifdef EN_C
  113. #define BUTTON_CLICK() ((buttons & EN_C) || RRK(EN_KEYPAD_MIDDLE))
  114. #else
  115. #define BUTTON_CLICK() RRK(EN_KEYPAD_MIDDLE)
  116. #endif
  117. #endif
  118. #if HAS_DIGITAL_BUTTONS
  119. // Wheel spin pins where BA is 00, 10, 11, 01 (1 bit always changes)
  120. #define BLEN_A 0
  121. #define BLEN_B 1
  122. #define EN_A _BV(BLEN_A)
  123. #define EN_B _BV(BLEN_B)
  124. #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
  125. #if BUTTON_EXISTS(ENC) || ENABLED(TOUCH_BUTTONS)
  126. #define BLEN_C 2
  127. #define EN_C _BV(BLEN_C)
  128. #endif
  129. #if ENABLED(LCD_I2C_VIKI)
  130. #include <LiquidTWI2.h>
  131. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  132. // button and encoder bit positions within 'buttons'
  133. #define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
  134. #define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
  135. #define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
  136. #define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
  137. #define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
  138. #if BUTTON_EXISTS(ENC) // The pause/stop/restart button is connected to BTN_ENC when used
  139. #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
  140. #define BUTTON_CLICK() (buttons & (B_MI|B_RI|B_ST)) // Pause/stop also acts as click until a proper pause/stop is implemented.
  141. #else
  142. #define BUTTON_CLICK() (buttons & (B_MI|B_RI))
  143. #endif
  144. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  145. #elif ENABLED(LCD_I2C_PANELOLU2)
  146. #if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
  147. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  148. #define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
  149. #define BUTTON_CLICK() (buttons & B_MI)
  150. #endif
  151. #endif
  152. #else
  153. #undef BUTTON_EXISTS
  154. #define BUTTON_EXISTS(...) false
  155. // Shift register bits correspond to buttons:
  156. #define BL_LE 7 // Left
  157. #define BL_UP 6 // Up
  158. #define BL_MI 5 // Middle
  159. #define BL_DW 4 // Down
  160. #define BL_RI 3 // Right
  161. #define BL_ST 2 // Red Button
  162. #define B_LE (_BV(BL_LE))
  163. #define B_UP (_BV(BL_UP))
  164. #define B_MI (_BV(BL_MI))
  165. #define B_DW (_BV(BL_DW))
  166. #define B_RI (_BV(BL_RI))
  167. #define B_ST (_BV(BL_ST))
  168. #ifndef BUTTON_CLICK
  169. #define BUTTON_CLICK() (buttons & (B_MI|B_ST))
  170. #endif
  171. #endif
  172. #if BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS)
  173. #define BLEN_D 3
  174. #define EN_D _BV(BLEN_D)
  175. #define LCD_BACK_CLICKED() (buttons & EN_D)
  176. #else
  177. #define LCD_BACK_CLICKED() false
  178. #endif
  179. #ifndef BUTTON_CLICK
  180. #ifdef EN_C
  181. #define BUTTON_CLICK() (buttons & EN_C)
  182. #else
  183. #define BUTTON_CLICK() false
  184. #endif
  185. #endif
  186. #if HAS_GRAPHICAL_LCD
  187. enum MarlinFont : uint8_t {
  188. FONT_STATUSMENU = 1,
  189. FONT_EDIT,
  190. FONT_MENU
  191. };
  192. #else
  193. enum HD44780CharSet : uint8_t {
  194. CHARSET_MENU,
  195. CHARSET_INFO,
  196. CHARSET_BOOT
  197. };
  198. #endif
  199. ////////////////////////////////////////////
  200. //////////// MarlinUI Singleton ////////////
  201. ////////////////////////////////////////////
  202. class MarlinUI {
  203. public:
  204. MarlinUI() {
  205. #if HAS_LCD_MENU
  206. currentScreen = status_screen;
  207. #endif
  208. }
  209. #if HAS_BUZZER
  210. static void buzz(const long duration, const uint16_t freq);
  211. #endif
  212. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  213. static void update_indicators();
  214. #endif
  215. // LCD implementations
  216. static void clear_lcd();
  217. static void init_lcd();
  218. #if HAS_DISPLAY
  219. static void init();
  220. static void update();
  221. static void set_alert_status_P(PGM_P const message);
  222. static char status_message[];
  223. static bool has_status();
  224. static uint8_t alert_level; // Higher levels block lower levels
  225. static inline void reset_alert_level() { alert_level = 0; }
  226. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  227. static uint8_t status_scroll_offset;
  228. static void advance_status_scroll();
  229. static char* status_and_len(uint8_t &len);
  230. #endif
  231. static void abort_print();
  232. static void pause_print();
  233. static void resume_print();
  234. #if HAS_PRINT_PROGRESS
  235. #if HAS_PRINT_PROGRESS_PERMYRIAD
  236. typedef uint16_t progress_t;
  237. #define PROGRESS_SCALE 100U
  238. #define PROGRESS_MASK 0x7FFF
  239. #else
  240. typedef uint8_t progress_t;
  241. #define PROGRESS_SCALE 1U
  242. #define PROGRESS_MASK 0x7F
  243. #endif
  244. #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
  245. static progress_t progress_override;
  246. static void set_progress(const progress_t p) { progress_override = _MIN(p, 100U * (PROGRESS_SCALE)); }
  247. static void set_progress_done() { progress_override = (PROGRESS_MASK + 1U) + 100U * (PROGRESS_SCALE); }
  248. static void progress_reset() { if (progress_override & (PROGRESS_MASK + 1U)) set_progress(0); }
  249. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  250. static uint32_t remaining_time;
  251. FORCE_INLINE static void set_remaining_time(const uint32_t r) { remaining_time = r; }
  252. FORCE_INLINE static uint32_t get_remaining_time() { return remaining_time; }
  253. FORCE_INLINE static void reset_remaining_time() { set_remaining_time(0); }
  254. #endif
  255. #endif
  256. static progress_t _get_progress();
  257. #if HAS_PRINT_PROGRESS_PERMYRIAD
  258. FORCE_INLINE static uint16_t get_progress_permyriad() { return _get_progress(); }
  259. #endif
  260. static uint8_t get_progress_percent() { return uint8_t(_get_progress() / (PROGRESS_SCALE)); }
  261. #else
  262. static constexpr uint8_t get_progress_percent() { return 0; }
  263. #endif
  264. #if HAS_SPI_LCD
  265. static millis_t next_button_update_ms;
  266. static bool detected();
  267. static LCDViewAction lcdDrawUpdate;
  268. FORCE_INLINE static bool should_draw() { return bool(lcdDrawUpdate); }
  269. FORCE_INLINE static void refresh(const LCDViewAction type) { lcdDrawUpdate = type; }
  270. FORCE_INLINE static void refresh() { refresh(LCDVIEW_CLEAR_CALL_REDRAW); }
  271. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  272. static void draw_custom_bootscreen(const uint8_t frame=0);
  273. static void show_custom_bootscreen();
  274. #endif
  275. #if ENABLED(SHOW_BOOTSCREEN)
  276. #ifndef BOOTSCREEN_TIMEOUT
  277. #define BOOTSCREEN_TIMEOUT 2500
  278. #endif
  279. static void draw_marlin_bootscreen(const bool line2=false);
  280. static void show_marlin_bootscreen();
  281. static void show_bootscreen();
  282. #endif
  283. #if HAS_GRAPHICAL_LCD
  284. static bool drawing_screen, first_page;
  285. static void set_font(const MarlinFont font_nr);
  286. #else
  287. static constexpr bool drawing_screen = false, first_page = true;
  288. static void set_custom_characters(const HD44780CharSet screen_charset=CHARSET_INFO);
  289. #if ENABLED(LCD_PROGRESS_BAR)
  290. static millis_t progress_bar_ms; // Start time for the current progress bar cycle
  291. static void draw_progress_bar(const uint8_t percent);
  292. #if PROGRESS_MSG_EXPIRE > 0
  293. static millis_t expire_status_ms; // = 0
  294. FORCE_INLINE static void reset_progress_bar_timeout() { expire_status_ms = 0; }
  295. #endif
  296. #endif
  297. #endif
  298. static uint8_t lcd_status_update_delay;
  299. #if HAS_LCD_CONTRAST
  300. static int16_t contrast;
  301. static void set_contrast(const int16_t value);
  302. FORCE_INLINE static void refresh_contrast() { set_contrast(contrast); }
  303. #endif
  304. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  305. static millis_t next_filament_display;
  306. #endif
  307. static void quick_feedback(const bool clear_buttons=true);
  308. #if HAS_BUZZER
  309. static void completion_feedback(const bool good=true);
  310. #endif
  311. #if DISABLED(LIGHTWEIGHT_UI)
  312. static void draw_status_message(const bool blink);
  313. #endif
  314. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  315. static void draw_hotend_status(const uint8_t row, const uint8_t extruder);
  316. #endif
  317. static void status_screen();
  318. #else
  319. static void refresh() {}
  320. #endif
  321. static bool get_blink();
  322. static void kill_screen(PGM_P const lcd_error, PGM_P const lcd_component);
  323. static void draw_kill_screen();
  324. static void set_status(const char* const message, const bool persist=false);
  325. static void set_status_P(PGM_P const message, const int8_t level=0);
  326. static void status_printf_P(const uint8_t level, PGM_P const fmt, ...);
  327. static void reset_status(const bool no_welcome=false);
  328. #else // No LCD
  329. // Send status to host as a notification
  330. void set_status(const char* message, const bool=false);
  331. void set_status_P(PGM_P message, const int8_t=0);
  332. void status_printf_P(const uint8_t, PGM_P message, ...);
  333. static inline void init() {}
  334. static inline void update() {}
  335. static inline void refresh() {}
  336. static inline void return_to_status() {}
  337. static inline void set_alert_status_P(PGM_P const) {}
  338. static inline void reset_status(const bool=false) {}
  339. static inline void reset_alert_level() {}
  340. static constexpr bool has_status() { return false; }
  341. #endif
  342. #if HAS_LCD_MENU
  343. #if ENABLED(TOUCH_BUTTONS)
  344. static uint8_t touch_buttons;
  345. static uint8_t repeat_delay;
  346. #endif
  347. #if ENABLED(ENCODER_RATE_MULTIPLIER)
  348. static bool encoderRateMultiplierEnabled;
  349. static millis_t lastEncoderMovementMillis;
  350. static void enable_encoder_multiplier(const bool onoff);
  351. #endif
  352. #if ENABLED(SDSUPPORT)
  353. #if ENABLED(SCROLL_LONG_FILENAMES)
  354. static uint8_t filename_scroll_pos, filename_scroll_max;
  355. #endif
  356. static const char * scrolled_filename(CardReader &theCard, const uint8_t maxlen, uint8_t hash, const bool doScroll);
  357. #endif
  358. #if IS_KINEMATIC
  359. static bool processing_manual_move;
  360. #else
  361. static constexpr bool processing_manual_move = false;
  362. #endif
  363. #if E_MANUAL > 1
  364. static int8_t manual_move_e_index;
  365. #else
  366. static constexpr int8_t manual_move_e_index = 0;
  367. #endif
  368. static int16_t preheat_hotend_temp[2], preheat_bed_temp[2];
  369. static uint8_t preheat_fan_speed[2];
  370. // Select Screen (modal NO/YES style dialog)
  371. static bool selection;
  372. static void set_selection(const bool sel) { selection = sel; }
  373. static bool update_selection();
  374. static void manage_manual_move();
  375. static bool lcd_clicked;
  376. static bool use_click();
  377. static void synchronize(PGM_P const msg=nullptr);
  378. static screenFunc_t currentScreen;
  379. static bool screen_changed;
  380. static void goto_screen(const screenFunc_t screen, const uint16_t encoder=0, const uint8_t top=0, const uint8_t items=0);
  381. static void save_previous_screen();
  382. // goto_previous_screen and go_back may also be used as menu item callbacks
  383. #if ENABLED(TURBO_BACK_MENU_ITEM)
  384. static void _goto_previous_screen(const bool is_back);
  385. static inline void goto_previous_screen() { _goto_previous_screen(false); }
  386. static inline void go_back() { _goto_previous_screen(true); }
  387. #else
  388. static void _goto_previous_screen();
  389. FORCE_INLINE static void goto_previous_screen() { _goto_previous_screen(); }
  390. FORCE_INLINE static void go_back() { _goto_previous_screen(); }
  391. #endif
  392. static void return_to_status();
  393. static inline bool on_status_screen() { return currentScreen == status_screen; }
  394. FORCE_INLINE static void run_current_screen() { (*currentScreen)(); }
  395. #if ENABLED(LIGHTWEIGHT_UI)
  396. static void lcd_in_status(const bool inStatus);
  397. #endif
  398. FORCE_INLINE static void defer_status_screen(const bool defer=true) {
  399. #if LCD_TIMEOUT_TO_STATUS
  400. defer_return_to_status = defer;
  401. #else
  402. UNUSED(defer);
  403. #endif
  404. }
  405. static inline void goto_previous_screen_no_defer() {
  406. defer_status_screen(false);
  407. goto_previous_screen();
  408. }
  409. #if ENABLED(SD_REPRINT_LAST_SELECTED_FILE)
  410. static void reselect_last_file();
  411. #endif
  412. #if ENABLED(G26_MESH_VALIDATION)
  413. FORCE_INLINE static void chirp() {
  414. #if HAS_BUZZER
  415. buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ);
  416. #endif
  417. }
  418. #endif
  419. #if ENABLED(AUTO_BED_LEVELING_UBL)
  420. static void ubl_plot(const uint8_t x_plot, const uint8_t y_plot);
  421. #endif
  422. static void draw_select_screen_prompt(PGM_P const pref, const char * const string=nullptr, PGM_P const suff=nullptr);
  423. #elif HAS_SPI_LCD
  424. static constexpr bool lcd_clicked = false;
  425. static constexpr bool on_status_screen() { return true; }
  426. FORCE_INLINE static void run_current_screen() { status_screen(); }
  427. #endif
  428. #define LCD_HAS_WAIT_FOR_MOVE EITHER(DELTA_CALIBRATION_MENU, DELTA_AUTO_CALIBRATION) || (ENABLED(LCD_BED_LEVELING) && EITHER(PROBE_MANUALLY, MESH_BED_LEVELING))
  429. #if LCD_HAS_WAIT_FOR_MOVE
  430. static bool wait_for_move;
  431. #else
  432. static constexpr bool wait_for_move = false;
  433. #endif
  434. #if HAS_LCD_MENU && EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  435. static bool external_control;
  436. FORCE_INLINE static void capture() { external_control = true; }
  437. FORCE_INLINE static void release() { external_control = false; }
  438. #else
  439. static constexpr bool external_control = false;
  440. #endif
  441. #if HAS_ENCODER_ACTION
  442. static volatile uint8_t buttons;
  443. #if ENABLED(REPRAPWORLD_KEYPAD)
  444. static volatile uint8_t keypad_buttons;
  445. static bool handle_keypad();
  446. #endif
  447. #if HAS_SLOW_BUTTONS
  448. static volatile uint8_t slow_buttons;
  449. static uint8_t read_slow_buttons();
  450. #endif
  451. static void update_buttons();
  452. static inline bool button_pressed() { return BUTTON_CLICK(); }
  453. #if EITHER(AUTO_BED_LEVELING_UBL, G26_MESH_VALIDATION)
  454. static void wait_for_release();
  455. #endif
  456. static uint32_t encoderPosition;
  457. #if ENABLED(REVERSE_ENCODER_DIRECTION)
  458. #define ENCODERBASE -1
  459. #else
  460. #define ENCODERBASE +1
  461. #endif
  462. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  463. static int8_t encoderDirection;
  464. #else
  465. static constexpr int8_t encoderDirection = ENCODERBASE;
  466. #endif
  467. FORCE_INLINE static void encoder_direction_normal() {
  468. #if EITHER(REVERSE_MENU_DIRECTION, REVERSE_SELECT_DIRECTION)
  469. encoderDirection = ENCODERBASE;
  470. #endif
  471. }
  472. FORCE_INLINE static void encoder_direction_menus() {
  473. #if ENABLED(REVERSE_MENU_DIRECTION)
  474. encoderDirection = -(ENCODERBASE);
  475. #endif
  476. }
  477. FORCE_INLINE static void encoder_direction_select() {
  478. #if ENABLED(REVERSE_SELECT_DIRECTION)
  479. encoderDirection = -(ENCODERBASE);
  480. #endif
  481. }
  482. #else
  483. static inline void update_buttons() {}
  484. #endif
  485. private:
  486. static void _synchronize();
  487. #if HAS_DISPLAY
  488. static void finish_status(const bool persist);
  489. #endif
  490. #if HAS_SPI_LCD
  491. #if HAS_LCD_MENU
  492. #if LCD_TIMEOUT_TO_STATUS
  493. static bool defer_return_to_status;
  494. #else
  495. static constexpr bool defer_return_to_status = false;
  496. #endif
  497. #endif
  498. static void draw_status_screen();
  499. #endif
  500. };
  501. extern MarlinUI ui;
  502. #define LCD_MESSAGEPGM_P(x) ui.set_status_P(x)
  503. #define LCD_ALERTMESSAGEPGM_P(x) ui.set_alert_status_P(x)
  504. #define LCD_MESSAGEPGM(x) LCD_MESSAGEPGM_P(GET_TEXT(x))
  505. #define LCD_ALERTMESSAGEPGM(x) LCD_ALERTMESSAGEPGM_P(GET_TEXT(x))