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.

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