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

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