From b8a32cba0b5ef08bf3bd0dae4f17221bbe302b84 Mon Sep 17 00:00:00 2001 From: ConstantijnCrijnen <43953114+ConstantijnCrijnen@users.noreply.github.com> Date: Thu, 21 Jan 2021 07:12:24 +0100 Subject: [PATCH 01/18] Printcounter Fix (issue #20785) --- Marlin/src/MarlinCore.cpp | 6 +++++- Marlin/src/core/boards.h | 1 + Marlin/src/core/macros.h | 1 + Marlin/src/gcode/control/M80_M81.cpp | 2 +- Marlin/src/lcd/marlinui.cpp | 4 +++- Marlin/src/module/printcounter.cpp | 19 +++++++++++++------ 6 files changed, 24 insertions(+), 9 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index f994e2e32cd9..bc1e3bec68cd 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -461,10 +461,10 @@ void startOrResumeJob() { inline void abortSDPrinting() { IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel()); + Stopwatch::stop(); //without this, PRINTCOUNTER would count print as successful card.endFilePrint(TERN_(SD_RESORT, true)); queue.clear(); quickstop_stepper(); - print_job_timer.stop(); #if DISABLED(SD_ABORT_NO_COOLDOWN) thermalManager.disable_all_heaters(); #endif @@ -478,6 +478,10 @@ void startOrResumeJob() { #ifdef EVENT_GCODE_SD_ABORT queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif + + //Wait for EVENT_GCODE_SD_ABORT to finish, so it doesn't get interrupted by PRINTCOUNTER + planner.synchronize(); + print_job_timer.stop(); TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h index 13a202daedb1..547c3b1db90f 100644 --- a/Marlin/src/core/boards.h +++ b/Marlin/src/core/boards.h @@ -415,3 +415,4 @@ #define MB(V...) DO(MB,||,V) #define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY, MELZI_V2) +#define ENV_LPC1768 MB(RAMPS_14_RE_ARM_EFB, RAMPS_14_RE_ARM_EEB, RAMPS_14_RE_ARM_EFF, RAMPS_14_RE_ARM_EEF, RAMPS_14_RE_ARM_SF, MKS_SBASE, MKS_SGEN_L, AZSMZ_MINI, BIQU_BQ111_A4, SELENA_COMPACT, BIQU_B300_V1_0, GMARSH_X6_REV1, BTT_SKR_V1_1, BTT_SKR_V1_3, BTT_SKR_V1_4) \ No newline at end of file diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index d5b3342437ea..63ef59703495 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -162,6 +162,7 @@ #define _DO_12(W,C,A,V...) (_##W##_1(A) C _DO_11(W,C,V)) #define _DO_13(W,C,A,V...) (_##W##_1(A) C _DO_12(W,C,V)) #define _DO_14(W,C,A,V...) (_##W##_1(A) C _DO_13(W,C,V)) +#define _DO_15(W,C,A,V...) (_##W##_1(A) C _DO_14(W,C,V)) #define __DO_N(W,C,N,V...) _DO_##N(W,C,V) #define _DO_N(W,C,N,V...) __DO_N(W,C,N,V) #define DO(W,C,V...) (_DO_N(W,C,NUM_ARGS(V),V)) diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index ea0f9c2b1393..ea09b34634dd 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -89,8 +89,8 @@ */ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); - print_job_timer.stop(); planner.finish_and_disable(); + print_job_timer.stop(); //moved, so writing to eeprom doesn't interrupt queued planner moves #if HAS_FAN thermalManager.zero_fan_speeds(); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index d4e1357e8616..fa05d0a4abac 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1492,7 +1492,9 @@ void MarlinUI::update() { host_action_cancel(); #endif TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR)); - print_job_timer.stop(); + //print_job_timer.stop(); //is already called by abortSDPrinting(). + //...so it would be called twice in case of SDPrinting + // LCD_MESSAGEPGM(MSG_PRINT_ABORTED); TERN_(HAS_LCD_MENU, return_to_status()); } diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index ab87717f0111..3d3e642f781d 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -243,11 +243,15 @@ void PrintCounter::tick() { update_next = now + updateInterval * 1000; } - static uint32_t eeprom_next; // = 0 - if (ELAPSED(now, eeprom_next)) { - eeprom_next = now + saveInterval * 1000; - saveStats(); - } + #if !ENV_LPC1768 + //LPC1769 boards seem to lose steps when saving to EEPROM during print (issue #20785) + //todo: Which other boards are incompatible? + static uint32_t eeprom_next; // = 0 + if (ELAPSED(now, eeprom_next)) { + eeprom_next = now + saveInterval * 1000; + saveStats(); + } + #endif } // @Override @@ -281,7 +285,10 @@ bool PrintCounter::stop() { saveStats(); return true; } - else return false; + else { + saveStats(); + return false; + } } // @Override From 7c675fab1952e3543dfa3b5ba4887806255cc5d3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 02:07:59 -0600 Subject: [PATCH 02/18] Add pc.abort method --- Marlin/src/MarlinCore.cpp | 9 ++++----- Marlin/src/libs/stopwatch.h | 1 + Marlin/src/module/printcounter.cpp | 24 ++++++++++-------------- Marlin/src/module/printcounter.h | 5 ++++- 4 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 5db8d2fb033c..b08f4e8192a5 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -361,7 +361,6 @@ void startOrResumeJob() { inline void abortSDPrinting() { IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel()); - Stopwatch::stop(); //without this, PRINTCOUNTER would count print as successful card.endFilePrint(TERN_(SD_RESORT, true)); queue.clear(); quickstop_stepper(); @@ -378,10 +377,10 @@ void startOrResumeJob() { #ifdef EVENT_GCODE_SD_ABORT queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif - - //Wait for EVENT_GCODE_SD_ABORT to finish, so it doesn't get interrupted by PRINTCOUNTER - planner.synchronize(); - print_job_timer.stop(); + + planner.synchronize(); // Wait for EVENT_GCODE_SD_ABORT to finish, so it doesn't get interrupted by PRINTCOUNTER + + print_job_timer.abort(); TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } diff --git a/Marlin/src/libs/stopwatch.h b/Marlin/src/libs/stopwatch.h index 6e8e95a9a5f1..b64a36a90e78 100644 --- a/Marlin/src/libs/stopwatch.h +++ b/Marlin/src/libs/stopwatch.h @@ -56,6 +56,7 @@ class Stopwatch { * @return true on success */ static bool stop(); + static inline bool abort() { return stop(); } // Alias by default /** * @brief Pause the stopwatch diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 3d3e642f781d..5573b9b20ce8 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -271,24 +271,20 @@ bool PrintCounter::start() { return false; } -// @Override -bool PrintCounter::stop() { +bool PrintCounter::_stop(const bool completed) { TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("stop"))); - if (super::stop()) { - data.finishedPrints++; + const bool did_stop = super::stop(); + if (did_stop) { data.printTime += deltaDuration(); - - if (duration() > data.longestPrint) - data.longestPrint = duration(); - - saveStats(); - return true; - } - else { - saveStats(); - return false; + if (completed) { + data.finishedPrints++; + if (duration() > data.longestPrint) + data.longestPrint = duration(); + } } + saveStats(); + return did_stop; } // @Override diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 66d8cbb7b38e..0d75e6e3f7a1 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -176,7 +176,10 @@ class PrintCounter: public Stopwatch { * The following functions are being overridden */ static bool start(); - static bool stop(); + static bool _stop(const bool completed); + static inline bool stop() { return _stop(true); } + static inline bool abort() { return _stop(false); } + static void reset(); #if HAS_SERVICE_INTERVALS From 2e3ab9760728f1cfd234f6cf78e629653f333933 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 02:24:25 -0600 Subject: [PATCH 03/18] fixups --- Marlin/src/MarlinCore.cpp | 4 +++- Marlin/src/core/boards.h | 1 - Marlin/src/gcode/control/M80_M81.cpp | 3 ++- Marlin/src/lcd/marlinui.cpp | 3 --- Marlin/src/module/printcounter.cpp | 6 +++--- Marlin/src/module/temperature.cpp | 1 - Marlin/src/pins/lpc1768/pins_MKS_SBASE.h | 2 +- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index b08f4e8192a5..032c6061b31b 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -786,7 +786,9 @@ void minkill(const bool steppers_off/*=false*/) { */ void stop() { thermalManager.disable_all_heaters(); // 'unpause' taken care of in here - print_job_timer.stop(); + + planner.synchronize(); + print_job_timer.stop(); // Wait for planner before calling! #if ENABLED(PROBING_FANS_OFF) if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h index 547c3b1db90f..13a202daedb1 100644 --- a/Marlin/src/core/boards.h +++ b/Marlin/src/core/boards.h @@ -415,4 +415,3 @@ #define MB(V...) DO(MB,||,V) #define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY, MELZI_V2) -#define ENV_LPC1768 MB(RAMPS_14_RE_ARM_EFB, RAMPS_14_RE_ARM_EEB, RAMPS_14_RE_ARM_EFF, RAMPS_14_RE_ARM_EEF, RAMPS_14_RE_ARM_SF, MKS_SBASE, MKS_SGEN_L, AZSMZ_MINI, BIQU_BQ111_A4, SELENA_COMPACT, BIQU_B300_V1_0, GMARSH_X6_REV1, BTT_SKR_V1_1, BTT_SKR_V1_3, BTT_SKR_V1_4) \ No newline at end of file diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index ea09b34634dd..cd5a92d7b31e 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -90,7 +90,8 @@ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); planner.finish_and_disable(); - print_job_timer.stop(); //moved, so writing to eeprom doesn't interrupt queued planner moves + + print_job_timer.stop(); // Wait for planner before calling! #if HAS_FAN thermalManager.zero_fan_speeds(); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 77aea67853de..c78407a5af03 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1496,9 +1496,6 @@ void MarlinUI::update() { host_action_cancel(); #endif TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR)); - //print_job_timer.stop(); //is already called by abortSDPrinting(). - //...so it would be called twice in case of SDPrinting - // LCD_MESSAGEPGM(MSG_PRINT_ABORTED); TERN_(HAS_LCD_MENU, return_to_status()); } diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 5573b9b20ce8..20bf175e7815 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -243,9 +243,9 @@ void PrintCounter::tick() { update_next = now + updateInterval * 1000; } - #if !ENV_LPC1768 - //LPC1769 boards seem to lose steps when saving to EEPROM during print (issue #20785) - //todo: Which other boards are incompatible? + // LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) + // TODO: Which other boards are incompatible? + #ifndef MCU_LPC1768 static uint32_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { eeprom_next = now + saveInterval * 1000; diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 00a048736a6b..589baf77962e 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2186,7 +2186,6 @@ void Temperature::disable_all_heaters() { #endif - #if ENABLED(PROBING_HEATERS_OFF) void Temperature::pause(const bool p) { diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h index ea9748ca5486..fbddc66e7ce6 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h @@ -27,7 +27,7 @@ #if defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1769) #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#elif NOT_TARGET(MKS_HAS_LPC1769, MCU_LPC1768) +#elif !defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1768) #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." #endif From 977eaa09ee2fd613846ba044acff3ebd44e4bb1e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 02:25:59 -0600 Subject: [PATCH 04/18] comments --- Marlin/src/MarlinCore.cpp | 5 ++--- Marlin/src/module/endstops.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 032c6061b31b..d1ca900449e1 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -378,9 +378,8 @@ void startOrResumeJob() { queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif - planner.synchronize(); // Wait for EVENT_GCODE_SD_ABORT to finish, so it doesn't get interrupted by PRINTCOUNTER - - print_job_timer.abort(); + planner.synchronize(); + print_job_timer.abort(); // Wait for planner before calling! TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index b9d2c1cdf561..1328851752d1 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -398,7 +398,7 @@ void Endstops::event_handler() { card.endFilePrint(); quickstop_stepper(); thermalManager.disable_all_heaters(); - print_job_timer.stop(); + print_job_timer.stop(); // Wait for planner before calling! } #endif } From 2bf7c362b307efd4dbed2259f20a6023768649b7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 02:24:25 -0600 Subject: [PATCH 05/18] fixups --- Marlin/Configuration.h | 3 +++ Marlin/src/HAL/LPC1768/inc/Conditionals_post.h | 7 +++++++ Marlin/src/MarlinCore.cpp | 9 +++++---- Marlin/src/core/boards.h | 1 - Marlin/src/gcode/control/M80_M81.cpp | 3 ++- Marlin/src/lcd/marlinui.cpp | 3 --- Marlin/src/module/printcounter.cpp | 6 ++---- Marlin/src/module/printcounter.h | 16 +++++++++------- Marlin/src/module/temperature.cpp | 1 - Marlin/src/pins/lpc1768/pins_MKS_SBASE.h | 2 +- 10 files changed, 29 insertions(+), 22 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index d86c4484417c..697b8e557ad9 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1753,6 +1753,9 @@ * View the current statistics with M78. */ //#define PRINTCOUNTER +#if ENABLED(PRINTCOUNTER) + #define PRINTCOUNTER_SAVE_INTERVAL 1 // (seconds) EEPROM save interval during print +#endif /** * Password diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index ce6d3fdde27f..61fca2ab730d 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -26,3 +26,10 @@ #elif EITHER(I2C_EEPROM, SPI_EEPROM) #define USE_SHARED_EEPROM 1 #endif + +// LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) +// TODO: Which other boards are incompatible? +#if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0 + #undef PRINTCOUNTER_SAVE_INTERVAL + #warning "PRINTCOUNTER_SAVE_INTERVAL causes print artifacts! Disabling auto-save." +#endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index b08f4e8192a5..e78f2053e927 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -378,9 +378,8 @@ void startOrResumeJob() { queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif - planner.synchronize(); // Wait for EVENT_GCODE_SD_ABORT to finish, so it doesn't get interrupted by PRINTCOUNTER - - print_job_timer.abort(); + planner.synchronize(); + print_job_timer.abort(); // Wait for planner before calling! TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } @@ -786,7 +785,9 @@ void minkill(const bool steppers_off/*=false*/) { */ void stop() { thermalManager.disable_all_heaters(); // 'unpause' taken care of in here - print_job_timer.stop(); + + planner.synchronize(); + print_job_timer.stop(); // Wait for planner before calling #if ENABLED(PROBING_FANS_OFF) if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h index 547c3b1db90f..13a202daedb1 100644 --- a/Marlin/src/core/boards.h +++ b/Marlin/src/core/boards.h @@ -415,4 +415,3 @@ #define MB(V...) DO(MB,||,V) #define IS_MELZI MB(MELZI, MELZI_CREALITY, MELZI_MAKR3D, MELZI_MALYAN, MELZI_TRONXY, MELZI_V2) -#define ENV_LPC1768 MB(RAMPS_14_RE_ARM_EFB, RAMPS_14_RE_ARM_EEB, RAMPS_14_RE_ARM_EFF, RAMPS_14_RE_ARM_EEF, RAMPS_14_RE_ARM_SF, MKS_SBASE, MKS_SGEN_L, AZSMZ_MINI, BIQU_BQ111_A4, SELENA_COMPACT, BIQU_B300_V1_0, GMARSH_X6_REV1, BTT_SKR_V1_1, BTT_SKR_V1_3, BTT_SKR_V1_4) \ No newline at end of file diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index ea09b34634dd..3d6b900eea88 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -90,7 +90,8 @@ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); planner.finish_and_disable(); - print_job_timer.stop(); //moved, so writing to eeprom doesn't interrupt queued planner moves + + print_job_timer.stop(); // Wait for planner before calling #if HAS_FAN thermalManager.zero_fan_speeds(); diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 77aea67853de..c78407a5af03 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1496,9 +1496,6 @@ void MarlinUI::update() { host_action_cancel(); #endif TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR)); - //print_job_timer.stop(); //is already called by abortSDPrinting(). - //...so it would be called twice in case of SDPrinting - // LCD_MESSAGEPGM(MSG_PRINT_ABORTED); TERN_(HAS_LCD_MENU, return_to_status()); } diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 5573b9b20ce8..f434aa0c199c 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -243,10 +243,8 @@ void PrintCounter::tick() { update_next = now + updateInterval * 1000; } - #if !ENV_LPC1768 - //LPC1769 boards seem to lose steps when saving to EEPROM during print (issue #20785) - //todo: Which other boards are incompatible? - static uint32_t eeprom_next; // = 0 + #if PRINTCOUNTER_SAVE_INTERVAL > 0 + static millis_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { eeprom_next = now + saveInterval * 1000; saveStats(); diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 0d75e6e3f7a1..f0e0da372731 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -77,13 +77,15 @@ class PrintCounter: public Stopwatch { */ static constexpr uint16_t updateInterval = 10; - /** - * @brief Interval in seconds between EEPROM saves - * @details This const value defines what will be the time between each - * EEPROM save cycle, the development team recommends to set this value - * no lower than 3600 secs (1 hour). - */ - static constexpr uint16_t saveInterval = 3600; + #if PRINTCOUNTER_SAVE_INTERVAL > 0 + /** + * @brief Interval in seconds between EEPROM saves + * @details This const value defines what will be the time between each + * EEPROM save cycle, the development team recommends to set this value + * no lower than 3600 secs (1 hour). + */ + static constexpr uint16_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; + #endif /** * @brief Timestamp of the last call to deltaDuration() diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 00a048736a6b..589baf77962e 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -2186,7 +2186,6 @@ void Temperature::disable_all_heaters() { #endif - #if ENABLED(PROBING_HEATERS_OFF) void Temperature::pause(const bool p) { diff --git a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h index ea9748ca5486..fbddc66e7ce6 100644 --- a/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h +++ b/Marlin/src/pins/lpc1768/pins_MKS_SBASE.h @@ -27,7 +27,7 @@ #if defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1769) #error "Oops! Make sure you have the LPC1769 environment selected in your IDE." -#elif NOT_TARGET(MKS_HAS_LPC1769, MCU_LPC1768) +#elif !defined(MKS_HAS_LPC1769) && NOT_TARGET(MCU_LPC1768) #error "Oops! Make sure you have the LPC1768 environment selected in your IDE." #endif From a0a94d3a50982424ca744c33004e5728b32f5411 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 02:49:49 -0600 Subject: [PATCH 06/18] synchronize is not sensible here --- Marlin/src/MarlinCore.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index e78f2053e927..9e2615514c88 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -364,6 +364,7 @@ void startOrResumeJob() { card.endFilePrint(TERN_(SD_RESORT, true)); queue.clear(); quickstop_stepper(); + print_job_timer.abort(); #if DISABLED(SD_ABORT_NO_COOLDOWN) thermalManager.disable_all_heaters(); #endif @@ -378,9 +379,6 @@ void startOrResumeJob() { queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif - planner.synchronize(); - print_job_timer.abort(); // Wait for planner before calling! - TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } From 75c65df52d1469b4da371de6a617fd50f826c4a1 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 03:02:21 -0600 Subject: [PATCH 07/18] Apply SEC_TO_MS --- Marlin/src/gcode/feature/L6470/M916-918.cpp | 2 +- Marlin/src/gcode/parser.h | 2 +- Marlin/src/module/printcounter.cpp | 9 +++++---- Marlin/src/module/printcounter.h | 4 ++-- Marlin/src/module/tool_change.cpp | 4 ++-- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Marlin/src/gcode/feature/L6470/M916-918.cpp b/Marlin/src/gcode/feature/L6470/M916-918.cpp index 2672f9123987..8a1ea4830606 100644 --- a/Marlin/src/gcode/feature/L6470/M916-918.cpp +++ b/Marlin/src/gcode/feature/L6470/M916-918.cpp @@ -119,7 +119,7 @@ void GcodeSuite::M916() { M91x_counter_max = 256; // KVAL_HOLD is 8 bits uint8_t M91x_delay_s = parser.byteval('D'); // get delay in seconds - millis_t M91x_delay_ms = M91x_delay_s * 60 * 1000; + millis_t M91x_delay_ms = SEC_TO_MS(M91x_delay_s * 60); millis_t M91x_delay_end; DEBUG_ECHOLNPGM(".\n."); diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 8633d2b1e9db..cf531c4e4705 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -282,7 +282,7 @@ class GCodeParser { // Code value for use as time static inline millis_t value_millis() { return value_ulong(); } - static inline millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); } + static inline millis_t value_millis_from_seconds() { return (millis_t)SEC_TO_MS(value_float()); } // Reduce to fewer bits static inline int16_t value_int() { return (int16_t)value_long(); } diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index f434aa0c199c..5cc4a90448e0 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -224,9 +224,12 @@ void PrintCounter::tick() { millis_t now = millis(); - static uint32_t update_next; // = 0 + static millis_t update_next; // = 0 if (ELAPSED(now, update_next)) { + update_next = now + updateInterval; + TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("tick"))); + millis_t delta = deltaDuration(); data.printTime += delta; @@ -239,14 +242,12 @@ void PrintCounter::tick() { #if SERVICE_INTERVAL_3 > 0 data.nextService3 -= _MIN(delta, data.nextService3); #endif - - update_next = now + updateInterval * 1000; } #if PRINTCOUNTER_SAVE_INTERVAL > 0 static millis_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { - eeprom_next = now + saveInterval * 1000; + eeprom_next = now + saveInterval; saveStats(); } #endif diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index f0e0da372731..5eb69cdc8e45 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -75,7 +75,7 @@ class PrintCounter: public Stopwatch { * @note The max value for this option is 60(s), otherwise integer * overflow will happen. */ - static constexpr uint16_t updateInterval = 10; + static constexpr millis_t updateInterval = SEC_TO_MS(10); #if PRINTCOUNTER_SAVE_INTERVAL > 0 /** @@ -84,7 +84,7 @@ class PrintCounter: public Stopwatch { * EEPROM save cycle, the development team recommends to set this value * no lower than 3600 secs (1 hour). */ - static constexpr uint16_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; + static constexpr millis_t saveInterval = SEC_TO_MS(PRINTCOUNTER_SAVE_INTERVAL); #endif /** diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 052b8cd34a64..867ae5d9271d 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -828,7 +828,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a // Cool down with fan #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed; - gcode.dwell(toolchange_settings.fan_time * 1000); + gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time)); thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0; #endif @@ -1102,7 +1102,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Cool down with fan #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed; - gcode.dwell(toolchange_settings.fan_time * 1000); + gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time)); thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0; #endif } From f6d284757021ba15a212316e20d2eb64a5ef29ff Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 03:14:57 -0600 Subject: [PATCH 08/18] Use original save interval --- Marlin/Configuration.h | 2 +- Marlin/src/module/printcounter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 697b8e557ad9..9c745c753bbe 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1754,7 +1754,7 @@ */ //#define PRINTCOUNTER #if ENABLED(PRINTCOUNTER) - #define PRINTCOUNTER_SAVE_INTERVAL 1 // (seconds) EEPROM save interval during print + #define PRINTCOUNTER_SAVE_INTERVAL 3600 // (ms) EEPROM save interval during print #endif /** diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 5eb69cdc8e45..5060686653f8 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -84,7 +84,7 @@ class PrintCounter: public Stopwatch { * EEPROM save cycle, the development team recommends to set this value * no lower than 3600 secs (1 hour). */ - static constexpr millis_t saveInterval = SEC_TO_MS(PRINTCOUNTER_SAVE_INTERVAL); + static constexpr millis_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; #endif /** From 71a4294b6a62254d15c4c312e935288e7d5b22e5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 03:51:16 -0600 Subject: [PATCH 09/18] Longer interval --- Marlin/Configuration.h | 2 +- Marlin/src/module/printcounter.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 9c745c753bbe..4fbee0977121 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -1754,7 +1754,7 @@ */ //#define PRINTCOUNTER #if ENABLED(PRINTCOUNTER) - #define PRINTCOUNTER_SAVE_INTERVAL 3600 // (ms) EEPROM save interval during print + #define PRINTCOUNTER_SAVE_INTERVAL 60 // (minutes) EEPROM save interval during print #endif /** diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 5060686653f8..7883b52beb0a 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -84,7 +84,7 @@ class PrintCounter: public Stopwatch { * EEPROM save cycle, the development team recommends to set this value * no lower than 3600 secs (1 hour). */ - static constexpr millis_t saveInterval = PRINTCOUNTER_SAVE_INTERVAL; + static constexpr millis_t saveInterval = SEC_TO_MS((PRINTCOUNTER_SAVE_INTERVAL) * 60); #endif /** From fd903e43d4d4b4a3d9cd699f3a511180deac6b72 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 03:54:28 -0600 Subject: [PATCH 10/18] better --- Marlin/src/module/printcounter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 7883b52beb0a..782b1f3cb11d 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -84,7 +84,7 @@ class PrintCounter: public Stopwatch { * EEPROM save cycle, the development team recommends to set this value * no lower than 3600 secs (1 hour). */ - static constexpr millis_t saveInterval = SEC_TO_MS((PRINTCOUNTER_SAVE_INTERVAL) * 60); + static constexpr millis_t saveInterval = MIN_TO_MS(PRINTCOUNTER_SAVE_INTERVAL); #endif /** From 211aeb880e4b4814bda97f5161fe2d3cd3ad9a41 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 04:12:06 -0600 Subject: [PATCH 11/18] sync instead of disabling --- Marlin/src/HAL/LPC1768/inc/Conditionals_post.h | 4 ++-- Marlin/src/module/printcounter.cpp | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index 61fca2ab730d..73cddaaf0ef1 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -30,6 +30,6 @@ // LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) // TODO: Which other boards are incompatible? #if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0 - #undef PRINTCOUNTER_SAVE_INTERVAL - #warning "PRINTCOUNTER_SAVE_INTERVAL causes print artifacts! Disabling auto-save." + #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save." + #define SYNC_FOR_PRINTCOUNTER 1 #endif diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 5cc4a90448e0..5ca444cb91ff 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -245,6 +245,7 @@ void PrintCounter::tick() { } #if PRINTCOUNTER_SAVE_INTERVAL > 0 + TERN(SYNC_FOR_PRINTCOUNTER, planner.synchronize()); static millis_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { eeprom_next = now + saveInterval; From 2ac41080715755ab24f26289e3697adedc1cc044 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 04:25:37 -0600 Subject: [PATCH 12/18] .stop needed for non-sd --- Marlin/src/lcd/marlinui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index c78407a5af03..46db57193669 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1495,6 +1495,7 @@ void MarlinUI::update() { #ifdef ACTION_ON_CANCEL host_action_cancel(); #endif + IF_DISABLED(SDSUPPORT, print_job_timer.stop()); TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR)); LCD_MESSAGEPGM(MSG_PRINT_ABORTED); TERN_(HAS_LCD_MENU, return_to_status()); From 9e61b9aba180f59eac02469b6f250f0e6efe6da3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 04:55:26 -0600 Subject: [PATCH 13/18] Sync on any write --- Marlin/src/HAL/LPC1768/inc/Conditionals_post.h | 2 +- Marlin/src/MarlinCore.cpp | 6 ++++-- Marlin/src/gcode/control/M80_M81.cpp | 2 +- Marlin/src/module/printcounter.cpp | 7 ++++++- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index 73cddaaf0ef1..94e4ce134170 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -31,5 +31,5 @@ // TODO: Which other boards are incompatible? #if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0 #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save." - #define SYNC_FOR_PRINTCOUNTER 1 + #define PRINTCOUNTER_SYNC 1 #endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 9e2615514c88..26386c86ff44 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -362,6 +362,7 @@ void startOrResumeJob() { inline void abortSDPrinting() { IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel()); card.endFilePrint(TERN_(SD_RESORT, true)); + queue.clear(); quickstop_stepper(); print_job_timer.abort(); @@ -374,7 +375,9 @@ void startOrResumeJob() { cutter.kill(); // Full cutter shutdown including ISR control #endif wait_for_heatup = false; + TERN_(POWER_LOSS_RECOVERY, recovery.purge()); + #ifdef EVENT_GCODE_SD_ABORT queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif @@ -784,8 +787,7 @@ void minkill(const bool steppers_off/*=false*/) { void stop() { thermalManager.disable_all_heaters(); // 'unpause' taken care of in here - planner.synchronize(); - print_job_timer.stop(); // Wait for planner before calling + print_job_timer.stop(); #if ENABLED(PROBING_FANS_OFF) if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index 3d6b900eea88..394b06d8ac30 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -91,7 +91,7 @@ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); planner.finish_and_disable(); - print_job_timer.stop(); // Wait for planner before calling + print_job_timer.stop(); #if HAS_FAN thermalManager.zero_fan_speeds(); diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 5ca444cb91ff..654155497e6e 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -41,6 +41,10 @@ Stopwatch print_job_timer; // Global Print Job Timer instance #include "../libs/buzzer.h" #endif +#if PRINTCOUNTER_SYNC + #include "../module/planner.h" +#endif + // Service intervals #if HAS_SERVICE_INTERVALS #if SERVICE_INTERVAL_1 > 0 @@ -160,6 +164,8 @@ void PrintCounter::saveStats() { // Refuses to save data if object is not loaded if (!isLoaded()) return; + TERN(PRINTCOUNTER_SYNC, planner.synchronize()); + // Saves the struct to EEPROM persistentStore.access_start(); persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics)); @@ -245,7 +251,6 @@ void PrintCounter::tick() { } #if PRINTCOUNTER_SAVE_INTERVAL > 0 - TERN(SYNC_FOR_PRINTCOUNTER, planner.synchronize()); static millis_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { eeprom_next = now + saveInterval; From 02d267f6139e9984d8a8117a68fac1bf322e0fbb Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 25 Jan 2021 07:31:58 -0600 Subject: [PATCH 14/18] etc --- Marlin/src/module/printcounter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 654155497e6e..45072c8f0189 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -164,7 +164,7 @@ void PrintCounter::saveStats() { // Refuses to save data if object is not loaded if (!isLoaded()) return; - TERN(PRINTCOUNTER_SYNC, planner.synchronize()); + TERN_(PRINTCOUNTER_SYNC, planner.synchronize()); // Saves the struct to EEPROM persistentStore.access_start(); From 57a666556c2e715af38dfe65a9a37106face0ecb Mon Sep 17 00:00:00 2001 From: ConstantijnCrijnen <43953114+ConstantijnCrijnen@users.noreply.github.com> Date: Mon, 25 Jan 2021 22:03:21 +0100 Subject: [PATCH 15/18] Revert "Merge branch 'Printcounter-Fix-(issue-#20785)' of https://github.com/ConstantijnCrijnen/Marlin into Printcounter-Fix-(issue-#20785)" This reverts commit a5571df42e65e9279fe3f2874cd424f669744ed9, reversing changes made to 977eaa09ee2fd613846ba044acff3ebd44e4bb1e. --- Marlin/Configuration.h | 5 +- Marlin/Configuration_adv.h | 34 +- .../src/HAL/LPC1768/inc/Conditionals_post.h | 7 - Marlin/src/MarlinCore.cpp | 26 +- Marlin/src/gcode/control/M80_M81.cpp | 2 +- Marlin/src/gcode/feature/L6470/M916-918.cpp | 2 +- Marlin/src/gcode/parser.h | 2 +- Marlin/src/inc/Conditionals_LCD.h | 43 ++- Marlin/src/inc/SanityCheck.h | 2 + Marlin/src/inc/Version.h | 2 +- Marlin/src/lcd/dogm/dogm_Statusscreen.h | 2 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 4 - Marlin/src/lcd/dwin/e3v2/dwin.cpp | 63 ++-- Marlin/src/lcd/marlinui.cpp | 1 - Marlin/src/lcd/menu/menu_bed_corners.cpp | 8 +- Marlin/src/lcd/menu/menu_tune.cpp | 13 +- Marlin/src/lcd/tft/tft_image.cpp | 41 +-- Marlin/src/lcd/tft/tft_image.h | 3 +- Marlin/src/lcd/tft/tft_string.cpp | 7 +- Marlin/src/lcd/tft/tft_string.h | 7 +- Marlin/src/lcd/tft/ui_320x240.cpp | 251 ++++++++++++--- Marlin/src/lcd/tft/ui_320x240.h | 92 +++++- Marlin/src/lcd/tft/ui_480x320.cpp | 291 +++++++++++++++--- Marlin/src/lcd/tft/ui_480x320.h | 104 +++++-- Marlin/src/lcd/tft/ui_common.cpp | 246 --------------- Marlin/src/lcd/tft/ui_common.h | 76 ----- Marlin/src/module/printcounter.cpp | 21 +- Marlin/src/module/printcounter.h | 21 +- Marlin/src/module/tool_change.cpp | 4 +- .../PlatformIO/scripts/common-dependencies.py | 2 +- 30 files changed, 749 insertions(+), 633 deletions(-) delete mode 100644 Marlin/src/lcd/tft/ui_common.cpp delete mode 100644 Marlin/src/lcd/tft/ui_common.h diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 461b679d0497..d86c4484417c 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -421,7 +421,7 @@ #define TEMP_SENSOR_CHAMBER 0 // Dummy thermistor constant temperature readings, for use with 998 and 999 -#define DUMMY_THERMISTOR_998_VALUE 25 +#define DUMMY_THERMISTOR_998_VALUE 25 #define DUMMY_THERMISTOR_999_VALUE 100 // Resistor values when using MAX31865 sensors (-5) on TEMP_SENSOR_0 / 1 @@ -1753,9 +1753,6 @@ * View the current statistics with M78. */ //#define PRINTCOUNTER -#if ENABLED(PRINTCOUNTER) - #define PRINTCOUNTER_SAVE_INTERVAL 60 // (minutes) EEPROM save interval during print -#endif /** * Password diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index bcd1d6242290..604bbb9359b6 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -163,7 +163,7 @@ #if ENABLED(CHAMBER_VENT) #define CHAMBER_VENT_SERVO_NR 1 // Index of the vent servo #define HIGH_EXCESS_HEAT_LIMIT 5 // How much above target temp to consider there is excess heat in the chamber - #define LOW_EXCESS_HEAT_LIMIT 3 + #define LOW_EXCESS_HEAT_LIMIT 3 #define MIN_COOLING_SLOPE_TIME_CHAMBER_VENT 20 #define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5 #endif @@ -206,7 +206,7 @@ * and/or decrease WATCH_TEMP_INCREASE. WATCH_TEMP_INCREASE should not be set * below 2. */ - #define WATCH_TEMP_PERIOD 20 // Seconds + #define WATCH_TEMP_PERIOD 20 // Seconds #define WATCH_TEMP_INCREASE 2 // Degrees Celsius #endif @@ -284,8 +284,8 @@ // DEFAULT_Kf and PID_FAN_SCALING_LIN_FACTOR are calculated accordingly. #define PID_FAN_SCALING_AT_FULL_SPEED 13.0 //=PID_FAN_SCALING_LIN_FACTOR*255+DEFAULT_Kf - #define PID_FAN_SCALING_AT_MIN_SPEED 6.0 //=PID_FAN_SCALING_LIN_FACTOR*PID_FAN_SCALING_MIN_SPEED+DEFAULT_Kf - #define PID_FAN_SCALING_MIN_SPEED 10.0 // Minimum fan speed at which to enable PID_FAN_SCALING + #define PID_FAN_SCALING_AT_MIN_SPEED 6.0 //=PID_FAN_SCALING_LIN_FACTOR*PID_FAN_SCALING_MIN_SPEED+DEFAULT_Kf + #define PID_FAN_SCALING_MIN_SPEED 10.0 // Minimum fan speed at which to enable PID_FAN_SCALING #define DEFAULT_Kf (255.0*PID_FAN_SCALING_AT_MIN_SPEED-PID_FAN_SCALING_AT_FULL_SPEED*PID_FAN_SCALING_MIN_SPEED)/(255.0-PID_FAN_SCALING_MIN_SPEED) #define PID_FAN_SCALING_LIN_FACTOR (PID_FAN_SCALING_AT_FULL_SPEED-DEFAULT_Kf)/255.0 @@ -2056,21 +2056,21 @@ */ //#define FWRETRACT #if ENABLED(FWRETRACT) - #define FWRETRACT_AUTORETRACT // Override slicer retractions + #define FWRETRACT_AUTORETRACT // Override slicer retractions #if ENABLED(FWRETRACT_AUTORETRACT) - #define MIN_AUTORETRACT 0.1 // (mm) Don't convert E moves under this length - #define MAX_AUTORETRACT 10.0 // (mm) Don't convert E moves over this length - #endif - #define RETRACT_LENGTH 3 // (mm) Default retract length (positive value) - #define RETRACT_LENGTH_SWAP 13 // (mm) Default swap retract length (positive value) - #define RETRACT_FEEDRATE 45 // (mm/s) Default feedrate for retracting - #define RETRACT_ZRAISE 0 // (mm) Default retract Z-raise - #define RETRACT_RECOVER_LENGTH 0 // (mm) Default additional recover length (added to retract length on recover) - #define RETRACT_RECOVER_LENGTH_SWAP 0 // (mm) Default additional swap recover length (added to retract length on recover from toolchange) - #define RETRACT_RECOVER_FEEDRATE 8 // (mm/s) Default feedrate for recovering from retraction - #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // (mm/s) Default feedrate for recovering from swap retraction + #define MIN_AUTORETRACT 0.1 // (mm) Don't convert E moves under this length + #define MAX_AUTORETRACT 10.0 // (mm) Don't convert E moves over this length + #endif + #define RETRACT_LENGTH 3 // (mm) Default retract length (positive value) + #define RETRACT_LENGTH_SWAP 13 // (mm) Default swap retract length (positive value) + #define RETRACT_FEEDRATE 45 // (mm/s) Default feedrate for retracting + #define RETRACT_ZRAISE 0 // (mm) Default retract Z-raise + #define RETRACT_RECOVER_LENGTH 0 // (mm) Default additional recover length (added to retract length on recover) + #define RETRACT_RECOVER_LENGTH_SWAP 0 // (mm) Default additional swap recover length (added to retract length on recover from toolchange) + #define RETRACT_RECOVER_FEEDRATE 8 // (mm/s) Default feedrate for recovering from retraction + #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // (mm/s) Default feedrate for recovering from swap retraction #if ENABLED(MIXING_EXTRUDER) - //#define RETRACT_SYNC_MIXING // Retract and restore all mixing steppers simultaneously + //#define RETRACT_SYNC_MIXING // Retract and restore all mixing steppers simultaneously #endif #endif diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index 94e4ce134170..ce6d3fdde27f 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -26,10 +26,3 @@ #elif EITHER(I2C_EEPROM, SPI_EEPROM) #define USE_SHARED_EEPROM 1 #endif - -// LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) -// TODO: Which other boards are incompatible? -#if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0 - #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save." - #define PRINTCOUNTER_SYNC 1 -#endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 77df2fdc5888..d1ca900449e1 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -362,24 +362,25 @@ void startOrResumeJob() { inline void abortSDPrinting() { IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel()); card.endFilePrint(TERN_(SD_RESORT, true)); - queue.clear(); quickstop_stepper(); - - print_job_timer.abort(); - - IF_DISABLED(SD_ABORT_NO_COOLDOWN, thermalManager.disable_all_heaters()); - - TERN(HAS_CUTTER, cutter.kill(), thermalManager.zero_fan_speeds()); // Full cutter shutdown including ISR control - + #if DISABLED(SD_ABORT_NO_COOLDOWN) + thermalManager.disable_all_heaters(); + #endif + #if !HAS_CUTTER + thermalManager.zero_fan_speeds(); + #else + cutter.kill(); // Full cutter shutdown including ISR control + #endif wait_for_heatup = false; - TERN_(POWER_LOSS_RECOVERY, recovery.purge()); - #ifdef EVENT_GCODE_SD_ABORT queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif + planner.synchronize(); + print_job_timer.abort(); // Wait for planner before calling! + TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } @@ -785,7 +786,8 @@ void minkill(const bool steppers_off/*=false*/) { void stop() { thermalManager.disable_all_heaters(); // 'unpause' taken care of in here - print_job_timer.stop(); + planner.synchronize(); + print_job_timer.stop(); // Wait for planner before calling! #if ENABLED(PROBING_FANS_OFF) if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were @@ -955,7 +957,7 @@ void setup() { #endif #if HAS_SUICIDE - SETUP_LOG("SUICIDE_PIN"); + SETUP_LOG("SUICIDE_PIN") OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING); #endif diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index 394b06d8ac30..cd5a92d7b31e 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -91,7 +91,7 @@ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); planner.finish_and_disable(); - print_job_timer.stop(); + print_job_timer.stop(); // Wait for planner before calling! #if HAS_FAN thermalManager.zero_fan_speeds(); diff --git a/Marlin/src/gcode/feature/L6470/M916-918.cpp b/Marlin/src/gcode/feature/L6470/M916-918.cpp index 8a1ea4830606..2672f9123987 100644 --- a/Marlin/src/gcode/feature/L6470/M916-918.cpp +++ b/Marlin/src/gcode/feature/L6470/M916-918.cpp @@ -119,7 +119,7 @@ void GcodeSuite::M916() { M91x_counter_max = 256; // KVAL_HOLD is 8 bits uint8_t M91x_delay_s = parser.byteval('D'); // get delay in seconds - millis_t M91x_delay_ms = SEC_TO_MS(M91x_delay_s * 60); + millis_t M91x_delay_ms = M91x_delay_s * 60 * 1000; millis_t M91x_delay_end; DEBUG_ECHOLNPGM(".\n."); diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index cf531c4e4705..8633d2b1e9db 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -282,7 +282,7 @@ class GCodeParser { // Code value for use as time static inline millis_t value_millis() { return value_ulong(); } - static inline millis_t value_millis_from_seconds() { return (millis_t)SEC_TO_MS(value_float()); } + static inline millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); } // Reduce to fewer bits static inline int16_t value_int() { return (int16_t)value_long(); } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 2acda7bd5937..a5bb24f27c41 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1155,37 +1155,36 @@ #endif #endif -#if ENABLED(TFT_COLOR_UI) - #if TFT_HEIGHT == 240 - #if ENABLED(TFT_INTERFACE_SPI) - #define TFT_320x240_SPI - #elif ENABLED(TFT_INTERFACE_FSMC) - #define TFT_320x240 - #endif - #elif TFT_HEIGHT == 320 - #if ENABLED(TFT_INTERFACE_SPI) - #define TFT_480x320_SPI - #elif ENABLED(TFT_INTERFACE_FSMC) - #define TFT_480x320 - #endif - #elif TFT_HEIGHT == 272 - #if ENABLED(TFT_INTERFACE_SPI) - #define TFT_480x272_SPI - #elif ENABLED(TFT_INTERFACE_FSMC) - #define TFT_480x272 - #endif +#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_320x240_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_320x240 + #endif +#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_480x320_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_480x320 + #endif +#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_480x272_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_480x272 #endif #endif +// Fewer lines with touch buttons on-screen #if EITHER(TFT_320x240, TFT_320x240_SPI) #define HAS_UI_320x240 1 + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) #elif EITHER(TFT_480x320, TFT_480x320_SPI) #define HAS_UI_480x320 1 + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) #elif EITHER(TFT_480x272, TFT_480x272_SPI) #define HAS_UI_480x272 1 -#endif -#if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272) - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) #endif // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index b3beedfe80fd..1f7b317917c9 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -802,6 +802,8 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #if ENABLED(BABYSTEP_XY) static_assert(BABYSTEP_MULTIPLICATOR_XY <= 0.25f, "BABYSTEP_MULTIPLICATOR_XY must be less than or equal to 0.25mm."); #endif + #elif ENABLED(BABYSTEP_DISPLAY_TOTAL) && ANY(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) + #error "New Color UI (TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) does not support BABYSTEP_DISPLAY_TOTAL yet." #endif #endif diff --git a/Marlin/src/inc/Version.h b/Marlin/src/inc/Version.h index 81708fe4295c..a41c32caecce 100644 --- a/Marlin/src/inc/Version.h +++ b/Marlin/src/inc/Version.h @@ -42,7 +42,7 @@ * version was tagged. */ #ifndef STRING_DISTRIBUTION_DATE - #define STRING_DISTRIBUTION_DATE "2021-01-25" + #define STRING_DISTRIBUTION_DATE "2021-01-24" #endif /** diff --git a/Marlin/src/lcd/dogm/dogm_Statusscreen.h b/Marlin/src/lcd/dogm/dogm_Statusscreen.h index 61fee3e048ff..15578e21d92d 100644 --- a/Marlin/src/lcd/dogm/dogm_Statusscreen.h +++ b/Marlin/src/lcd/dogm/dogm_Statusscreen.h @@ -193,7 +193,7 @@ #define STATUS_LOGO_HEIGHT (sizeof(status_logo_bmp) / (STATUS_LOGO_BYTEWIDTH)) #endif #ifndef STATUS_LOGO_Y - #define STATUS_LOGO_Y _MAX(0U, (28U - _MIN(28U, STATUS_LOGO_HEIGHT)) / 2U) + #define STATUS_LOGO_Y _MAX(0L, (28L - _MIN(28L, STATUS_LOGO_HEIGHT)) / 2L) #endif static_assert( sizeof(status_logo_bmp) == (STATUS_LOGO_BYTEWIDTH) * (STATUS_LOGO_HEIGHT), diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 8ae6ab662793..985041ede572 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -40,10 +40,6 @@ #include "../../gcode/parser.h" // for units (and volumetric) -#if ENABLED(LCD_SHOW_E_TOTAL) - #include "../../MarlinCore.h" // for printingIsActive(), marlin_state and MF_SD_COMPLETE -#endif - #if ENABLED(FILAMENT_LCD_DISPLAY) #include "../../feature/filwidth.h" #include "../../module/planner.h" diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index e0caa0722f18..b872ce32aa07 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -132,9 +132,8 @@ #define FEEDRATE_E (60) -// Minimum unit (0.1) : multiple (10) -#define UNITFDIGITS 1 -#define MINUNITMULT pow(10, UNITFDIGITS) +// Mininum unit (0.1) : multiple (10) +#define MINUNITMULT 10 #define ENCODER_WAIT 20 #define DWIN_SCROLL_UPDATE_INTERVAL 2000 @@ -1172,8 +1171,8 @@ void HMI_Move_X() { } NOLESS(HMI_ValueStruct.Move_X_scale, (X_MIN_POS) * MINUNITMULT); NOMORE(HMI_ValueStruct.Move_X_scale, (X_MAX_POS) * MINUNITMULT); - current_position.x = HMI_ValueStruct.Move_X_scale / MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(1), HMI_ValueStruct.Move_X_scale); + current_position.x = HMI_ValueStruct.Move_X_scale / 10; + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale); DWIN_UpdateLCD(); } } @@ -1195,8 +1194,8 @@ void HMI_Move_Y() { } NOLESS(HMI_ValueStruct.Move_Y_scale, (Y_MIN_POS) * MINUNITMULT); NOMORE(HMI_ValueStruct.Move_Y_scale, (Y_MAX_POS) * MINUNITMULT); - current_position.y = HMI_ValueStruct.Move_Y_scale / MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale); + current_position.y = HMI_ValueStruct.Move_Y_scale / 10; + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale); DWIN_UpdateLCD(); } } @@ -1207,7 +1206,7 @@ void HMI_Move_Z() { if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Z_scale)) { checkkey = AxisMove; EncoderRate.enabled = false; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); if (!planner.is_full()) { // Wait for planner moves to finish! planner.synchronize(); @@ -1218,8 +1217,8 @@ void HMI_Move_Z() { } NOLESS(HMI_ValueStruct.Move_Z_scale, Z_MIN_POS * MINUNITMULT); NOMORE(HMI_ValueStruct.Move_Z_scale, Z_MAX_POS * MINUNITMULT); - current_position.z = HMI_ValueStruct.Move_Z_scale / MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); + current_position.z = HMI_ValueStruct.Move_Z_scale / 10; + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); DWIN_UpdateLCD(); } } @@ -1234,7 +1233,7 @@ void HMI_Move_Z() { checkkey = AxisMove; EncoderRate.enabled = false; last_E_scale = HMI_ValueStruct.Move_E_scale; - DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); + DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); if (!planner.is_full()) { planner.synchronize(); // Wait for planner moves to finish! planner.buffer_line(current_position, MMM_TO_MMS(FEEDRATE_E), active_extruder); @@ -1246,8 +1245,8 @@ void HMI_Move_Z() { HMI_ValueStruct.Move_E_scale = last_E_scale + (EXTRUDE_MAXLENGTH) * MINUNITMULT; else if ((last_E_scale - HMI_ValueStruct.Move_E_scale) > (EXTRUDE_MAXLENGTH) * MINUNITMULT) HMI_ValueStruct.Move_E_scale = last_E_scale - (EXTRUDE_MAXLENGTH) * MINUNITMULT; - current_position.e = HMI_ValueStruct.Move_E_scale / MINUNITMULT; - DWIN_Draw_Signed_Float(font8x16, Select_Color, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); + current_position.e = HMI_ValueStruct.Move_E_scale / 10; + DWIN_Draw_Signed_Float(font8x16, Select_Color, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); DWIN_UpdateLCD(); } } @@ -1504,7 +1503,7 @@ void HMI_MaxAccelerationXYZE() { NOMORE(HMI_ValueStruct.Max_Jerk, default_max_jerk[HMI_flag.jerk_axis] * 2 * MINUNITMULT); NOLESS(HMI_ValueStruct.Max_Jerk, (MIN_MAXJERK) * MINUNITMULT); // MaxJerk value - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); } } @@ -1526,7 +1525,7 @@ void HMI_StepXYZE() { NOMORE(HMI_ValueStruct.Max_Step, 999.9 * MINUNITMULT); NOLESS(HMI_ValueStruct.Max_Step, MIN_STEP); // Step value - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); } } @@ -2318,12 +2317,13 @@ void HMI_Prepare() { select_axis.reset(); Draw_Move_Menu(); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(1), current_position.x * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(2), current_position.y * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(3), current_position.z * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(1), current_position.x * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(2), current_position.y * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(3), current_position.z * MINUNITMULT); #if HAS_HOTEND - HMI_ValueStruct.Move_E_scale = current_position.e * MINUNITMULT; - DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); + current_position.e = HMI_ValueStruct.Move_E_scale = 0.0; + sync_plan_position_e(); + DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, 1, 216, MBASE(4), 0.0); #endif break; case PREPARE_CASE_DISA: // Disable steppers @@ -2573,7 +2573,8 @@ void HMI_AxisMove() { if (HMI_flag.ETempTooLow_flag) { if (encoder_diffState == ENCODER_DIFF_ENTER) { HMI_flag.ETempTooLow_flag = false; - HMI_ValueStruct.Move_E_scale = current_position.e * MINUNITMULT; + current_position.e = HMI_ValueStruct.Move_E_scale = 0; + sync_plan_position_e(); Draw_Move_Menu(); DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale); DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale); @@ -3019,11 +3020,11 @@ inline void Draw_Max_Accel_Menu() { Draw_Back_First(); LOOP_L_N(i, 3 + ENABLED(HAS_HOTEND)) Draw_Menu_Line(i + 1, ICON_MaxSpeedJerkX + i); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(1), planner.max_jerk[X_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(2), planner.max_jerk[Y_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(3), planner.max_jerk[Z_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(1), planner.max_jerk[X_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(2), planner.max_jerk[Y_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(3), planner.max_jerk[Z_AXIS] * MINUNITMULT); #if HAS_HOTEND - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(4), planner.max_jerk[E_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(4), planner.max_jerk[E_AXIS] * MINUNITMULT); #endif } #endif @@ -3067,11 +3068,11 @@ inline void Draw_Steps_Menu() { Draw_Back_First(); LOOP_L_N(i, 3 + ENABLED(HAS_HOTEND)) Draw_Menu_Line(i + 1, ICON_StepX + i); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(1), planner.settings.axis_steps_per_mm[X_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(2), planner.settings.axis_steps_per_mm[Y_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(3), planner.settings.axis_steps_per_mm[Z_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(1), planner.settings.axis_steps_per_mm[X_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(2), planner.settings.axis_steps_per_mm[Y_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(3), planner.settings.axis_steps_per_mm[Z_AXIS] * MINUNITMULT); #if HAS_HOTEND - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(4), planner.settings.axis_steps_per_mm[E_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(4), planner.settings.axis_steps_per_mm[E_AXIS] * MINUNITMULT); #endif } @@ -3418,7 +3419,7 @@ void HMI_MaxAcceleration() { checkkey = MaxJerk_value; HMI_flag.jerk_axis = AxisEnum(select_jerk.now - 1); HMI_ValueStruct.Max_Jerk = planner.max_jerk[HMI_flag.jerk_axis] * MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); EncoderRate.enabled = true; } else { // Back @@ -3448,7 +3449,7 @@ void HMI_Step() { checkkey = Step_value; HMI_flag.step_axis = AxisEnum(select_step.now - 1); HMI_ValueStruct.Max_Step = planner.settings.axis_steps_per_mm[HMI_flag.step_axis] * MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); EncoderRate.enabled = true; } else { // Back diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index 46db57193669..c78407a5af03 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1495,7 +1495,6 @@ void MarlinUI::update() { #ifdef ACTION_ON_CANCEL host_action_cancel(); #endif - IF_DISABLED(SDSUPPORT, print_job_timer.stop()); TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR)); LCD_MESSAGEPGM(MSG_PRINT_ABORTED); TERN_(HAS_LCD_MENU, return_to_status()); diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 751be18600f6..473b09d3280b 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -174,13 +174,12 @@ static inline void _lcd_level_bed_corners_get_next_position() { MenuItem_static::draw(0, GET_TEXT(MSG_PROBING_MESH), SS_INVERT); // "Probing Mesh" heading - uint8_t cy = TERN(TFT_COLOR_UI, 3, LCD_HEIGHT - 1), y = LCD_ROW_Y(cy); + uint8_t cy = LCD_HEIGHT - 1, y = LCD_ROW_Y(cy); // Display # of good points found vs total needed if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) { - SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy); + SETCURSOR(0, cy); lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_GOOD_POINTS)); - IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, cy)); lcd_put_u8str(GOOD_POINTS_TO_STR(good_points)); lcd_put_wchar('/'); lcd_put_u8str(GOOD_POINTS_TO_STR(nr_edge_points)); @@ -191,9 +190,8 @@ static inline void _lcd_level_bed_corners_get_next_position() { // Display the Last Z value if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) { - SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy); + SETCURSOR(0, cy); lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_LAST_Z)); - IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, 2)); lcd_put_u8str(LAST_Z_TO_STR(last_z)); } } diff --git a/Marlin/src/lcd/menu/menu_tune.cpp b/Marlin/src/lcd/menu/menu_tune.cpp index 0fbb57f2ac17..cccb352d8ff0 100644 --- a/Marlin/src/lcd/menu/menu_tune.cpp +++ b/Marlin/src/lcd/menu/menu_tune.cpp @@ -71,16 +71,9 @@ const bool in_view = TERN1(HAS_MARLINUI_U8GLIB, PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1)); if (in_view) { TERN_(HAS_MARLINUI_U8GLIB, ui.set_font(FONT_MENU)); - #if ENABLED(TFT_COLOR_UI) - lcd_moveto(4, 3); - lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL)); - lcd_put_wchar(':'); - lcd_moveto(10, 3); - #else - lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1)); - lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL)); - lcd_put_wchar(':'); - #endif + lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1)); + lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL)); + lcd_put_wchar(':'); lcd_put_u8str(BABYSTEP_TO_STR(spm * babystep.axis_total[BS_TOTAL_IND(axis)])); } #endif diff --git a/Marlin/src/lcd/tft/tft_image.cpp b/Marlin/src/lcd/tft/tft_image.cpp index 851410b2e0f5..9cc6fb15e4a0 100644 --- a/Marlin/src/lcd/tft/tft_image.cpp +++ b/Marlin/src/lcd/tft/tft_image.cpp @@ -20,11 +20,8 @@ * */ -#include "../../inc/MarlinConfigPre.h" - -#if HAS_GRAPHICAL_TFT - #include "tft_image.h" +#include const tImage NoLogo = { nullptr, 0, 0, NOCOLORS }; @@ -73,38 +70,4 @@ const tImage Leveling_32x32x4 = { (void *)leveling_32x32x4, 32, 32, GREYSC const tImage Slider8x16x4 = { (void *)slider_8x16x4, 8, 16, GREYSCALE4 }; -const tImage Images[imgCount] = { - TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MARLIN_LOGO_FULL_SIZE), NoLogo), - HotEnd_64x64x4, - Bed_64x64x4, - Bed_Heated_64x64x4, - Chamber_64x64x4, - Chamber_Heated_64x64x4, - Fan0_64x64x4, - Fan_Slow0_64x64x4, - Fan_Slow1_64x64x4, - Fan_Fast0_64x64x4, - Fan_Fast1_64x64x4, - Feedrate_32x32x4, - Flowrate_32x32x4, - SD_64x64x4, - Menu_64x64x4, - Settings_64x64x4, - Directory_32x32x4, - Confirm_64x64x4, - Cancel_64x64x4, - Increase_64x64x4, - Decrease_64x64x4, - Back_32x32x4, - Up_32x32x4, - Down_32x32x4, - Left_32x32x4, - Right_32x32x4, - Refresh_32x32x4, - Leveling_32x32x4, - Slider8x16x4, - Home_64x64x4, - BtnRounded_64x52x4, -}; - -#endif // HAS_GRAPHICAL_TFT +extern const tImage Images[imgCount]; diff --git a/Marlin/src/lcd/tft/tft_image.h b/Marlin/src/lcd/tft/tft_image.h index 960a4e4356af..21bd2d665fc6 100644 --- a/Marlin/src/lcd/tft/tft_image.h +++ b/Marlin/src/lcd/tft/tft_image.h @@ -21,10 +21,9 @@ */ #pragma once +#include "stdint.h" #include "../../inc/MarlinConfigPre.h" -#include - extern const uint8_t marlin_logo_112x38x1[]; extern const uint8_t marlin_logo_228x255x2[]; extern const uint8_t marlin_logo_228x255x4[]; diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index 31ac14cf92b3..eb805ac423dc 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -36,7 +36,7 @@ font_t *TFT_String::font_header; uint8_t TFT_String::data[]; uint16_t TFT_String::span; -uint8_t TFT_String::length; +uint16_t TFT_String::length; void TFT_String::set_font(const uint8_t *font) { font_header = (font_t *)font; @@ -122,14 +122,13 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { eol(); } -void TFT_String::add(uint8_t *string, uint8_t max_len) { +void TFT_String::add(uint8_t *string) { wchar_t wchar; - while (*string && max_len) { + while (*string) { string = get_utf8_value_cb(string, read_byte, &wchar); if (wchar > 255) wchar |= 0x0080; uint8_t ch = uint8_t(wchar & 0x00FF); add_character(ch); - max_len--; } eol(); } diff --git a/Marlin/src/lcd/tft/tft_string.h b/Marlin/src/lcd/tft/tft_string.h index 133889d9ae54..e800b1ded95e 100644 --- a/Marlin/src/lcd/tft/tft_string.h +++ b/Marlin/src/lcd/tft/tft_string.h @@ -69,7 +69,7 @@ class TFT_String { static uint8_t data[MAX_STRING_LENGTH + 1]; static uint16_t span; // in pixels - static uint8_t length; // in characters + static uint16_t length; // in characters static void add_character(uint8_t character); static void eol() { data[length] = 0x00; } @@ -85,7 +85,7 @@ class TFT_String { static void set(); static void add(uint8_t character) { add_character(character); eol(); } - static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH); + static void add(uint8_t *string); static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr); static void set(uint8_t *string) { set(); add(string); }; static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); }; @@ -96,9 +96,6 @@ class TFT_String { static void trim(uint8_t character=0x20); static void rtrim(uint8_t character=0x20); static void ltrim(uint8_t character=0x20); - - static void truncate(uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } } - static uint16_t width() { return span; } static uint8_t *string() { return data; } static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; } diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index eadd09ef27ec..aea0039698a2 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -24,7 +24,7 @@ #if HAS_UI_320x240 -#include "ui_common.h" +#include "ui_320x240.h" #include "../marlinui.h" #include "../menu/menu.h" @@ -45,6 +45,12 @@ #include "../../feature/bedlevel/bedlevel.h" #endif +#if !HAS_LCD_MENU + #error "Seriously? High resolution TFT screen without menu?" +#endif + +static bool draw_menu_navigation = false; + void MarlinUI::tft_idle() { #if ENABLED(TOUCH_SCREEN) if (draw_menu_navigation) { @@ -59,6 +65,28 @@ void MarlinUI::tft_idle() { TERN_(TOUCH_SCREEN, touch.idle()); } +void MarlinUI::init_lcd() { + tft.init(); + tft.set_font(MENU_FONT_NAME); + #ifdef SYMBOLS_FONT_NAME + tft.add_glyphs(SYMBOLS_FONT_NAME); + #endif + TERN_(TOUCH_SCREEN, touch.init()); + clear_lcd(); +} + +bool MarlinUI::detected() { return true; } + +void MarlinUI::clear_lcd() { + #if ENABLED(TOUCH_SCREEN) + touch.reset(); + draw_menu_navigation = false; + #endif + + tft.queue.reset(); + tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND); +} + #if ENABLED(SHOW_BOOTSCREEN) void MarlinUI::show_bootscreen() { tft.queue.reset(); @@ -70,8 +98,8 @@ void MarlinUI::tft_idle() { #define SITE_URL_Y (TFT_HEIGHT - 46) tft.set_background(COLOR_BACKGROUND); #else - #define BOOT_LOGO_W TFT_WIDTH // MarlinLogo320x240x16 - #define BOOT_LOGO_H TFT_HEIGHT + #define BOOT_LOGO_W 320 // MarlinLogo320x240x16 + #define BOOT_LOGO_H 240 #define SITE_URL_Y (TFT_HEIGHT - 52) #endif tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen); @@ -120,22 +148,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { currentTemperature = thermalManager.degHotend(Heater); targetTemperature = thermalManager.degTargetHotend(Heater); } - #if HAS_HEATED_BED - else if (Heater == H_BED) { - currentTemperature = thermalManager.degBed(); - targetTemperature = thermalManager.degTargetBed(); - } - #endif - #if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - currentTemperature = thermalManager.degChamber(); - #if HAS_HEATED_CHAMBER - targetTemperature = thermalManager.degTargetChamber(); - #else - targetTemperature = ABSOLUTE_ZERO; - #endif - } - #endif +#if HAS_HEATED_BED + else if (Heater == H_BED) { + currentTemperature = thermalManager.degBed(); + targetTemperature = thermalManager.degTargetBed(); + } +#endif // HAS_HEATED_BED +#if HAS_TEMP_CHAMBER + else if (Heater == H_CHAMBER) { + currentTemperature = thermalManager.degChamber(); + #if HAS_HEATED_CHAMBER + targetTemperature = thermalManager.degTargetChamber(); + #else + targetTemperature = ABSOLUTE_ZERO; + #endif + } +#endif // HAS_TEMP_CHAMBER else return; TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 64, 100, Heater)); @@ -148,17 +176,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { if (currentTemperature >= 50) Color = COLOR_HOTEND; } #if HAS_HEATED_BED - else if (Heater == H_BED) { - if (currentTemperature >= 50) Color = COLOR_HEATED_BED; - image = targetTemperature > 0 ? imgBedHeated : imgBed; - } - #endif + else if (Heater == H_BED) { + if (currentTemperature >= 50) Color = COLOR_HEATED_BED; + image = targetTemperature > 0 ? imgBedHeated : imgBed; + } + #endif // HAS_HEATED_BED #if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - if (currentTemperature >= 50) Color = COLOR_CHAMBER; - image = targetTemperature > 0 ? imgChamberHeated : imgChamber; - } - #endif + else if (Heater == H_CHAMBER) { + if (currentTemperature >= 50) Color = COLOR_CHAMBER; + image = targetTemperature > 0 ? imgChamberHeated : imgChamber; + } + #endif // HAS_TEMP_CHAMBER tft.add_image(0, 18, image, Color); @@ -172,6 +200,7 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { tft_string.add(LCD_STR_DEGREE); tft_string.trim(); tft.add_text(tft_string.center(64) + 2, 8, Color, tft_string); + } } @@ -203,7 +232,7 @@ void MarlinUI::draw_status_screen() { TERN_(TOUCH_SCREEN, touch.clear()); // heaters and fan - uint16_t i, x, y = TFT_STATUS_TOP_Y; + uint16_t i, x, y = POS_Y; for (i = 0 ; i < ITEMS_COUNT; i++) { x = (320 / ITEMS_COUNT - 64) / 2 + (320 * i / ITEMS_COUNT); @@ -312,6 +341,49 @@ void MarlinUI::draw_status_screen() { #endif } +// Draw a static item with no left-right margin required. Centered by default. +void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { + menu_item(row); + tft_string.set(pstr, itemIndex, itemString); + if (vstr) + tft_string.add(vstr); + tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); +} + +// Draw a generic menu item with pre_char (if selected) and post_char +void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) { + menu_item(row, sel); + + uint8_t *string = (uint8_t *)pstr; + MarlinImage image = noImage; + switch (*string) { + case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH + case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER + } + + uint8_t offset = MENU_TEXT_X_OFFSET; + if (image != noImage) { + string++; + offset = 32; + tft.add_image(0, 0, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + } + + tft_string.set(string, itemIndex, itemString); + tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); +} + +// Draw a menu item with a (potentially) editable value +void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) { + menu_item(row, sel); + + tft_string.set(pstr, itemIndex, itemString); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + if (data) { + tft_string.set(data); + tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + } +} + // Low-level draw_edit_screen can be used to draw an edit screen from anyplace void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { ui.encoder_direction_normal(); @@ -411,8 +483,16 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #endif } -#if ENABLED(ADVANCED_PAUSE_FEATURE) +#if ENABLED(SDSUPPORT) + void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) { + menu_item(row, sel); + if (isDir) + tft.add_image(0, 0, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + tft.add_text(32, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename()); + } +#endif +#if ENABLED(ADVANCED_PAUSE_FEATURE) void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) { #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -433,7 +513,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); } - #endif // ADVANCED_PAUSE_FEATURE #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -483,18 +562,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - constexpr uint8_t w = (TFT_WIDTH) / 10; - tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, w, 32); + + tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 32) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, 32, 32); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(x_plot)); tft_string.trim(); - tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, w, 32); + tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, 32, 32); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(y_plot)); tft_string.trim(); - tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -509,6 +588,104 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const } #endif // AUTO_BED_LEVELING_UBL +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + void MarlinUI::touch_calibration_screen() { + uint16_t x, y; + + calibrationState calibration_stage = touch_calibration.get_calibration_state(); + + if (calibration_stage == CALIBRATION_NONE) { + defer_status_screen(true); + clear_lcd(); + calibration_stage = touch_calibration.calibration_start(); + } + else { + x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; + y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; + tft.canvas(x - 15, y - 15, 31, 31); + tft.set_background(COLOR_BACKGROUND); + } + + touch.clear(); + + if (calibration_stage < CALIBRATION_SUCCESS) { + switch (calibration_stage) { + case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; + case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; + case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; + default: break; + } + + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + + tft.canvas(x - 15, y - 15, 31, 31); + tft.set_background(COLOR_BACKGROUND); + tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); + tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION); + + touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); + } + else { + tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); + defer_status_screen(false); + touch_calibration.calibration_end(); + touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); + } + + tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height()); + tft.set_background(COLOR_BACKGROUND); + tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); + } +#endif // TOUCH_SCREEN_CALIBRATION + +void menu_line(const uint8_t row, uint16_t color) { + tft.canvas(0, 2 + 34 * row, TFT_WIDTH, 32); + tft.set_background(color); +} + +void menu_pause_option(); + +void menu_item(const uint8_t row, bool sel ) { + #if ENABLED(TOUCH_SCREEN) + if (row == 0) { + touch.clear(); + draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true); + } + #endif + + menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + #if ENABLED(TOUCH_SCREEN) + const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; + touch.add_control(tct, 0, 2 + 34 * row, TFT_WIDTH, 32, encoderTopLine + row); + #endif +} + +void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { + #define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH)) + tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43); + tft.set_background(COLOR_BACKGROUND); +} + +int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { + tft_string.set(); + tft_string.add(c); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + return tft_string.width(); +} + +int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { + tft_string.set(utf8_str_P); + tft_string.trim(); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + return tft_string.width(); +} + +int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { + return lcd_put_u8str_max_P(utf8_str, max_length); +} + void MarlinUI::move_axis_screen() { } diff --git a/Marlin/src/lcd/tft/ui_320x240.h b/Marlin/src/lcd/tft/ui_320x240.h index 40b2185577b9..249a21c4f106 100644 --- a/Marlin/src/lcd/tft/ui_320x240.h +++ b/Marlin/src/lcd/tft/ui_320x240.h @@ -21,22 +21,88 @@ */ #pragma once -#define MARLIN_LOGO_FULL_SIZE MarlinLogo320x240x16 +#include "../../inc/MarlinConfigPre.h" -#define TFT_STATUS_TOP_Y 0 -#define TFT_TOP_LINE_Y 2 +#include "tft.h" +#include "tft_image.h" -#define MENU_TEXT_X_OFFSET 10 -#define MENU_TEXT_Y_OFFSET 7 +#if ENABLED(TOUCH_SCREEN) + #include "touch.h" +#endif -#define MENU_ITEM_ICON_X 0 -#define MENU_ITEM_ICON_Y 0 -#define MENU_ITEM_ICON_SPACE 32 +void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater); +void draw_fan_status(uint16_t x, uint16_t y, const bool blink); -#define MENU_ITEM_HEIGHT 32 -#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2) +#define MENU_TEXT_X_OFFSET 10 +#define MENU_TEXT_Y_OFFSET 7 +void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND); +void menu_item(const uint8_t row, bool sel = false); -#define MENU_FONT_NAME Helvetica14 -#define SYMBOLS_FONT_NAME Helvetica14_symbols +#define MENU_FONT_NAME Helvetica14 +#define SYMBOLS_FONT_NAME Helvetica14_symbols -#include "ui_common.h" +#define ABSOLUTE_ZERO -273.15 + +const tImage Images[imgCount] = { + TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo320x240x16), NoLogo), + HotEnd_64x64x4, + Bed_64x64x4, + Bed_Heated_64x64x4, + Chamber_64x64x4, + Chamber_Heated_64x64x4, + Fan0_64x64x4, + Fan_Slow0_64x64x4, + Fan_Slow1_64x64x4, + Fan_Fast0_64x64x4, + Fan_Fast1_64x64x4, + Feedrate_32x32x4, + Flowrate_32x32x4, + SD_64x64x4, + Menu_64x64x4, + Settings_64x64x4, + Directory_32x32x4, + Confirm_64x64x4, + Cancel_64x64x4, + Increase_64x64x4, + Decrease_64x64x4, + Back_32x32x4, + Up_32x32x4, + Down_32x32x4, + Left_32x32x4, + Right_32x32x4, + Refresh_32x32x4, + Leveling_32x32x4, + Slider8x16x4, + Home_64x64x4, + BtnRounded_64x52x4, +}; + +#if HAS_TEMP_CHAMBER && HOTENDS > 1 + #define ITEM_E0 0 + #define ITEM_E1 1 + #define ITEM_BED 2 + #define ITEM_CHAMBER 3 + #define ITEM_FAN 4 + #define ITEMS_COUNT 5 + #define POS_Y 0 +#elif HAS_TEMP_CHAMBER + #define ITEM_E0 0 + #define ITEM_BED 1 + #define ITEM_CHAMBER 2 + #define ITEM_FAN 3 + #define ITEMS_COUNT 4 + #define POS_Y 0 +#elif HOTENDS > 1 + #define ITEM_E0 0 + #define ITEM_E1 1 + #define ITEM_BED 2 + #define ITEM_FAN 3 + #define ITEMS_COUNT 4 + #define POS_Y 0 +#else + #define ITEM_E0 0 + #define ITEM_BED 1 + #define ITEM_FAN 2 + #define ITEMS_COUNT 3 + #define POS_Y 0 +#endif diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 5000aedc39a5..4165c3990c60 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -24,7 +24,7 @@ #if HAS_UI_480x320 || HAS_UI_480x272 -#include "ui_common.h" +#include "ui_480x320.h" #include "../marlinui.h" #include "../menu/menu.h" @@ -45,6 +45,14 @@ #include "../../feature/bedlevel/bedlevel.h" #endif +#if !HAS_LCD_MENU + #error "Seriously? High resolution TFT screen without menu?" +#endif + +#if ENABLED(TOUCH_SCREEN) + static bool draw_menu_navigation = false; +#endif + void MarlinUI::tft_idle() { #if ENABLED(TOUCH_SCREEN) if (draw_menu_navigation) { @@ -59,6 +67,28 @@ void MarlinUI::tft_idle() { TERN_(TOUCH_SCREEN, touch.idle()); } +void MarlinUI::init_lcd() { + tft.init(); + tft.set_font(MENU_FONT_NAME); + #ifdef SYMBOLS_FONT_NAME + tft.add_glyphs(SYMBOLS_FONT_NAME); + #endif + TERN_(TOUCH_SCREEN, touch.init()); + clear_lcd(); +} + +bool MarlinUI::detected() { return true; } + +void MarlinUI::clear_lcd() { + #if ENABLED(TOUCH_SCREEN) + touch.reset(); + draw_menu_navigation = false; + #endif + + tft.queue.reset(); + tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND); +} + #if ENABLED(SHOW_BOOTSCREEN) void MarlinUI::show_bootscreen() { tft.queue.reset(); @@ -70,8 +100,8 @@ void MarlinUI::tft_idle() { #define SITE_URL_Y (TFT_HEIGHT - 70) tft.set_background(COLOR_BACKGROUND); #else - #define BOOT_LOGO_W TFT_WIDTH // MarlinLogo480x320x16 - #define BOOT_LOGO_H TFT_HEIGHT + #define BOOT_LOGO_W 480 // MarlinLogo480x320x16 + #define BOOT_LOGO_H 320 #define SITE_URL_Y (TFT_HEIGHT - 90) #endif tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen); @@ -120,22 +150,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { currentTemperature = thermalManager.degHotend(Heater); targetTemperature = thermalManager.degTargetHotend(Heater); } - #if HAS_HEATED_BED - else if (Heater == H_BED) { - currentTemperature = thermalManager.degBed(); - targetTemperature = thermalManager.degTargetBed(); - } - #endif - #if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - currentTemperature = thermalManager.degChamber(); - #if HAS_HEATED_CHAMBER - targetTemperature = thermalManager.degTargetChamber(); - #else - targetTemperature = ABSOLUTE_ZERO; - #endif - } - #endif +#if HAS_HEATED_BED + else if (Heater == H_BED) { + currentTemperature = thermalManager.degBed(); + targetTemperature = thermalManager.degTargetBed(); + } +#endif // HAS_HEATED_BED +#if HAS_TEMP_CHAMBER + else if (Heater == H_CHAMBER) { + currentTemperature = thermalManager.degChamber(); + #if HAS_HEATED_CHAMBER + targetTemperature = thermalManager.degTargetChamber(); + #else + targetTemperature = ABSOLUTE_ZERO; + #endif + } +#endif // HAS_TEMP_CHAMBER else return; TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 80, 120, Heater)); @@ -148,17 +178,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { if (currentTemperature >= 50) Color = COLOR_HOTEND; } #if HAS_HEATED_BED - else if (Heater == H_BED) { - if (currentTemperature >= 50) Color = COLOR_HEATED_BED; - image = targetTemperature > 0 ? imgBedHeated : imgBed; - } - #endif + else if (Heater == H_BED) { + if (currentTemperature >= 50) Color = COLOR_HEATED_BED; + image = targetTemperature > 0 ? imgBedHeated : imgBed; + } + #endif // HAS_HEATED_BED #if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - if (currentTemperature >= 50) Color = COLOR_CHAMBER; - image = targetTemperature > 0 ? imgChamberHeated : imgChamber; - } - #endif + else if (Heater == H_CHAMBER) { + if (currentTemperature >= 50) Color = COLOR_CHAMBER; + image = targetTemperature > 0 ? imgChamberHeated : imgChamber; + } + #endif // HAS_TEMP_CHAMBER tft.add_image(8, 28, image, Color); @@ -203,7 +233,7 @@ void MarlinUI::draw_status_screen() { TERN_(TOUCH_SCREEN, touch.clear()); // heaters and fan - uint16_t i, x, y = TFT_STATUS_TOP_Y; + uint16_t i, x, y = POS_Y; for (i = 0 ; i < ITEMS_COUNT; i++) { x = (TFT_WIDTH / ITEMS_COUNT - 80) / 2 + (TFT_WIDTH * i / ITEMS_COUNT); @@ -319,6 +349,49 @@ void MarlinUI::draw_status_screen() { tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string); } +// Draw a static item with no left-right margin required. Centered by default. +void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { + menu_item(row); + tft_string.set(pstr, itemIndex, itemString); + if (vstr) + tft_string.add(vstr); + tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); +} + +// Draw a generic menu item with pre_char (if selected) and post_char +void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) { + menu_item(row, sel); + + uint8_t *string = (uint8_t *)pstr; + MarlinImage image = noImage; + switch (*string) { + case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH + case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER + } + + uint8_t offset = MENU_TEXT_X_OFFSET; + if (image != noImage) { + string++; + offset = 42; + tft.add_image(5, 5, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + } + + tft_string.set(string, itemIndex, itemString); + tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); +} + +// Draw a menu item with a (potentially) editable value +void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) { + menu_item(row, sel); + + tft_string.set(pstr, itemIndex, itemString); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + if (data) { + tft_string.set(data); + tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + } +} + // Low-level draw_edit_screen can be used to draw an edit screen from anyplace void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { ui.encoder_direction_normal(); @@ -418,8 +491,16 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #endif } -#if ENABLED(ADVANCED_PAUSE_FEATURE) +#if ENABLED(SDSUPPORT) + void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) { + menu_item(row, sel); + if (isDir) + tft.add_image(5, 5, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + tft.add_text(42, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename()); + } +#endif +#if ENABLED(ADVANCED_PAUSE_FEATURE) void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) { #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -440,7 +521,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); } - #endif // ADVANCED_PAUSE_FEATURE #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -490,18 +570,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - constexpr uint8_t w = (TFT_WIDTH) / 10; - tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, w, MENU_ITEM_HEIGHT); + + tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, MENU_ITEM_HEIGHT); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(x_plot)); tft_string.trim(); - tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, w, MENU_ITEM_HEIGHT); + tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 48, MENU_ITEM_HEIGHT); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(y_plot)); tft_string.trim(); - tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -516,6 +596,97 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const } #endif // AUTO_BED_LEVELING_UBL +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + void MarlinUI::touch_calibration_screen() { + uint16_t x, y; + + calibrationState calibration_stage = touch_calibration.get_calibration_state(); + + if (calibration_stage == CALIBRATION_NONE) { + defer_status_screen(true); + clear_lcd(); + calibration_stage = touch_calibration.calibration_start(); + } + else { + x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; + y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; + tft.canvas(x - 15, y - 15, 31, 31); + tft.set_background(COLOR_BACKGROUND); + } + + touch.clear(); + + if (calibration_stage < CALIBRATION_SUCCESS) { + switch (calibration_stage) { + case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; + case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; + case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; + default: break; + } + + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + + tft.canvas(x - 15, y - 15, 31, 31); + tft.set_background(COLOR_BACKGROUND); + tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); + tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION); + + touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); + } + else { + tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); + defer_status_screen(false); + touch_calibration.calibration_end(); + touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); + } + + tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height()); + tft.set_background(COLOR_BACKGROUND); + tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); + } +#endif // TOUCH_SCREEN_CALIBRATION + +void menu_line(const uint8_t row, uint16_t color) { + tft.canvas(0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT); + tft.set_background(color); +} + +void menu_pause_option(); + +void menu_item(const uint8_t row, bool sel ) { + #if ENABLED(TOUCH_SCREEN) + if (row == 0) { + touch.clear(); + draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true); + } + #endif + + menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + #if ENABLED(TOUCH_SCREEN) + const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; + touch.add_control(tct, 0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row); + #endif +} + +void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { + #define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH)) + tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43); + tft.set_background(COLOR_BACKGROUND); +} + +int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { + tft_string.set(utf8_str_P); + tft_string.trim(); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + return tft_string.width(); +} + +int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { + return lcd_put_u8str_max_P(utf8_str, max_length); +} + #if ENABLED(BABYSTEP_ZPROBE_OFFSET) #include "../../feature/babystep.h" #endif @@ -718,14 +889,37 @@ static void moveAxis(AxisEnum axis, const int8_t direction) { drawAxisValue(axis); } -static void e_plus() { moveAxis(E_AXIS, 1); } -static void e_minus() { moveAxis(E_AXIS, -1); } -static void x_minus() { moveAxis(X_AXIS, -1); } -static void x_plus() { moveAxis(X_AXIS, 1); } -static void y_plus() { moveAxis(Y_AXIS, 1); } -static void y_minus() { moveAxis(Y_AXIS, -1); } -static void z_plus() { moveAxis(Z_AXIS, 1); } -static void z_minus() { moveAxis(Z_AXIS, -1); } +static void e_plus() { + moveAxis(E_AXIS, 1); +} + +static void e_minus() { + moveAxis(E_AXIS, -1); +} + +static void x_minus() { + moveAxis(X_AXIS, -1); +} + +static void x_plus() { + moveAxis(X_AXIS, 1); +} + +static void y_plus() { + moveAxis(Y_AXIS, 1); +} + +static void y_minus() { + moveAxis(Y_AXIS, -1); +} + +static void z_plus() { + moveAxis(Z_AXIS, 1); +} + +static void z_minus() { + moveAxis(Z_AXIS, -1); +} #if ENABLED(TOUCH_SCREEN) static void e_select() { @@ -808,9 +1002,8 @@ void MarlinUI::move_axis_screen() { const bool busy = printingIsActive(); - // Babysteps during printing? Select babystep for Z probe offset - if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) - motionAxisState.z_selection = Z_SELECTION_Z_PROBE; + // if we have baby step and we are printing, select baby step + if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) motionAxisState.z_selection = Z_SELECTION_Z_PROBE; // ROW 1 -> E- Y- CurY Z+ int x = X_MARGIN, y = Y_MARGIN, spacing = 0; @@ -896,7 +1089,7 @@ void MarlinUI::move_axis_screen() { TERN_(HAS_TFT_XPT2046, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size)); } - // aligned with x+ + // alinged with x+ drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy); TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack)); diff --git a/Marlin/src/lcd/tft/ui_480x320.h b/Marlin/src/lcd/tft/ui_480x320.h index fca9ed9c2a22..e3a688f112b1 100644 --- a/Marlin/src/lcd/tft/ui_480x320.h +++ b/Marlin/src/lcd/tft/ui_480x320.h @@ -21,29 +21,97 @@ */ #pragma once -#define MARLIN_LOGO_FULL_SIZE MarlinLogo480x320x16 +#include "../../inc/MarlinConfigPre.h" -#include "ui_common.h" +#include "tft.h" +#include "tft_image.h" -#define TFT_STATUS_TOP_Y 4 -#define TFT_TOP_LINE_Y 4 +#if ENABLED(TOUCH_SCREEN) + #include "touch.h" +#endif -#define MENU_TEXT_X_OFFSET 16 -#define MENU_TEXT_Y_OFFSET 7 +void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater); +void draw_fan_status(uint16_t x, uint16_t y, const bool blink); -#define MENU_ITEM_ICON_X 5 -#define MENU_ITEM_ICON_Y 5 -#define MENU_ITEM_ICON_SPACE 42 +#define MENU_TEXT_X_OFFSET 16 +#define MENU_TEXT_Y_OFFSET 7 +void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND); +void menu_item(const uint8_t row, bool sel = false); #if HAS_UI_480x320 - #define MENU_FONT_NAME Helvetica18 - #define SYMBOLS_FONT_NAME Helvetica18_symbols - #define MENU_ITEM_HEIGHT 43 - #define FONT_LINE_HEIGHT 34 + #define MENU_FONT_NAME Helvetica18 + #define SYMBOLS_FONT_NAME Helvetica18_symbols + #define MENU_ITEM_HEIGHT 43 + #define FONT_LINE_HEIGHT 34 #elif HAS_UI_480x272 - #define MENU_FONT_NAME Helvetica14 - #define SYMBOLS_FONT_NAME Helvetica14_symbols - #define MENU_ITEM_HEIGHT 36 - #define FONT_LINE_HEIGHT 24 + #define MENU_FONT_NAME Helvetica14 + #define SYMBOLS_FONT_NAME Helvetica14_symbols + #define MENU_ITEM_HEIGHT 36 + #define FONT_LINE_HEIGHT 24 +#endif + +#define ABSOLUTE_ZERO -273.15 + +const tImage Images[imgCount] = { + TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo480x320x16), NoLogo), + HotEnd_64x64x4, + Bed_64x64x4, + Bed_Heated_64x64x4, + Chamber_64x64x4, + Chamber_Heated_64x64x4, + Fan0_64x64x4, + Fan_Slow0_64x64x4, + Fan_Slow1_64x64x4, + Fan_Fast0_64x64x4, + Fan_Fast1_64x64x4, + Feedrate_32x32x4, + Flowrate_32x32x4, + SD_64x64x4, + Menu_64x64x4, + Settings_64x64x4, + Directory_32x32x4, + Confirm_64x64x4, + Cancel_64x64x4, + Increase_64x64x4, + Decrease_64x64x4, + Back_32x32x4, + Up_32x32x4, + Down_32x32x4, + Left_32x32x4, + Right_32x32x4, + Refresh_32x32x4, + Leveling_32x32x4, + Slider8x16x4, + Home_64x64x4, + BtnRounded_64x52x4, +}; + +#if HAS_TEMP_CHAMBER && HOTENDS > 1 + #define ITEM_E0 0 + #define ITEM_E1 1 + #define ITEM_BED 2 + #define ITEM_CHAMBER 3 + #define ITEM_FAN 4 + #define ITEMS_COUNT 5 + #define POS_Y 4 +#elif HAS_TEMP_CHAMBER + #define ITEM_E0 0 + #define ITEM_BED 1 + #define ITEM_CHAMBER 2 + #define ITEM_FAN 3 + #define ITEMS_COUNT 4 + #define POS_Y 4 +#elif HOTENDS > 1 + #define ITEM_E0 0 + #define ITEM_E1 1 + #define ITEM_BED 2 + #define ITEM_FAN 3 + #define ITEMS_COUNT 4 + #define POS_Y 4 +#else + #define ITEM_E0 0 + #define ITEM_BED 1 + #define ITEM_FAN 2 + #define ITEMS_COUNT 3 + #define POS_Y 4 #endif -#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2) diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp deleted file mode 100644 index 842fc3909c2a..000000000000 --- a/Marlin/src/lcd/tft/ui_common.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -#include "../../inc/MarlinConfigPre.h" - -#if HAS_GRAPHICAL_TFT - -#include "ui_common.h" -#include "../lcdprint.h" -#include "../../libs/numtostr.h" -#include "../menu/menu.h" - -void menu_pause_option(); - -static xy_uint_t cursor; - -#if ENABLED(TOUCH_SCREEN) - bool draw_menu_navigation = false; -#endif - -void menu_line(const uint8_t row, uint16_t color) { - cursor.set(0, row); - tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT); - tft.set_background(color); -} - -void menu_item(const uint8_t row, bool sel ) { - #if ENABLED(TOUCH_SCREEN) - if (row == 0) { - touch.clear(); - draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true); - } - #endif - - menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - #if ENABLED(TOUCH_SCREEN) - const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; - touch.add_control(tct, 0, TFT_TOP_LINE_Y + row * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row); - #endif -} - -// -// lcdprint.h functions -// - -#define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH)) - -void lcd_gotopixel(const uint16_t x, const uint16_t y) { - if (x >= TFT_WIDTH) return; - cursor.set(x / (TFT_COL_WIDTH), y / MENU_LINE_HEIGHT); - tft.canvas(x, TFT_TOP_LINE_Y + y, (TFT_WIDTH) - x, MENU_ITEM_HEIGHT); - tft.set_background(COLOR_BACKGROUND); -} - -void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { - lcd_gotopixel(int(col) * (TFT_COL_WIDTH), int(row) * MENU_LINE_HEIGHT); -} - -int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { - if (max_length < 1) return 0; - tft_string.set(); - tft_string.add(c); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT); - return tft_string.width(); -} - -int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { - if (max_length < 1) return 0; - tft_string.set(utf8_str_P); - tft_string.trim(); - tft_string.truncate(max_length); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT); - return tft_string.width(); -} - -int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { - return lcd_put_u8str_max_P(utf8_str, max_length); -} - -void lcd_put_int(const int i) { - // 3 digits max for this one... - const char* str = i16tostr3left(int16_t(i)); - lcd_put_u8str_max(str, 3); -} - -// -// Menu Item methods -// - -// Draw a generic menu item with pre_char (if selected) and post_char -void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) { - menu_item(row, sel); - - uint8_t *string = (uint8_t *)pstr; - MarlinImage image = noImage; - switch (*string) { - case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH - case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER - } - - uint8_t offset = MENU_TEXT_X_OFFSET; - if (image != noImage) { - string++; - offset = MENU_ITEM_ICON_SPACE; - tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - } - - tft_string.set(string, itemIndex, itemString); - tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); -} - -// Draw a menu item with a (potentially) editable value -void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) { - menu_item(row, sel); - - tft_string.set(pstr, itemIndex, itemString); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - if (data) { - tft_string.set(data); - tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - } -} - -// Draw a static item with no left-right margin required. Centered by default. -void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { - menu_item(row); - tft_string.set(pstr, itemIndex, itemString); - if (vstr) - tft_string.add(vstr); - tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); -} - -#if ENABLED(SDSUPPORT) - - void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) { - menu_item(row, sel); - if (isDir) - tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename()); - } - -#endif - -// -// MarlinUI methods -// - -bool MarlinUI::detected() { return true; } - -void MarlinUI::init_lcd() { - tft.init(); - tft.set_font(MENU_FONT_NAME); - #ifdef SYMBOLS_FONT_NAME - tft.add_glyphs(SYMBOLS_FONT_NAME); - #endif - TERN_(TOUCH_SCREEN, touch.init()); - clear_lcd(); -} - -void MarlinUI::clear_lcd() { - #if ENABLED(TOUCH_SCREEN) - touch.reset(); - draw_menu_navigation = false; - #endif - - tft.queue.reset(); - tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND); - cursor.set(0, 0); -} - -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - - void MarlinUI::touch_calibration_screen() { - uint16_t x, y; - - calibrationState calibration_stage = touch_calibration.get_calibration_state(); - - if (calibration_stage == CALIBRATION_NONE) { - defer_status_screen(true); - clear_lcd(); - calibration_stage = touch_calibration.calibration_start(); - } - else { - x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; - y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; - tft.canvas(x - 15, y - 15, 31, 31); - tft.set_background(COLOR_BACKGROUND); - } - - touch.clear(); - - if (calibration_stage < CALIBRATION_SUCCESS) { - switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; - case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; - case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; - case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; - default: break; - } - - x = touch_calibration.calibration_points[calibration_stage].x; - y = touch_calibration.calibration_points[calibration_stage].y; - - tft.canvas(x - 15, y - 15, 31, 31); - tft.set_background(COLOR_BACKGROUND); - tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); - tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION); - - touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); - } - else { - tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); - defer_status_screen(false); - touch_calibration.calibration_end(); - touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); - } - - tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height()); - tft.set_background(COLOR_BACKGROUND); - tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); - } - -#endif // TOUCH_SCREEN_CALIBRATION - -#endif // HAS_GRAPHICAL_TFT diff --git a/Marlin/src/lcd/tft/ui_common.h b/Marlin/src/lcd/tft/ui_common.h deleted file mode 100644 index d40e471171b3..000000000000 --- a/Marlin/src/lcd/tft/ui_common.h +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ -#pragma once - -#include "../../inc/MarlinConfigPre.h" - -#if !HAS_LCD_MENU - #error "Seriously? High resolution TFT screen without menu?" -#endif - -#include "tft.h" -#include "tft_image.h" - -#if ENABLED(TOUCH_SCREEN) - #include "touch.h" - extern bool draw_menu_navigation; -#endif - -#if HAS_UI_320x240 - #include "ui_320x240.h" -#elif HAS_UI_480x320 || HAS_UI_480x272 - #include "ui_480x320.h" -#endif - -void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater); -void draw_fan_status(uint16_t x, uint16_t y, const bool blink); - -void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND); -void menu_item(const uint8_t row, bool sel = false); - -#define ABSOLUTE_ZERO -273.15 - -#if HAS_TEMP_CHAMBER && HOTENDS > 1 - #define ITEM_E0 0 - #define ITEM_E1 1 - #define ITEM_BED 2 - #define ITEM_CHAMBER 3 - #define ITEM_FAN 4 - #define ITEMS_COUNT 5 -#elif HAS_TEMP_CHAMBER - #define ITEM_E0 0 - #define ITEM_BED 1 - #define ITEM_CHAMBER 2 - #define ITEM_FAN 3 - #define ITEMS_COUNT 4 -#elif HOTENDS > 1 - #define ITEM_E0 0 - #define ITEM_E1 1 - #define ITEM_BED 2 - #define ITEM_FAN 3 - #define ITEMS_COUNT 4 -#else - #define ITEM_E0 0 - #define ITEM_BED 1 - #define ITEM_FAN 2 - #define ITEMS_COUNT 3 -#endif diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 45072c8f0189..20bf175e7815 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -41,10 +41,6 @@ Stopwatch print_job_timer; // Global Print Job Timer instance #include "../libs/buzzer.h" #endif -#if PRINTCOUNTER_SYNC - #include "../module/planner.h" -#endif - // Service intervals #if HAS_SERVICE_INTERVALS #if SERVICE_INTERVAL_1 > 0 @@ -164,8 +160,6 @@ void PrintCounter::saveStats() { // Refuses to save data if object is not loaded if (!isLoaded()) return; - TERN_(PRINTCOUNTER_SYNC, planner.synchronize()); - // Saves the struct to EEPROM persistentStore.access_start(); persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics)); @@ -230,12 +224,9 @@ void PrintCounter::tick() { millis_t now = millis(); - static millis_t update_next; // = 0 + static uint32_t update_next; // = 0 if (ELAPSED(now, update_next)) { - update_next = now + updateInterval; - TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("tick"))); - millis_t delta = deltaDuration(); data.printTime += delta; @@ -248,12 +239,16 @@ void PrintCounter::tick() { #if SERVICE_INTERVAL_3 > 0 data.nextService3 -= _MIN(delta, data.nextService3); #endif + + update_next = now + updateInterval * 1000; } - #if PRINTCOUNTER_SAVE_INTERVAL > 0 - static millis_t eeprom_next; // = 0 + // LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) + // TODO: Which other boards are incompatible? + #ifndef MCU_LPC1768 + static uint32_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { - eeprom_next = now + saveInterval; + eeprom_next = now + saveInterval * 1000; saveStats(); } #endif diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 4deae45a656d..0d75e6e3f7a1 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -71,18 +71,19 @@ class PrintCounter: public Stopwatch { * @brief Interval in seconds between counter updates * @details This const value defines what will be the time between each * accumulator update. This is different from the EEPROM save interval. + * + * @note The max value for this option is 60(s), otherwise integer + * overflow will happen. */ - static constexpr millis_t updateInterval = SEC_TO_MS(10); + static constexpr uint16_t updateInterval = 10; - #if PRINTCOUNTER_SAVE_INTERVAL > 0 - /** - * @brief Interval in seconds between EEPROM saves - * @details This const value defines what will be the time between each - * EEPROM save cycle, the development team recommends to set this value - * no lower than 3600 secs (1 hour). - */ - static constexpr millis_t saveInterval = MIN_TO_MS(PRINTCOUNTER_SAVE_INTERVAL); - #endif + /** + * @brief Interval in seconds between EEPROM saves + * @details This const value defines what will be the time between each + * EEPROM save cycle, the development team recommends to set this value + * no lower than 3600 secs (1 hour). + */ + static constexpr uint16_t saveInterval = 3600; /** * @brief Timestamp of the last call to deltaDuration() diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 867ae5d9271d..052b8cd34a64 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -828,7 +828,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a // Cool down with fan #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed; - gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time)); + gcode.dwell(toolchange_settings.fan_time * 1000); thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0; #endif @@ -1102,7 +1102,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Cool down with fan #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed; - gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time)); + gcode.dwell(toolchange_settings.fan_time * 1000); thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0; #endif } diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 4500f529a66b..4b8c339d460d 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -83,7 +83,7 @@ def add_to_feat_cnf(feature, flines): feat[name] = '='.join(parts) else: for dep in line.split(','): - lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0) + lib_name = re.sub(r'([@~^=]|[<>]=?)[\d.]+', '', dep.strip()).split('=').pop(0) lib_re = re.compile('(?!^' + lib_name + '\\b)') feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep] From 051944ffe80c57b1d3398c7c816015b0a4d76676 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 26 Jan 2021 02:18:12 -0600 Subject: [PATCH 16/18] Update Configuration.h --- Marlin/Configuration.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 08c377755085..d888e62aaf46 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -421,7 +421,7 @@ #define TEMP_SENSOR_CHAMBER 0 // Dummy thermistor constant temperature readings, for use with 998 and 999 -#define DUMMY_THERMISTOR_998_VALUE 25 +#define DUMMY_THERMISTOR_998_VALUE 25 #define DUMMY_THERMISTOR_999_VALUE 100 // Resistor values when using MAX31865 sensors (-5) on TEMP_SENSOR_0 / 1 @@ -1754,6 +1754,9 @@ * View the current statistics with M78. */ //#define PRINTCOUNTER +#if ENABLED(PRINTCOUNTER) + #define PRINTCOUNTER_SAVE_INTERVAL 60 // (minutes) EEPROM save interval during print +#endif /** * Password From 6b9482dea6e67baf5bd38d10046d477fb2d7c8d3 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 26 Jan 2021 02:19:10 -0600 Subject: [PATCH 17/18] fix spacing --- Marlin/Configuration_adv.h | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 604bbb9359b6..bcd1d6242290 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -163,7 +163,7 @@ #if ENABLED(CHAMBER_VENT) #define CHAMBER_VENT_SERVO_NR 1 // Index of the vent servo #define HIGH_EXCESS_HEAT_LIMIT 5 // How much above target temp to consider there is excess heat in the chamber - #define LOW_EXCESS_HEAT_LIMIT 3 + #define LOW_EXCESS_HEAT_LIMIT 3 #define MIN_COOLING_SLOPE_TIME_CHAMBER_VENT 20 #define MIN_COOLING_SLOPE_DEG_CHAMBER_VENT 1.5 #endif @@ -206,7 +206,7 @@ * and/or decrease WATCH_TEMP_INCREASE. WATCH_TEMP_INCREASE should not be set * below 2. */ - #define WATCH_TEMP_PERIOD 20 // Seconds + #define WATCH_TEMP_PERIOD 20 // Seconds #define WATCH_TEMP_INCREASE 2 // Degrees Celsius #endif @@ -284,8 +284,8 @@ // DEFAULT_Kf and PID_FAN_SCALING_LIN_FACTOR are calculated accordingly. #define PID_FAN_SCALING_AT_FULL_SPEED 13.0 //=PID_FAN_SCALING_LIN_FACTOR*255+DEFAULT_Kf - #define PID_FAN_SCALING_AT_MIN_SPEED 6.0 //=PID_FAN_SCALING_LIN_FACTOR*PID_FAN_SCALING_MIN_SPEED+DEFAULT_Kf - #define PID_FAN_SCALING_MIN_SPEED 10.0 // Minimum fan speed at which to enable PID_FAN_SCALING + #define PID_FAN_SCALING_AT_MIN_SPEED 6.0 //=PID_FAN_SCALING_LIN_FACTOR*PID_FAN_SCALING_MIN_SPEED+DEFAULT_Kf + #define PID_FAN_SCALING_MIN_SPEED 10.0 // Minimum fan speed at which to enable PID_FAN_SCALING #define DEFAULT_Kf (255.0*PID_FAN_SCALING_AT_MIN_SPEED-PID_FAN_SCALING_AT_FULL_SPEED*PID_FAN_SCALING_MIN_SPEED)/(255.0-PID_FAN_SCALING_MIN_SPEED) #define PID_FAN_SCALING_LIN_FACTOR (PID_FAN_SCALING_AT_FULL_SPEED-DEFAULT_Kf)/255.0 @@ -2056,21 +2056,21 @@ */ //#define FWRETRACT #if ENABLED(FWRETRACT) - #define FWRETRACT_AUTORETRACT // Override slicer retractions + #define FWRETRACT_AUTORETRACT // Override slicer retractions #if ENABLED(FWRETRACT_AUTORETRACT) - #define MIN_AUTORETRACT 0.1 // (mm) Don't convert E moves under this length - #define MAX_AUTORETRACT 10.0 // (mm) Don't convert E moves over this length - #endif - #define RETRACT_LENGTH 3 // (mm) Default retract length (positive value) - #define RETRACT_LENGTH_SWAP 13 // (mm) Default swap retract length (positive value) - #define RETRACT_FEEDRATE 45 // (mm/s) Default feedrate for retracting - #define RETRACT_ZRAISE 0 // (mm) Default retract Z-raise - #define RETRACT_RECOVER_LENGTH 0 // (mm) Default additional recover length (added to retract length on recover) - #define RETRACT_RECOVER_LENGTH_SWAP 0 // (mm) Default additional swap recover length (added to retract length on recover from toolchange) - #define RETRACT_RECOVER_FEEDRATE 8 // (mm/s) Default feedrate for recovering from retraction - #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // (mm/s) Default feedrate for recovering from swap retraction + #define MIN_AUTORETRACT 0.1 // (mm) Don't convert E moves under this length + #define MAX_AUTORETRACT 10.0 // (mm) Don't convert E moves over this length + #endif + #define RETRACT_LENGTH 3 // (mm) Default retract length (positive value) + #define RETRACT_LENGTH_SWAP 13 // (mm) Default swap retract length (positive value) + #define RETRACT_FEEDRATE 45 // (mm/s) Default feedrate for retracting + #define RETRACT_ZRAISE 0 // (mm) Default retract Z-raise + #define RETRACT_RECOVER_LENGTH 0 // (mm) Default additional recover length (added to retract length on recover) + #define RETRACT_RECOVER_LENGTH_SWAP 0 // (mm) Default additional swap recover length (added to retract length on recover from toolchange) + #define RETRACT_RECOVER_FEEDRATE 8 // (mm/s) Default feedrate for recovering from retraction + #define RETRACT_RECOVER_FEEDRATE_SWAP 8 // (mm/s) Default feedrate for recovering from swap retraction #if ENABLED(MIXING_EXTRUDER) - //#define RETRACT_SYNC_MIXING // Retract and restore all mixing steppers simultaneously + //#define RETRACT_SYNC_MIXING // Retract and restore all mixing steppers simultaneously #endif #endif From 112568aeaf146a9fb5f87f2a697906909955f843 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Tue, 26 Jan 2021 02:24:51 -0600 Subject: [PATCH 18/18] Get back to known good state --- .../src/HAL/LPC1768/inc/Conditionals_post.h | 7 + Marlin/src/MarlinCore.cpp | 24 +- Marlin/src/gcode/control/M80_M81.cpp | 2 +- Marlin/src/gcode/feature/L6470/M916-918.cpp | 2 +- Marlin/src/gcode/parser.h | 2 +- Marlin/src/inc/Conditionals_LCD.h | 43 +-- Marlin/src/inc/SanityCheck.h | 2 - Marlin/src/lcd/dogm/dogm_Statusscreen.h | 2 +- Marlin/src/lcd/dogm/status_screen_DOGM.cpp | 4 + Marlin/src/lcd/dwin/e3v2/dwin.cpp | 63 ++-- Marlin/src/lcd/marlinui.cpp | 1 + Marlin/src/lcd/menu/menu_bed_corners.cpp | 8 +- Marlin/src/lcd/menu/menu_tune.cpp | 13 +- Marlin/src/lcd/tft/tft_image.cpp | 41 ++- Marlin/src/lcd/tft/tft_image.h | 3 +- Marlin/src/lcd/tft/tft_string.cpp | 7 +- Marlin/src/lcd/tft/tft_string.h | 7 +- Marlin/src/lcd/tft/ui_320x240.cpp | 251 +++------------ Marlin/src/lcd/tft/ui_320x240.h | 92 +----- Marlin/src/lcd/tft/ui_480x320.cpp | 291 +++--------------- Marlin/src/lcd/tft/ui_480x320.h | 104 ++----- Marlin/src/lcd/tft/ui_common.cpp | 246 +++++++++++++++ Marlin/src/lcd/tft/ui_common.h | 76 +++++ Marlin/src/module/endstops.cpp | 2 +- Marlin/src/module/printcounter.cpp | 21 +- Marlin/src/module/printcounter.h | 21 +- Marlin/src/module/tool_change.cpp | 4 +- .../PlatformIO/scripts/common-dependencies.py | 2 +- 28 files changed, 611 insertions(+), 730 deletions(-) create mode 100644 Marlin/src/lcd/tft/ui_common.cpp create mode 100644 Marlin/src/lcd/tft/ui_common.h diff --git a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h index ce6d3fdde27f..94e4ce134170 100644 --- a/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h +++ b/Marlin/src/HAL/LPC1768/inc/Conditionals_post.h @@ -26,3 +26,10 @@ #elif EITHER(I2C_EEPROM, SPI_EEPROM) #define USE_SHARED_EEPROM 1 #endif + +// LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) +// TODO: Which other boards are incompatible? +#if defined(MCU_LPC1768) && PRINTCOUNTER_SAVE_INTERVAL > 0 + #warning "To prevent step loss, motion will pause for PRINTCOUNTER auto-save." + #define PRINTCOUNTER_SYNC 1 +#endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 34a0ba8906ed..4b6c281de2ed 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -362,25 +362,24 @@ void startOrResumeJob() { inline void abortSDPrinting() { IF_DISABLED(NO_SD_AUTOSTART, card.autofile_cancel()); card.endFilePrint(TERN_(SD_RESORT, true)); + queue.clear(); quickstop_stepper(); - #if DISABLED(SD_ABORT_NO_COOLDOWN) - thermalManager.disable_all_heaters(); - #endif - #if !HAS_CUTTER - thermalManager.zero_fan_speeds(); - #else - cutter.kill(); // Full cutter shutdown including ISR control - #endif + + print_job_timer.abort(); + + IF_DISABLED(SD_ABORT_NO_COOLDOWN, thermalManager.disable_all_heaters()); + + TERN(HAS_CUTTER, cutter.kill(), thermalManager.zero_fan_speeds()); // Full cutter shutdown including ISR control + wait_for_heatup = false; + TERN_(POWER_LOSS_RECOVERY, recovery.purge()); + #ifdef EVENT_GCODE_SD_ABORT queue.inject_P(PSTR(EVENT_GCODE_SD_ABORT)); #endif - planner.synchronize(); - print_job_timer.abort(); // Wait for planner before calling! - TERN_(PASSWORD_AFTER_SD_PRINT_ABORT, password.lock_machine()); } @@ -786,8 +785,7 @@ void minkill(const bool steppers_off/*=false*/) { void stop() { thermalManager.disable_all_heaters(); // 'unpause' taken care of in here - planner.synchronize(); - print_job_timer.stop(); // Wait for planner before calling! + print_job_timer.stop(); #if ENABLED(PROBING_FANS_OFF) if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index cd5a92d7b31e..394b06d8ac30 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -91,7 +91,7 @@ void GcodeSuite::M81() { thermalManager.disable_all_heaters(); planner.finish_and_disable(); - print_job_timer.stop(); // Wait for planner before calling! + print_job_timer.stop(); #if HAS_FAN thermalManager.zero_fan_speeds(); diff --git a/Marlin/src/gcode/feature/L6470/M916-918.cpp b/Marlin/src/gcode/feature/L6470/M916-918.cpp index 2672f9123987..8a1ea4830606 100644 --- a/Marlin/src/gcode/feature/L6470/M916-918.cpp +++ b/Marlin/src/gcode/feature/L6470/M916-918.cpp @@ -119,7 +119,7 @@ void GcodeSuite::M916() { M91x_counter_max = 256; // KVAL_HOLD is 8 bits uint8_t M91x_delay_s = parser.byteval('D'); // get delay in seconds - millis_t M91x_delay_ms = M91x_delay_s * 60 * 1000; + millis_t M91x_delay_ms = SEC_TO_MS(M91x_delay_s * 60); millis_t M91x_delay_end; DEBUG_ECHOLNPGM(".\n."); diff --git a/Marlin/src/gcode/parser.h b/Marlin/src/gcode/parser.h index 8633d2b1e9db..cf531c4e4705 100644 --- a/Marlin/src/gcode/parser.h +++ b/Marlin/src/gcode/parser.h @@ -282,7 +282,7 @@ class GCodeParser { // Code value for use as time static inline millis_t value_millis() { return value_ulong(); } - static inline millis_t value_millis_from_seconds() { return (millis_t)(value_float() * 1000); } + static inline millis_t value_millis_from_seconds() { return (millis_t)SEC_TO_MS(value_float()); } // Reduce to fewer bits static inline int16_t value_int() { return (int16_t)value_long(); } diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index a5bb24f27c41..2acda7bd5937 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -1155,36 +1155,37 @@ #endif #endif -#if ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 240 - #if ENABLED(TFT_INTERFACE_SPI) - #define TFT_320x240_SPI - #elif ENABLED(TFT_INTERFACE_FSMC) - #define TFT_320x240 - #endif -#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 320 - #if ENABLED(TFT_INTERFACE_SPI) - #define TFT_480x320_SPI - #elif ENABLED(TFT_INTERFACE_FSMC) - #define TFT_480x320 - #endif -#elif ENABLED(TFT_COLOR_UI) && TFT_HEIGHT == 272 - #if ENABLED(TFT_INTERFACE_SPI) - #define TFT_480x272_SPI - #elif ENABLED(TFT_INTERFACE_FSMC) - #define TFT_480x272 +#if ENABLED(TFT_COLOR_UI) + #if TFT_HEIGHT == 240 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_320x240_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_320x240 + #endif + #elif TFT_HEIGHT == 320 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_480x320_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_480x320 + #endif + #elif TFT_HEIGHT == 272 + #if ENABLED(TFT_INTERFACE_SPI) + #define TFT_480x272_SPI + #elif ENABLED(TFT_INTERFACE_FSMC) + #define TFT_480x272 + #endif #endif #endif -// Fewer lines with touch buttons on-screen #if EITHER(TFT_320x240, TFT_320x240_SPI) #define HAS_UI_320x240 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) #elif EITHER(TFT_480x320, TFT_480x320_SPI) #define HAS_UI_480x320 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) #elif EITHER(TFT_480x272, TFT_480x272_SPI) #define HAS_UI_480x272 1 - #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) +#endif +#if ANY(HAS_UI_320x240, HAS_UI_480x320, HAS_UI_480x272) + #define LCD_HEIGHT TERN(TOUCH_SCREEN, 6, 7) // Fewer lines with touch buttons onscreen #endif // This emulated DOGM has 'touch/xpt2046', not 'tft/xpt2046' diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 1f7b317917c9..b3beedfe80fd 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -802,8 +802,6 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #if ENABLED(BABYSTEP_XY) static_assert(BABYSTEP_MULTIPLICATOR_XY <= 0.25f, "BABYSTEP_MULTIPLICATOR_XY must be less than or equal to 0.25mm."); #endif - #elif ENABLED(BABYSTEP_DISPLAY_TOTAL) && ANY(TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) - #error "New Color UI (TFT_320x240, TFT_320x240_SPI, TFT_480x320, TFT_480x320_SPI) does not support BABYSTEP_DISPLAY_TOTAL yet." #endif #endif diff --git a/Marlin/src/lcd/dogm/dogm_Statusscreen.h b/Marlin/src/lcd/dogm/dogm_Statusscreen.h index 15578e21d92d..61fee3e048ff 100644 --- a/Marlin/src/lcd/dogm/dogm_Statusscreen.h +++ b/Marlin/src/lcd/dogm/dogm_Statusscreen.h @@ -193,7 +193,7 @@ #define STATUS_LOGO_HEIGHT (sizeof(status_logo_bmp) / (STATUS_LOGO_BYTEWIDTH)) #endif #ifndef STATUS_LOGO_Y - #define STATUS_LOGO_Y _MAX(0L, (28L - _MIN(28L, STATUS_LOGO_HEIGHT)) / 2L) + #define STATUS_LOGO_Y _MAX(0U, (28U - _MIN(28U, STATUS_LOGO_HEIGHT)) / 2U) #endif static_assert( sizeof(status_logo_bmp) == (STATUS_LOGO_BYTEWIDTH) * (STATUS_LOGO_HEIGHT), diff --git a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp index 985041ede572..8ae6ab662793 100644 --- a/Marlin/src/lcd/dogm/status_screen_DOGM.cpp +++ b/Marlin/src/lcd/dogm/status_screen_DOGM.cpp @@ -40,6 +40,10 @@ #include "../../gcode/parser.h" // for units (and volumetric) +#if ENABLED(LCD_SHOW_E_TOTAL) + #include "../../MarlinCore.h" // for printingIsActive(), marlin_state and MF_SD_COMPLETE +#endif + #if ENABLED(FILAMENT_LCD_DISPLAY) #include "../../feature/filwidth.h" #include "../../module/planner.h" diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.cpp b/Marlin/src/lcd/dwin/e3v2/dwin.cpp index b872ce32aa07..e0caa0722f18 100644 --- a/Marlin/src/lcd/dwin/e3v2/dwin.cpp +++ b/Marlin/src/lcd/dwin/e3v2/dwin.cpp @@ -132,8 +132,9 @@ #define FEEDRATE_E (60) -// Mininum unit (0.1) : multiple (10) -#define MINUNITMULT 10 +// Minimum unit (0.1) : multiple (10) +#define UNITFDIGITS 1 +#define MINUNITMULT pow(10, UNITFDIGITS) #define ENCODER_WAIT 20 #define DWIN_SCROLL_UPDATE_INTERVAL 2000 @@ -1171,8 +1172,8 @@ void HMI_Move_X() { } NOLESS(HMI_ValueStruct.Move_X_scale, (X_MIN_POS) * MINUNITMULT); NOMORE(HMI_ValueStruct.Move_X_scale, (X_MAX_POS) * MINUNITMULT); - current_position.x = HMI_ValueStruct.Move_X_scale / 10; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale); + current_position.x = HMI_ValueStruct.Move_X_scale / MINUNITMULT; + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(1), HMI_ValueStruct.Move_X_scale); DWIN_UpdateLCD(); } } @@ -1194,8 +1195,8 @@ void HMI_Move_Y() { } NOLESS(HMI_ValueStruct.Move_Y_scale, (Y_MIN_POS) * MINUNITMULT); NOMORE(HMI_ValueStruct.Move_Y_scale, (Y_MAX_POS) * MINUNITMULT); - current_position.y = HMI_ValueStruct.Move_Y_scale / 10; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale); + current_position.y = HMI_ValueStruct.Move_Y_scale / MINUNITMULT; + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale); DWIN_UpdateLCD(); } } @@ -1206,7 +1207,7 @@ void HMI_Move_Z() { if (Apply_Encoder(encoder_diffState, HMI_ValueStruct.Move_Z_scale)) { checkkey = AxisMove; EncoderRate.enabled = false; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); if (!planner.is_full()) { // Wait for planner moves to finish! planner.synchronize(); @@ -1217,8 +1218,8 @@ void HMI_Move_Z() { } NOLESS(HMI_ValueStruct.Move_Z_scale, Z_MIN_POS * MINUNITMULT); NOMORE(HMI_ValueStruct.Move_Z_scale, Z_MAX_POS * MINUNITMULT); - current_position.z = HMI_ValueStruct.Move_Z_scale / 10; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); + current_position.z = HMI_ValueStruct.Move_Z_scale / MINUNITMULT; + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 216, MBASE(3), HMI_ValueStruct.Move_Z_scale); DWIN_UpdateLCD(); } } @@ -1233,7 +1234,7 @@ void HMI_Move_Z() { checkkey = AxisMove; EncoderRate.enabled = false; last_E_scale = HMI_ValueStruct.Move_E_scale; - DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); + DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); if (!planner.is_full()) { planner.synchronize(); // Wait for planner moves to finish! planner.buffer_line(current_position, MMM_TO_MMS(FEEDRATE_E), active_extruder); @@ -1245,8 +1246,8 @@ void HMI_Move_Z() { HMI_ValueStruct.Move_E_scale = last_E_scale + (EXTRUDE_MAXLENGTH) * MINUNITMULT; else if ((last_E_scale - HMI_ValueStruct.Move_E_scale) > (EXTRUDE_MAXLENGTH) * MINUNITMULT) HMI_ValueStruct.Move_E_scale = last_E_scale - (EXTRUDE_MAXLENGTH) * MINUNITMULT; - current_position.e = HMI_ValueStruct.Move_E_scale / 10; - DWIN_Draw_Signed_Float(font8x16, Select_Color, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); + current_position.e = HMI_ValueStruct.Move_E_scale / MINUNITMULT; + DWIN_Draw_Signed_Float(font8x16, Select_Color, 3, UNITFDIGITS, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); DWIN_UpdateLCD(); } } @@ -1503,7 +1504,7 @@ void HMI_MaxAccelerationXYZE() { NOMORE(HMI_ValueStruct.Max_Jerk, default_max_jerk[HMI_flag.jerk_axis] * 2 * MINUNITMULT); NOLESS(HMI_ValueStruct.Max_Jerk, (MIN_MAXJERK) * MINUNITMULT); // MaxJerk value - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); } } @@ -1525,7 +1526,7 @@ void HMI_StepXYZE() { NOMORE(HMI_ValueStruct.Max_Step, 999.9 * MINUNITMULT); NOLESS(HMI_ValueStruct.Max_Step, MIN_STEP); // Step value - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); } } @@ -2317,13 +2318,12 @@ void HMI_Prepare() { select_axis.reset(); Draw_Move_Menu(); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(1), current_position.x * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(2), current_position.y * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(3), current_position.z * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(1), current_position.x * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(2), current_position.y * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 216, MBASE(3), current_position.z * MINUNITMULT); #if HAS_HOTEND - current_position.e = HMI_ValueStruct.Move_E_scale = 0.0; - sync_plan_position_e(); - DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, 1, 216, MBASE(4), 0.0); + HMI_ValueStruct.Move_E_scale = current_position.e * MINUNITMULT; + DWIN_Draw_Signed_Float(font8x16, Color_Bg_Black, 3, 1, 216, MBASE(4), HMI_ValueStruct.Move_E_scale); #endif break; case PREPARE_CASE_DISA: // Disable steppers @@ -2573,8 +2573,7 @@ void HMI_AxisMove() { if (HMI_flag.ETempTooLow_flag) { if (encoder_diffState == ENCODER_DIFF_ENTER) { HMI_flag.ETempTooLow_flag = false; - current_position.e = HMI_ValueStruct.Move_E_scale = 0; - sync_plan_position_e(); + HMI_ValueStruct.Move_E_scale = current_position.e * MINUNITMULT; Draw_Move_Menu(); DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(1), HMI_ValueStruct.Move_X_scale); DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 216, MBASE(2), HMI_ValueStruct.Move_Y_scale); @@ -3020,11 +3019,11 @@ inline void Draw_Max_Accel_Menu() { Draw_Back_First(); LOOP_L_N(i, 3 + ENABLED(HAS_HOTEND)) Draw_Menu_Line(i + 1, ICON_MaxSpeedJerkX + i); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(1), planner.max_jerk[X_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(2), planner.max_jerk[Y_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(3), planner.max_jerk[Z_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(1), planner.max_jerk[X_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(2), planner.max_jerk[Y_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(3), planner.max_jerk[Z_AXIS] * MINUNITMULT); #if HAS_HOTEND - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(4), planner.max_jerk[E_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(4), planner.max_jerk[E_AXIS] * MINUNITMULT); #endif } #endif @@ -3068,11 +3067,11 @@ inline void Draw_Steps_Menu() { Draw_Back_First(); LOOP_L_N(i, 3 + ENABLED(HAS_HOTEND)) Draw_Menu_Line(i + 1, ICON_StepX + i); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(1), planner.settings.axis_steps_per_mm[X_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(2), planner.settings.axis_steps_per_mm[Y_AXIS] * MINUNITMULT); - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(3), planner.settings.axis_steps_per_mm[Z_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(1), planner.settings.axis_steps_per_mm[X_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(2), planner.settings.axis_steps_per_mm[Y_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(3), planner.settings.axis_steps_per_mm[Z_AXIS] * MINUNITMULT); #if HAS_HOTEND - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, 1, 210, MBASE(4), planner.settings.axis_steps_per_mm[E_AXIS] * MINUNITMULT); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Color_Bg_Black, 3, UNITFDIGITS, 210, MBASE(4), planner.settings.axis_steps_per_mm[E_AXIS] * MINUNITMULT); #endif } @@ -3419,7 +3418,7 @@ void HMI_MaxAcceleration() { checkkey = MaxJerk_value; HMI_flag.jerk_axis = AxisEnum(select_jerk.now - 1); HMI_ValueStruct.Max_Jerk = planner.max_jerk[HMI_flag.jerk_axis] * MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_jerk.now), HMI_ValueStruct.Max_Jerk); EncoderRate.enabled = true; } else { // Back @@ -3449,7 +3448,7 @@ void HMI_Step() { checkkey = Step_value; HMI_flag.step_axis = AxisEnum(select_step.now - 1); HMI_ValueStruct.Max_Step = planner.settings.axis_steps_per_mm[HMI_flag.step_axis] * MINUNITMULT; - DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, 1, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); + DWIN_Draw_FloatValue(true, true, 0, font8x16, Color_White, Select_Color, 3, UNITFDIGITS, 210, MBASE(select_step.now), HMI_ValueStruct.Max_Step); EncoderRate.enabled = true; } else { // Back diff --git a/Marlin/src/lcd/marlinui.cpp b/Marlin/src/lcd/marlinui.cpp index c78407a5af03..46db57193669 100644 --- a/Marlin/src/lcd/marlinui.cpp +++ b/Marlin/src/lcd/marlinui.cpp @@ -1495,6 +1495,7 @@ void MarlinUI::update() { #ifdef ACTION_ON_CANCEL host_action_cancel(); #endif + IF_DISABLED(SDSUPPORT, print_job_timer.stop()); TERN_(HOST_PROMPT_SUPPORT, host_prompt_open(PROMPT_INFO, PSTR("UI Aborted"), DISMISS_STR)); LCD_MESSAGEPGM(MSG_PRINT_ABORTED); TERN_(HAS_LCD_MENU, return_to_status()); diff --git a/Marlin/src/lcd/menu/menu_bed_corners.cpp b/Marlin/src/lcd/menu/menu_bed_corners.cpp index 473b09d3280b..751be18600f6 100644 --- a/Marlin/src/lcd/menu/menu_bed_corners.cpp +++ b/Marlin/src/lcd/menu/menu_bed_corners.cpp @@ -174,12 +174,13 @@ static inline void _lcd_level_bed_corners_get_next_position() { MenuItem_static::draw(0, GET_TEXT(MSG_PROBING_MESH), SS_INVERT); // "Probing Mesh" heading - uint8_t cy = LCD_HEIGHT - 1, y = LCD_ROW_Y(cy); + uint8_t cy = TERN(TFT_COLOR_UI, 3, LCD_HEIGHT - 1), y = LCD_ROW_Y(cy); // Display # of good points found vs total needed if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) { - SETCURSOR(0, cy); + SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy); lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_GOOD_POINTS)); + IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, cy)); lcd_put_u8str(GOOD_POINTS_TO_STR(good_points)); lcd_put_wchar('/'); lcd_put_u8str(GOOD_POINTS_TO_STR(nr_edge_points)); @@ -190,8 +191,9 @@ static inline void _lcd_level_bed_corners_get_next_position() { // Display the Last Z value if (PAGE_CONTAINS(y - (MENU_FONT_HEIGHT), y)) { - SETCURSOR(0, cy); + SETCURSOR(TERN(TFT_COLOR_UI, 2, 0), cy); lcd_put_u8str_P(GET_TEXT(MSG_LEVEL_CORNERS_LAST_Z)); + IF_ENABLED(TFT_COLOR_UI, lcd_moveto(12, 2)); lcd_put_u8str(LAST_Z_TO_STR(last_z)); } } diff --git a/Marlin/src/lcd/menu/menu_tune.cpp b/Marlin/src/lcd/menu/menu_tune.cpp index cccb352d8ff0..0fbb57f2ac17 100644 --- a/Marlin/src/lcd/menu/menu_tune.cpp +++ b/Marlin/src/lcd/menu/menu_tune.cpp @@ -71,9 +71,16 @@ const bool in_view = TERN1(HAS_MARLINUI_U8GLIB, PAGE_CONTAINS(LCD_PIXEL_HEIGHT - MENU_FONT_HEIGHT, LCD_PIXEL_HEIGHT - 1)); if (in_view) { TERN_(HAS_MARLINUI_U8GLIB, ui.set_font(FONT_MENU)); - lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1)); - lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL)); - lcd_put_wchar(':'); + #if ENABLED(TFT_COLOR_UI) + lcd_moveto(4, 3); + lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL)); + lcd_put_wchar(':'); + lcd_moveto(10, 3); + #else + lcd_moveto(0, TERN(HAS_MARLINUI_U8GLIB, LCD_PIXEL_HEIGHT - MENU_FONT_DESCENT, LCD_HEIGHT - 1)); + lcd_put_u8str_P(GET_TEXT(MSG_BABYSTEP_TOTAL)); + lcd_put_wchar(':'); + #endif lcd_put_u8str(BABYSTEP_TO_STR(spm * babystep.axis_total[BS_TOTAL_IND(axis)])); } #endif diff --git a/Marlin/src/lcd/tft/tft_image.cpp b/Marlin/src/lcd/tft/tft_image.cpp index 9cc6fb15e4a0..851410b2e0f5 100644 --- a/Marlin/src/lcd/tft/tft_image.cpp +++ b/Marlin/src/lcd/tft/tft_image.cpp @@ -20,8 +20,11 @@ * */ +#include "../../inc/MarlinConfigPre.h" + +#if HAS_GRAPHICAL_TFT + #include "tft_image.h" -#include const tImage NoLogo = { nullptr, 0, 0, NOCOLORS }; @@ -70,4 +73,38 @@ const tImage Leveling_32x32x4 = { (void *)leveling_32x32x4, 32, 32, GREYSC const tImage Slider8x16x4 = { (void *)slider_8x16x4, 8, 16, GREYSCALE4 }; -extern const tImage Images[imgCount]; +const tImage Images[imgCount] = { + TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MARLIN_LOGO_FULL_SIZE), NoLogo), + HotEnd_64x64x4, + Bed_64x64x4, + Bed_Heated_64x64x4, + Chamber_64x64x4, + Chamber_Heated_64x64x4, + Fan0_64x64x4, + Fan_Slow0_64x64x4, + Fan_Slow1_64x64x4, + Fan_Fast0_64x64x4, + Fan_Fast1_64x64x4, + Feedrate_32x32x4, + Flowrate_32x32x4, + SD_64x64x4, + Menu_64x64x4, + Settings_64x64x4, + Directory_32x32x4, + Confirm_64x64x4, + Cancel_64x64x4, + Increase_64x64x4, + Decrease_64x64x4, + Back_32x32x4, + Up_32x32x4, + Down_32x32x4, + Left_32x32x4, + Right_32x32x4, + Refresh_32x32x4, + Leveling_32x32x4, + Slider8x16x4, + Home_64x64x4, + BtnRounded_64x52x4, +}; + +#endif // HAS_GRAPHICAL_TFT diff --git a/Marlin/src/lcd/tft/tft_image.h b/Marlin/src/lcd/tft/tft_image.h index 21bd2d665fc6..960a4e4356af 100644 --- a/Marlin/src/lcd/tft/tft_image.h +++ b/Marlin/src/lcd/tft/tft_image.h @@ -21,9 +21,10 @@ */ #pragma once -#include "stdint.h" #include "../../inc/MarlinConfigPre.h" +#include + extern const uint8_t marlin_logo_112x38x1[]; extern const uint8_t marlin_logo_228x255x2[]; extern const uint8_t marlin_logo_228x255x4[]; diff --git a/Marlin/src/lcd/tft/tft_string.cpp b/Marlin/src/lcd/tft/tft_string.cpp index eb805ac423dc..31ac14cf92b3 100644 --- a/Marlin/src/lcd/tft/tft_string.cpp +++ b/Marlin/src/lcd/tft/tft_string.cpp @@ -36,7 +36,7 @@ font_t *TFT_String::font_header; uint8_t TFT_String::data[]; uint16_t TFT_String::span; -uint16_t TFT_String::length; +uint8_t TFT_String::length; void TFT_String::set_font(const uint8_t *font) { font_header = (font_t *)font; @@ -122,13 +122,14 @@ void TFT_String::add(uint8_t *string, int8_t index, uint8_t *itemString) { eol(); } -void TFT_String::add(uint8_t *string) { +void TFT_String::add(uint8_t *string, uint8_t max_len) { wchar_t wchar; - while (*string) { + while (*string && max_len) { string = get_utf8_value_cb(string, read_byte, &wchar); if (wchar > 255) wchar |= 0x0080; uint8_t ch = uint8_t(wchar & 0x00FF); add_character(ch); + max_len--; } eol(); } diff --git a/Marlin/src/lcd/tft/tft_string.h b/Marlin/src/lcd/tft/tft_string.h index e800b1ded95e..133889d9ae54 100644 --- a/Marlin/src/lcd/tft/tft_string.h +++ b/Marlin/src/lcd/tft/tft_string.h @@ -69,7 +69,7 @@ class TFT_String { static uint8_t data[MAX_STRING_LENGTH + 1]; static uint16_t span; // in pixels - static uint16_t length; // in characters + static uint8_t length; // in characters static void add_character(uint8_t character); static void eol() { data[length] = 0x00; } @@ -85,7 +85,7 @@ class TFT_String { static void set(); static void add(uint8_t character) { add_character(character); eol(); } - static void add(uint8_t *string); + static void add(uint8_t *string, uint8_t max_len=MAX_STRING_LENGTH); static void add(uint8_t *string, int8_t index, uint8_t *itemString=nullptr); static void set(uint8_t *string) { set(); add(string); }; static void set(uint8_t *string, int8_t index, const char *itemString=nullptr) { set(); add(string, index, (uint8_t *)itemString); }; @@ -96,6 +96,9 @@ class TFT_String { static void trim(uint8_t character=0x20); static void rtrim(uint8_t character=0x20); static void ltrim(uint8_t character=0x20); + + static void truncate(uint8_t maxlen) { if (length > maxlen) { length = maxlen; eol(); } } + static uint16_t width() { return span; } static uint8_t *string() { return data; } static uint16_t center(uint16_t width) { return span > width ? 0 : (width - span) / 2; } diff --git a/Marlin/src/lcd/tft/ui_320x240.cpp b/Marlin/src/lcd/tft/ui_320x240.cpp index aea0039698a2..eadd09ef27ec 100644 --- a/Marlin/src/lcd/tft/ui_320x240.cpp +++ b/Marlin/src/lcd/tft/ui_320x240.cpp @@ -24,7 +24,7 @@ #if HAS_UI_320x240 -#include "ui_320x240.h" +#include "ui_common.h" #include "../marlinui.h" #include "../menu/menu.h" @@ -45,12 +45,6 @@ #include "../../feature/bedlevel/bedlevel.h" #endif -#if !HAS_LCD_MENU - #error "Seriously? High resolution TFT screen without menu?" -#endif - -static bool draw_menu_navigation = false; - void MarlinUI::tft_idle() { #if ENABLED(TOUCH_SCREEN) if (draw_menu_navigation) { @@ -65,28 +59,6 @@ void MarlinUI::tft_idle() { TERN_(TOUCH_SCREEN, touch.idle()); } -void MarlinUI::init_lcd() { - tft.init(); - tft.set_font(MENU_FONT_NAME); - #ifdef SYMBOLS_FONT_NAME - tft.add_glyphs(SYMBOLS_FONT_NAME); - #endif - TERN_(TOUCH_SCREEN, touch.init()); - clear_lcd(); -} - -bool MarlinUI::detected() { return true; } - -void MarlinUI::clear_lcd() { - #if ENABLED(TOUCH_SCREEN) - touch.reset(); - draw_menu_navigation = false; - #endif - - tft.queue.reset(); - tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND); -} - #if ENABLED(SHOW_BOOTSCREEN) void MarlinUI::show_bootscreen() { tft.queue.reset(); @@ -98,8 +70,8 @@ void MarlinUI::clear_lcd() { #define SITE_URL_Y (TFT_HEIGHT - 46) tft.set_background(COLOR_BACKGROUND); #else - #define BOOT_LOGO_W 320 // MarlinLogo320x240x16 - #define BOOT_LOGO_H 240 + #define BOOT_LOGO_W TFT_WIDTH // MarlinLogo320x240x16 + #define BOOT_LOGO_H TFT_HEIGHT #define SITE_URL_Y (TFT_HEIGHT - 52) #endif tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen); @@ -148,22 +120,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { currentTemperature = thermalManager.degHotend(Heater); targetTemperature = thermalManager.degTargetHotend(Heater); } -#if HAS_HEATED_BED - else if (Heater == H_BED) { - currentTemperature = thermalManager.degBed(); - targetTemperature = thermalManager.degTargetBed(); - } -#endif // HAS_HEATED_BED -#if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - currentTemperature = thermalManager.degChamber(); - #if HAS_HEATED_CHAMBER - targetTemperature = thermalManager.degTargetChamber(); - #else - targetTemperature = ABSOLUTE_ZERO; - #endif - } -#endif // HAS_TEMP_CHAMBER + #if HAS_HEATED_BED + else if (Heater == H_BED) { + currentTemperature = thermalManager.degBed(); + targetTemperature = thermalManager.degTargetBed(); + } + #endif + #if HAS_TEMP_CHAMBER + else if (Heater == H_CHAMBER) { + currentTemperature = thermalManager.degChamber(); + #if HAS_HEATED_CHAMBER + targetTemperature = thermalManager.degTargetChamber(); + #else + targetTemperature = ABSOLUTE_ZERO; + #endif + } + #endif else return; TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 64, 100, Heater)); @@ -176,17 +148,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { if (currentTemperature >= 50) Color = COLOR_HOTEND; } #if HAS_HEATED_BED - else if (Heater == H_BED) { - if (currentTemperature >= 50) Color = COLOR_HEATED_BED; - image = targetTemperature > 0 ? imgBedHeated : imgBed; - } - #endif // HAS_HEATED_BED + else if (Heater == H_BED) { + if (currentTemperature >= 50) Color = COLOR_HEATED_BED; + image = targetTemperature > 0 ? imgBedHeated : imgBed; + } + #endif #if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - if (currentTemperature >= 50) Color = COLOR_CHAMBER; - image = targetTemperature > 0 ? imgChamberHeated : imgChamber; - } - #endif // HAS_TEMP_CHAMBER + else if (Heater == H_CHAMBER) { + if (currentTemperature >= 50) Color = COLOR_CHAMBER; + image = targetTemperature > 0 ? imgChamberHeated : imgChamber; + } + #endif tft.add_image(0, 18, image, Color); @@ -200,7 +172,6 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { tft_string.add(LCD_STR_DEGREE); tft_string.trim(); tft.add_text(tft_string.center(64) + 2, 8, Color, tft_string); - } } @@ -232,7 +203,7 @@ void MarlinUI::draw_status_screen() { TERN_(TOUCH_SCREEN, touch.clear()); // heaters and fan - uint16_t i, x, y = POS_Y; + uint16_t i, x, y = TFT_STATUS_TOP_Y; for (i = 0 ; i < ITEMS_COUNT; i++) { x = (320 / ITEMS_COUNT - 64) / 2 + (320 * i / ITEMS_COUNT); @@ -341,49 +312,6 @@ void MarlinUI::draw_status_screen() { #endif } -// Draw a static item with no left-right margin required. Centered by default. -void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { - menu_item(row); - tft_string.set(pstr, itemIndex, itemString); - if (vstr) - tft_string.add(vstr); - tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); -} - -// Draw a generic menu item with pre_char (if selected) and post_char -void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) { - menu_item(row, sel); - - uint8_t *string = (uint8_t *)pstr; - MarlinImage image = noImage; - switch (*string) { - case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH - case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER - } - - uint8_t offset = MENU_TEXT_X_OFFSET; - if (image != noImage) { - string++; - offset = 32; - tft.add_image(0, 0, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - } - - tft_string.set(string, itemIndex, itemString); - tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); -} - -// Draw a menu item with a (potentially) editable value -void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) { - menu_item(row, sel); - - tft_string.set(pstr, itemIndex, itemString); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - if (data) { - tft_string.set(data); - tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - } -} - // Low-level draw_edit_screen can be used to draw an edit screen from anyplace void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { ui.encoder_direction_normal(); @@ -483,16 +411,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #endif } -#if ENABLED(SDSUPPORT) - void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) { - menu_item(row, sel); - if (isDir) - tft.add_image(0, 0, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - tft.add_text(32, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename()); - } -#endif - #if ENABLED(ADVANCED_PAUSE_FEATURE) + void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) { #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -513,6 +433,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); } + #endif // ADVANCED_PAUSE_FEATURE #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -562,18 +483,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(96 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - - tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 32) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, 32, 32); + constexpr uint8_t w = (TFT_WIDTH) / 10; + tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 1, w, 32); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(x_plot)); tft_string.trim(); - tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, 32, 32); + tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET, GRID_OFFSET_Y + (GRID_HEIGHT - 27) / 2, w, 32); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(y_plot)); tft_string.trim(); - tft.add_text(tft_string.center(32), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -588,104 +509,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const } #endif // AUTO_BED_LEVELING_UBL -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - void MarlinUI::touch_calibration_screen() { - uint16_t x, y; - - calibrationState calibration_stage = touch_calibration.get_calibration_state(); - - if (calibration_stage == CALIBRATION_NONE) { - defer_status_screen(true); - clear_lcd(); - calibration_stage = touch_calibration.calibration_start(); - } - else { - x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; - y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; - tft.canvas(x - 15, y - 15, 31, 31); - tft.set_background(COLOR_BACKGROUND); - } - - touch.clear(); - - if (calibration_stage < CALIBRATION_SUCCESS) { - switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; - case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; - case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; - case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; - default: break; - } - - x = touch_calibration.calibration_points[calibration_stage].x; - y = touch_calibration.calibration_points[calibration_stage].y; - - tft.canvas(x - 15, y - 15, 31, 31); - tft.set_background(COLOR_BACKGROUND); - tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); - tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION); - - touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); - } - else { - tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); - defer_status_screen(false); - touch_calibration.calibration_end(); - touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); - } - - tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height()); - tft.set_background(COLOR_BACKGROUND); - tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); - } -#endif // TOUCH_SCREEN_CALIBRATION - -void menu_line(const uint8_t row, uint16_t color) { - tft.canvas(0, 2 + 34 * row, TFT_WIDTH, 32); - tft.set_background(color); -} - -void menu_pause_option(); - -void menu_item(const uint8_t row, bool sel ) { - #if ENABLED(TOUCH_SCREEN) - if (row == 0) { - touch.clear(); - draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true); - } - #endif - - menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - #if ENABLED(TOUCH_SCREEN) - const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; - touch.add_control(tct, 0, 2 + 34 * row, TFT_WIDTH, 32, encoderTopLine + row); - #endif -} - -void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { - #define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH)) - tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43); - tft.set_background(COLOR_BACKGROUND); -} - -int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { - tft_string.set(); - tft_string.add(c); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - return tft_string.width(); -} - -int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { - tft_string.set(utf8_str_P); - tft_string.trim(); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - return tft_string.width(); -} - -int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { - return lcd_put_u8str_max_P(utf8_str, max_length); -} - void MarlinUI::move_axis_screen() { } diff --git a/Marlin/src/lcd/tft/ui_320x240.h b/Marlin/src/lcd/tft/ui_320x240.h index 249a21c4f106..40b2185577b9 100644 --- a/Marlin/src/lcd/tft/ui_320x240.h +++ b/Marlin/src/lcd/tft/ui_320x240.h @@ -21,88 +21,22 @@ */ #pragma once -#include "../../inc/MarlinConfigPre.h" +#define MARLIN_LOGO_FULL_SIZE MarlinLogo320x240x16 -#include "tft.h" -#include "tft_image.h" +#define TFT_STATUS_TOP_Y 0 +#define TFT_TOP_LINE_Y 2 -#if ENABLED(TOUCH_SCREEN) - #include "touch.h" -#endif +#define MENU_TEXT_X_OFFSET 10 +#define MENU_TEXT_Y_OFFSET 7 -void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater); -void draw_fan_status(uint16_t x, uint16_t y, const bool blink); +#define MENU_ITEM_ICON_X 0 +#define MENU_ITEM_ICON_Y 0 +#define MENU_ITEM_ICON_SPACE 32 -#define MENU_TEXT_X_OFFSET 10 -#define MENU_TEXT_Y_OFFSET 7 -void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND); -void menu_item(const uint8_t row, bool sel = false); +#define MENU_ITEM_HEIGHT 32 +#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2) -#define MENU_FONT_NAME Helvetica14 -#define SYMBOLS_FONT_NAME Helvetica14_symbols +#define MENU_FONT_NAME Helvetica14 +#define SYMBOLS_FONT_NAME Helvetica14_symbols -#define ABSOLUTE_ZERO -273.15 - -const tImage Images[imgCount] = { - TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo320x240x16), NoLogo), - HotEnd_64x64x4, - Bed_64x64x4, - Bed_Heated_64x64x4, - Chamber_64x64x4, - Chamber_Heated_64x64x4, - Fan0_64x64x4, - Fan_Slow0_64x64x4, - Fan_Slow1_64x64x4, - Fan_Fast0_64x64x4, - Fan_Fast1_64x64x4, - Feedrate_32x32x4, - Flowrate_32x32x4, - SD_64x64x4, - Menu_64x64x4, - Settings_64x64x4, - Directory_32x32x4, - Confirm_64x64x4, - Cancel_64x64x4, - Increase_64x64x4, - Decrease_64x64x4, - Back_32x32x4, - Up_32x32x4, - Down_32x32x4, - Left_32x32x4, - Right_32x32x4, - Refresh_32x32x4, - Leveling_32x32x4, - Slider8x16x4, - Home_64x64x4, - BtnRounded_64x52x4, -}; - -#if HAS_TEMP_CHAMBER && HOTENDS > 1 - #define ITEM_E0 0 - #define ITEM_E1 1 - #define ITEM_BED 2 - #define ITEM_CHAMBER 3 - #define ITEM_FAN 4 - #define ITEMS_COUNT 5 - #define POS_Y 0 -#elif HAS_TEMP_CHAMBER - #define ITEM_E0 0 - #define ITEM_BED 1 - #define ITEM_CHAMBER 2 - #define ITEM_FAN 3 - #define ITEMS_COUNT 4 - #define POS_Y 0 -#elif HOTENDS > 1 - #define ITEM_E0 0 - #define ITEM_E1 1 - #define ITEM_BED 2 - #define ITEM_FAN 3 - #define ITEMS_COUNT 4 - #define POS_Y 0 -#else - #define ITEM_E0 0 - #define ITEM_BED 1 - #define ITEM_FAN 2 - #define ITEMS_COUNT 3 - #define POS_Y 0 -#endif +#include "ui_common.h" diff --git a/Marlin/src/lcd/tft/ui_480x320.cpp b/Marlin/src/lcd/tft/ui_480x320.cpp index 4165c3990c60..5000aedc39a5 100644 --- a/Marlin/src/lcd/tft/ui_480x320.cpp +++ b/Marlin/src/lcd/tft/ui_480x320.cpp @@ -24,7 +24,7 @@ #if HAS_UI_480x320 || HAS_UI_480x272 -#include "ui_480x320.h" +#include "ui_common.h" #include "../marlinui.h" #include "../menu/menu.h" @@ -45,14 +45,6 @@ #include "../../feature/bedlevel/bedlevel.h" #endif -#if !HAS_LCD_MENU - #error "Seriously? High resolution TFT screen without menu?" -#endif - -#if ENABLED(TOUCH_SCREEN) - static bool draw_menu_navigation = false; -#endif - void MarlinUI::tft_idle() { #if ENABLED(TOUCH_SCREEN) if (draw_menu_navigation) { @@ -67,28 +59,6 @@ void MarlinUI::tft_idle() { TERN_(TOUCH_SCREEN, touch.idle()); } -void MarlinUI::init_lcd() { - tft.init(); - tft.set_font(MENU_FONT_NAME); - #ifdef SYMBOLS_FONT_NAME - tft.add_glyphs(SYMBOLS_FONT_NAME); - #endif - TERN_(TOUCH_SCREEN, touch.init()); - clear_lcd(); -} - -bool MarlinUI::detected() { return true; } - -void MarlinUI::clear_lcd() { - #if ENABLED(TOUCH_SCREEN) - touch.reset(); - draw_menu_navigation = false; - #endif - - tft.queue.reset(); - tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND); -} - #if ENABLED(SHOW_BOOTSCREEN) void MarlinUI::show_bootscreen() { tft.queue.reset(); @@ -100,8 +70,8 @@ void MarlinUI::clear_lcd() { #define SITE_URL_Y (TFT_HEIGHT - 70) tft.set_background(COLOR_BACKGROUND); #else - #define BOOT_LOGO_W 480 // MarlinLogo480x320x16 - #define BOOT_LOGO_H 320 + #define BOOT_LOGO_W TFT_WIDTH // MarlinLogo480x320x16 + #define BOOT_LOGO_H TFT_HEIGHT #define SITE_URL_Y (TFT_HEIGHT - 90) #endif tft.add_image((TFT_WIDTH - BOOT_LOGO_W) / 2, (TFT_HEIGHT - BOOT_LOGO_H) / 2, imgBootScreen); @@ -150,22 +120,22 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { currentTemperature = thermalManager.degHotend(Heater); targetTemperature = thermalManager.degTargetHotend(Heater); } -#if HAS_HEATED_BED - else if (Heater == H_BED) { - currentTemperature = thermalManager.degBed(); - targetTemperature = thermalManager.degTargetBed(); - } -#endif // HAS_HEATED_BED -#if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - currentTemperature = thermalManager.degChamber(); - #if HAS_HEATED_CHAMBER - targetTemperature = thermalManager.degTargetChamber(); - #else - targetTemperature = ABSOLUTE_ZERO; - #endif - } -#endif // HAS_TEMP_CHAMBER + #if HAS_HEATED_BED + else if (Heater == H_BED) { + currentTemperature = thermalManager.degBed(); + targetTemperature = thermalManager.degTargetBed(); + } + #endif + #if HAS_TEMP_CHAMBER + else if (Heater == H_CHAMBER) { + currentTemperature = thermalManager.degChamber(); + #if HAS_HEATED_CHAMBER + targetTemperature = thermalManager.degTargetChamber(); + #else + targetTemperature = ABSOLUTE_ZERO; + #endif + } + #endif else return; TERN_(TOUCH_SCREEN, if (targetTemperature >= 0) touch.add_control(HEATER, x, y, 80, 120, Heater)); @@ -178,17 +148,17 @@ void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater) { if (currentTemperature >= 50) Color = COLOR_HOTEND; } #if HAS_HEATED_BED - else if (Heater == H_BED) { - if (currentTemperature >= 50) Color = COLOR_HEATED_BED; - image = targetTemperature > 0 ? imgBedHeated : imgBed; - } - #endif // HAS_HEATED_BED + else if (Heater == H_BED) { + if (currentTemperature >= 50) Color = COLOR_HEATED_BED; + image = targetTemperature > 0 ? imgBedHeated : imgBed; + } + #endif #if HAS_TEMP_CHAMBER - else if (Heater == H_CHAMBER) { - if (currentTemperature >= 50) Color = COLOR_CHAMBER; - image = targetTemperature > 0 ? imgChamberHeated : imgChamber; - } - #endif // HAS_TEMP_CHAMBER + else if (Heater == H_CHAMBER) { + if (currentTemperature >= 50) Color = COLOR_CHAMBER; + image = targetTemperature > 0 ? imgChamberHeated : imgChamber; + } + #endif tft.add_image(8, 28, image, Color); @@ -233,7 +203,7 @@ void MarlinUI::draw_status_screen() { TERN_(TOUCH_SCREEN, touch.clear()); // heaters and fan - uint16_t i, x, y = POS_Y; + uint16_t i, x, y = TFT_STATUS_TOP_Y; for (i = 0 ; i < ITEMS_COUNT; i++) { x = (TFT_WIDTH / ITEMS_COUNT - 80) / 2 + (TFT_WIDTH * i / ITEMS_COUNT); @@ -349,49 +319,6 @@ void MarlinUI::draw_status_screen() { tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_STATUS_MESSAGE, tft_string); } -// Draw a static item with no left-right margin required. Centered by default. -void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { - menu_item(row); - tft_string.set(pstr, itemIndex, itemString); - if (vstr) - tft_string.add(vstr); - tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); -} - -// Draw a generic menu item with pre_char (if selected) and post_char -void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) { - menu_item(row, sel); - - uint8_t *string = (uint8_t *)pstr; - MarlinImage image = noImage; - switch (*string) { - case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH - case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER - } - - uint8_t offset = MENU_TEXT_X_OFFSET; - if (image != noImage) { - string++; - offset = 42; - tft.add_image(5, 5, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - } - - tft_string.set(string, itemIndex, itemString); - tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); -} - -// Draw a menu item with a (potentially) editable value -void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) { - menu_item(row, sel); - - tft_string.set(pstr, itemIndex, itemString); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - if (data) { - tft_string.set(data); - tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - } -} - // Low-level draw_edit_screen can be used to draw an edit screen from anyplace void MenuEditItemBase::draw_edit_screen(PGM_P const pstr, const char* const value/*=nullptr*/) { ui.encoder_direction_normal(); @@ -491,16 +418,8 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const #endif } -#if ENABLED(SDSUPPORT) - void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) { - menu_item(row, sel); - if (isDir) - tft.add_image(5, 5, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - tft.add_text(42, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename()); - } -#endif - #if ENABLED(ADVANCED_PAUSE_FEATURE) + void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) { #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -521,6 +440,7 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); } + #endif // ADVANCED_PAUSE_FEATURE #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -570,18 +490,18 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const tft_string.trim(); tft.add_text(120 - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - - tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - 48) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, 48, MENU_ITEM_HEIGHT); + constexpr uint8_t w = (TFT_WIDTH) / 10; + tft.canvas(GRID_OFFSET_X + (GRID_WIDTH - w) / 2, GRID_OFFSET_Y + GRID_HEIGHT + CONTROL_OFFSET - 5, w, MENU_ITEM_HEIGHT); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(x_plot)); tft_string.trim(); - tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); - tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, 48, MENU_ITEM_HEIGHT); + tft.canvas(GRID_OFFSET_X + GRID_WIDTH + CONTROL_OFFSET + 16 - 24, GRID_OFFSET_Y + (GRID_HEIGHT - MENU_ITEM_HEIGHT) / 2, w, MENU_ITEM_HEIGHT); tft.set_background(COLOR_BACKGROUND); tft_string.set(ui8tostr3rj(y_plot)); tft_string.trim(); - tft.add_text(tft_string.center(48), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + tft.add_text(tft_string.center(w), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); #if ENABLED(TOUCH_SCREEN) touch.clear(); @@ -596,97 +516,6 @@ void MenuItem_confirm::draw_select_screen(PGM_P const yes, PGM_P const no, const } #endif // AUTO_BED_LEVELING_UBL -#if ENABLED(TOUCH_SCREEN_CALIBRATION) - void MarlinUI::touch_calibration_screen() { - uint16_t x, y; - - calibrationState calibration_stage = touch_calibration.get_calibration_state(); - - if (calibration_stage == CALIBRATION_NONE) { - defer_status_screen(true); - clear_lcd(); - calibration_stage = touch_calibration.calibration_start(); - } - else { - x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; - y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; - tft.canvas(x - 15, y - 15, 31, 31); - tft.set_background(COLOR_BACKGROUND); - } - - touch.clear(); - - if (calibration_stage < CALIBRATION_SUCCESS) { - switch (calibration_stage) { - case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; - case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; - case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; - case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; - default: break; - } - - x = touch_calibration.calibration_points[calibration_stage].x; - y = touch_calibration.calibration_points[calibration_stage].y; - - tft.canvas(x - 15, y - 15, 31, 31); - tft.set_background(COLOR_BACKGROUND); - tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); - tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION); - - touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); - } - else { - tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); - defer_status_screen(false); - touch_calibration.calibration_end(); - touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); - } - - tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height()); - tft.set_background(COLOR_BACKGROUND); - tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); - } -#endif // TOUCH_SCREEN_CALIBRATION - -void menu_line(const uint8_t row, uint16_t color) { - tft.canvas(0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT); - tft.set_background(color); -} - -void menu_pause_option(); - -void menu_item(const uint8_t row, bool sel ) { - #if ENABLED(TOUCH_SCREEN) - if (row == 0) { - touch.clear(); - draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true); - } - #endif - - menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); - #if ENABLED(TOUCH_SCREEN) - const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; - touch.add_control(tct, 0, 4 + (MENU_ITEM_HEIGHT + 2) * row, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row); - #endif -} - -void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { - #define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH)) - tft.canvas(col * TFT_COL_WIDTH, 4 + 45 * row, TFT_WIDTH - (col * TFT_COL_WIDTH), 43); - tft.set_background(COLOR_BACKGROUND); -} - -int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { - tft_string.set(utf8_str_P); - tft_string.trim(); - tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); - return tft_string.width(); -} - -int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { - return lcd_put_u8str_max_P(utf8_str, max_length); -} - #if ENABLED(BABYSTEP_ZPROBE_OFFSET) #include "../../feature/babystep.h" #endif @@ -889,37 +718,14 @@ static void moveAxis(AxisEnum axis, const int8_t direction) { drawAxisValue(axis); } -static void e_plus() { - moveAxis(E_AXIS, 1); -} - -static void e_minus() { - moveAxis(E_AXIS, -1); -} - -static void x_minus() { - moveAxis(X_AXIS, -1); -} - -static void x_plus() { - moveAxis(X_AXIS, 1); -} - -static void y_plus() { - moveAxis(Y_AXIS, 1); -} - -static void y_minus() { - moveAxis(Y_AXIS, -1); -} - -static void z_plus() { - moveAxis(Z_AXIS, 1); -} - -static void z_minus() { - moveAxis(Z_AXIS, -1); -} +static void e_plus() { moveAxis(E_AXIS, 1); } +static void e_minus() { moveAxis(E_AXIS, -1); } +static void x_minus() { moveAxis(X_AXIS, -1); } +static void x_plus() { moveAxis(X_AXIS, 1); } +static void y_plus() { moveAxis(Y_AXIS, 1); } +static void y_minus() { moveAxis(Y_AXIS, -1); } +static void z_plus() { moveAxis(Z_AXIS, 1); } +static void z_minus() { moveAxis(Z_AXIS, -1); } #if ENABLED(TOUCH_SCREEN) static void e_select() { @@ -1002,8 +808,9 @@ void MarlinUI::move_axis_screen() { const bool busy = printingIsActive(); - // if we have baby step and we are printing, select baby step - if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) motionAxisState.z_selection = Z_SELECTION_Z_PROBE; + // Babysteps during printing? Select babystep for Z probe offset + if (busy && ENABLED(BABYSTEP_ZPROBE_OFFSET)) + motionAxisState.z_selection = Z_SELECTION_Z_PROBE; // ROW 1 -> E- Y- CurY Z+ int x = X_MARGIN, y = Y_MARGIN, spacing = 0; @@ -1089,7 +896,7 @@ void MarlinUI::move_axis_screen() { TERN_(HAS_TFT_XPT2046, touch.add_control(BUTTON, motionAxisState.stepValuePos.x, motionAxisState.stepValuePos.y, CUR_STEP_VALUE_WIDTH, BTN_HEIGHT, (intptr_t)step_size)); } - // alinged with x+ + // aligned with x+ drawBtn(xplus_x, TFT_HEIGHT - Y_MARGIN - BTN_HEIGHT, "off", (intptr_t)disable_steppers, imgCancel, COLOR_WHITE, !busy); TERN_(HAS_TFT_XPT2046, add_control(TFT_WIDTH - X_MARGIN - BTN_WIDTH, y, BACK, imgBack)); diff --git a/Marlin/src/lcd/tft/ui_480x320.h b/Marlin/src/lcd/tft/ui_480x320.h index e3a688f112b1..fca9ed9c2a22 100644 --- a/Marlin/src/lcd/tft/ui_480x320.h +++ b/Marlin/src/lcd/tft/ui_480x320.h @@ -21,97 +21,29 @@ */ #pragma once -#include "../../inc/MarlinConfigPre.h" +#define MARLIN_LOGO_FULL_SIZE MarlinLogo480x320x16 -#include "tft.h" -#include "tft_image.h" +#include "ui_common.h" -#if ENABLED(TOUCH_SCREEN) - #include "touch.h" -#endif +#define TFT_STATUS_TOP_Y 4 +#define TFT_TOP_LINE_Y 4 -void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater); -void draw_fan_status(uint16_t x, uint16_t y, const bool blink); +#define MENU_TEXT_X_OFFSET 16 +#define MENU_TEXT_Y_OFFSET 7 -#define MENU_TEXT_X_OFFSET 16 -#define MENU_TEXT_Y_OFFSET 7 -void menu_line(const uint8_t row, uint16_t color = COLOR_BACKGROUND); -void menu_item(const uint8_t row, bool sel = false); +#define MENU_ITEM_ICON_X 5 +#define MENU_ITEM_ICON_Y 5 +#define MENU_ITEM_ICON_SPACE 42 #if HAS_UI_480x320 - #define MENU_FONT_NAME Helvetica18 - #define SYMBOLS_FONT_NAME Helvetica18_symbols - #define MENU_ITEM_HEIGHT 43 - #define FONT_LINE_HEIGHT 34 + #define MENU_FONT_NAME Helvetica18 + #define SYMBOLS_FONT_NAME Helvetica18_symbols + #define MENU_ITEM_HEIGHT 43 + #define FONT_LINE_HEIGHT 34 #elif HAS_UI_480x272 - #define MENU_FONT_NAME Helvetica14 - #define SYMBOLS_FONT_NAME Helvetica14_symbols - #define MENU_ITEM_HEIGHT 36 - #define FONT_LINE_HEIGHT 24 -#endif - -#define ABSOLUTE_ZERO -273.15 - -const tImage Images[imgCount] = { - TERN(SHOW_BOOTSCREEN, TERN(BOOT_MARLIN_LOGO_SMALL, MarlinLogo195x59x16, MarlinLogo480x320x16), NoLogo), - HotEnd_64x64x4, - Bed_64x64x4, - Bed_Heated_64x64x4, - Chamber_64x64x4, - Chamber_Heated_64x64x4, - Fan0_64x64x4, - Fan_Slow0_64x64x4, - Fan_Slow1_64x64x4, - Fan_Fast0_64x64x4, - Fan_Fast1_64x64x4, - Feedrate_32x32x4, - Flowrate_32x32x4, - SD_64x64x4, - Menu_64x64x4, - Settings_64x64x4, - Directory_32x32x4, - Confirm_64x64x4, - Cancel_64x64x4, - Increase_64x64x4, - Decrease_64x64x4, - Back_32x32x4, - Up_32x32x4, - Down_32x32x4, - Left_32x32x4, - Right_32x32x4, - Refresh_32x32x4, - Leveling_32x32x4, - Slider8x16x4, - Home_64x64x4, - BtnRounded_64x52x4, -}; - -#if HAS_TEMP_CHAMBER && HOTENDS > 1 - #define ITEM_E0 0 - #define ITEM_E1 1 - #define ITEM_BED 2 - #define ITEM_CHAMBER 3 - #define ITEM_FAN 4 - #define ITEMS_COUNT 5 - #define POS_Y 4 -#elif HAS_TEMP_CHAMBER - #define ITEM_E0 0 - #define ITEM_BED 1 - #define ITEM_CHAMBER 2 - #define ITEM_FAN 3 - #define ITEMS_COUNT 4 - #define POS_Y 4 -#elif HOTENDS > 1 - #define ITEM_E0 0 - #define ITEM_E1 1 - #define ITEM_BED 2 - #define ITEM_FAN 3 - #define ITEMS_COUNT 4 - #define POS_Y 4 -#else - #define ITEM_E0 0 - #define ITEM_BED 1 - #define ITEM_FAN 2 - #define ITEMS_COUNT 3 - #define POS_Y 4 + #define MENU_FONT_NAME Helvetica14 + #define SYMBOLS_FONT_NAME Helvetica14_symbols + #define MENU_ITEM_HEIGHT 36 + #define FONT_LINE_HEIGHT 24 #endif +#define MENU_LINE_HEIGHT (MENU_ITEM_HEIGHT + 2) diff --git a/Marlin/src/lcd/tft/ui_common.cpp b/Marlin/src/lcd/tft/ui_common.cpp new file mode 100644 index 000000000000..842fc3909c2a --- /dev/null +++ b/Marlin/src/lcd/tft/ui_common.cpp @@ -0,0 +1,246 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "../../inc/MarlinConfigPre.h" + +#if HAS_GRAPHICAL_TFT + +#include "ui_common.h" +#include "../lcdprint.h" +#include "../../libs/numtostr.h" +#include "../menu/menu.h" + +void menu_pause_option(); + +static xy_uint_t cursor; + +#if ENABLED(TOUCH_SCREEN) + bool draw_menu_navigation = false; +#endif + +void menu_line(const uint8_t row, uint16_t color) { + cursor.set(0, row); + tft.canvas(0, TFT_TOP_LINE_Y + cursor.y * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT); + tft.set_background(color); +} + +void menu_item(const uint8_t row, bool sel ) { + #if ENABLED(TOUCH_SCREEN) + if (row == 0) { + touch.clear(); + draw_menu_navigation = TERN(ADVANCED_PAUSE_FEATURE, ui.currentScreen != menu_pause_option, true); + } + #endif + + menu_line(row, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + #if ENABLED(TOUCH_SCREEN) + const TouchControlType tct = TERN(SINGLE_TOUCH_NAVIGATION, true, sel) ? MENU_CLICK : MENU_ITEM; + touch.add_control(tct, 0, TFT_TOP_LINE_Y + row * MENU_LINE_HEIGHT, TFT_WIDTH, MENU_ITEM_HEIGHT, encoderTopLine + row); + #endif +} + +// +// lcdprint.h functions +// + +#define TFT_COL_WIDTH ((TFT_WIDTH) / (LCD_WIDTH)) + +void lcd_gotopixel(const uint16_t x, const uint16_t y) { + if (x >= TFT_WIDTH) return; + cursor.set(x / (TFT_COL_WIDTH), y / MENU_LINE_HEIGHT); + tft.canvas(x, TFT_TOP_LINE_Y + y, (TFT_WIDTH) - x, MENU_ITEM_HEIGHT); + tft.set_background(COLOR_BACKGROUND); +} + +void lcd_moveto(const lcd_uint_t col, const lcd_uint_t row) { + lcd_gotopixel(int(col) * (TFT_COL_WIDTH), int(row) * MENU_LINE_HEIGHT); +} + +int lcd_put_wchar_max(wchar_t c, pixel_len_t max_length) { + if (max_length < 1) return 0; + tft_string.set(); + tft_string.add(c); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT); + return tft_string.width(); +} + +int lcd_put_u8str_max_P(PGM_P utf8_str_P, pixel_len_t max_length) { + if (max_length < 1) return 0; + tft_string.set(utf8_str_P); + tft_string.trim(); + tft_string.truncate(max_length); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + lcd_gotopixel((cursor.x + 1) * (TFT_COL_WIDTH) + tft_string.width(), cursor.y * MENU_LINE_HEIGHT); + return tft_string.width(); +} + +int lcd_put_u8str_max(const char * utf8_str, pixel_len_t max_length) { + return lcd_put_u8str_max_P(utf8_str, max_length); +} + +void lcd_put_int(const int i) { + // 3 digits max for this one... + const char* str = i16tostr3left(int16_t(i)); + lcd_put_u8str_max(str, 3); +} + +// +// Menu Item methods +// + +// Draw a generic menu item with pre_char (if selected) and post_char +void MenuItemBase::_draw(const bool sel, const uint8_t row, PGM_P const pstr, const char pre_char, const char post_char) { + menu_item(row, sel); + + uint8_t *string = (uint8_t *)pstr; + MarlinImage image = noImage; + switch (*string) { + case 0x01: image = imgRefresh; break; // LCD_STR_REFRESH + case 0x02: image = imgDirectory; break; // LCD_STR_FOLDER + } + + uint8_t offset = MENU_TEXT_X_OFFSET; + if (image != noImage) { + string++; + offset = MENU_ITEM_ICON_SPACE; + tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, image, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + } + + tft_string.set(string, itemIndex, itemString); + tft.add_text(offset, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); +} + +// Draw a menu item with a (potentially) editable value +void MenuEditItemBase::draw(const bool sel, const uint8_t row, PGM_P const pstr, const char* const data, const bool pgm) { + menu_item(row, sel); + + tft_string.set(pstr, itemIndex, itemString); + tft.add_text(MENU_TEXT_X_OFFSET, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, tft_string); + if (data) { + tft_string.set(data); + tft.add_text(TFT_WIDTH - MENU_TEXT_X_OFFSET - tft_string.width(), MENU_TEXT_Y_OFFSET, COLOR_MENU_VALUE, tft_string); + } +} + +// Draw a static item with no left-right margin required. Centered by default. +void MenuItem_static::draw(const uint8_t row, PGM_P const pstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) { + menu_item(row); + tft_string.set(pstr, itemIndex, itemString); + if (vstr) + tft_string.add(vstr); + tft.add_text(tft_string.center(TFT_WIDTH), MENU_TEXT_Y_OFFSET, COLOR_YELLOW, tft_string); +} + +#if ENABLED(SDSUPPORT) + + void MenuItem_sdbase::draw(const bool sel, const uint8_t row, PGM_P const, CardReader &theCard, const bool isDir) { + menu_item(row, sel); + if (isDir) + tft.add_image(MENU_ITEM_ICON_X, MENU_ITEM_ICON_Y, imgDirectory, COLOR_MENU_TEXT, sel ? COLOR_SELECTION_BG : COLOR_BACKGROUND); + tft.add_text(MENU_ITEM_ICON_SPACE, MENU_TEXT_Y_OFFSET, COLOR_MENU_TEXT, theCard.longest_filename()); + } + +#endif + +// +// MarlinUI methods +// + +bool MarlinUI::detected() { return true; } + +void MarlinUI::init_lcd() { + tft.init(); + tft.set_font(MENU_FONT_NAME); + #ifdef SYMBOLS_FONT_NAME + tft.add_glyphs(SYMBOLS_FONT_NAME); + #endif + TERN_(TOUCH_SCREEN, touch.init()); + clear_lcd(); +} + +void MarlinUI::clear_lcd() { + #if ENABLED(TOUCH_SCREEN) + touch.reset(); + draw_menu_navigation = false; + #endif + + tft.queue.reset(); + tft.fill(0, 0, TFT_WIDTH, TFT_HEIGHT, COLOR_BACKGROUND); + cursor.set(0, 0); +} + +#if ENABLED(TOUCH_SCREEN_CALIBRATION) + + void MarlinUI::touch_calibration_screen() { + uint16_t x, y; + + calibrationState calibration_stage = touch_calibration.get_calibration_state(); + + if (calibration_stage == CALIBRATION_NONE) { + defer_status_screen(true); + clear_lcd(); + calibration_stage = touch_calibration.calibration_start(); + } + else { + x = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].x; + y = touch_calibration.calibration_points[_MIN(calibration_stage - 1, CALIBRATION_BOTTOM_RIGHT)].y; + tft.canvas(x - 15, y - 15, 31, 31); + tft.set_background(COLOR_BACKGROUND); + } + + touch.clear(); + + if (calibration_stage < CALIBRATION_SUCCESS) { + switch (calibration_stage) { + case CALIBRATION_TOP_LEFT: tft_string.set(GET_TEXT(MSG_TOP_LEFT)); break; + case CALIBRATION_BOTTOM_LEFT: tft_string.set(GET_TEXT(MSG_BOTTOM_LEFT)); break; + case CALIBRATION_TOP_RIGHT: tft_string.set(GET_TEXT(MSG_TOP_RIGHT)); break; + case CALIBRATION_BOTTOM_RIGHT: tft_string.set(GET_TEXT(MSG_BOTTOM_RIGHT)); break; + default: break; + } + + x = touch_calibration.calibration_points[calibration_stage].x; + y = touch_calibration.calibration_points[calibration_stage].y; + + tft.canvas(x - 15, y - 15, 31, 31); + tft.set_background(COLOR_BACKGROUND); + tft.add_bar(0, 15, 31, 1, COLOR_TOUCH_CALIBRATION); + tft.add_bar(15, 0, 1, 31, COLOR_TOUCH_CALIBRATION); + + touch.add_control(CALIBRATE, 0, 0, TFT_WIDTH, TFT_HEIGHT, uint32_t(x) << 16 | uint32_t(y)); + } + else { + tft_string.set(calibration_stage == CALIBRATION_SUCCESS ? GET_TEXT(MSG_CALIBRATION_COMPLETED) : GET_TEXT(MSG_CALIBRATION_FAILED)); + defer_status_screen(false); + touch_calibration.calibration_end(); + touch.add_control(BACK, 0, 0, TFT_WIDTH, TFT_HEIGHT); + } + + tft.canvas(0, (TFT_HEIGHT - tft_string.font_height()) >> 1, TFT_WIDTH, tft_string.font_height()); + tft.set_background(COLOR_BACKGROUND); + tft.add_text(tft_string.center(TFT_WIDTH), 0, COLOR_MENU_TEXT, tft_string); + } + +#endif // TOUCH_SCREEN_CALIBRATION + +#endif // HAS_GRAPHICAL_TFT diff --git a/Marlin/src/lcd/tft/ui_common.h b/Marlin/src/lcd/tft/ui_common.h new file mode 100644 index 000000000000..d40e471171b3 --- /dev/null +++ b/Marlin/src/lcd/tft/ui_common.h @@ -0,0 +1,76 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +#pragma once + +#include "../../inc/MarlinConfigPre.h" + +#if !HAS_LCD_MENU + #error "Seriously? High resolution TFT screen without menu?" +#endif + +#include "tft.h" +#include "tft_image.h" + +#if ENABLED(TOUCH_SCREEN) + #include "touch.h" + extern bool draw_menu_navigation; +#endif + +#if HAS_UI_320x240 + #include "ui_320x240.h" +#elif HAS_UI_480x320 || HAS_UI_480x272 + #include "ui_480x320.h" +#endif + +void draw_heater_status(uint16_t x, uint16_t y, const int8_t Heater); +void draw_fan_status(uint16_t x, uint16_t y, const bool blink); + +void menu_line(const uint8_t row, uint16_t color=COLOR_BACKGROUND); +void menu_item(const uint8_t row, bool sel = false); + +#define ABSOLUTE_ZERO -273.15 + +#if HAS_TEMP_CHAMBER && HOTENDS > 1 + #define ITEM_E0 0 + #define ITEM_E1 1 + #define ITEM_BED 2 + #define ITEM_CHAMBER 3 + #define ITEM_FAN 4 + #define ITEMS_COUNT 5 +#elif HAS_TEMP_CHAMBER + #define ITEM_E0 0 + #define ITEM_BED 1 + #define ITEM_CHAMBER 2 + #define ITEM_FAN 3 + #define ITEMS_COUNT 4 +#elif HOTENDS > 1 + #define ITEM_E0 0 + #define ITEM_E1 1 + #define ITEM_BED 2 + #define ITEM_FAN 3 + #define ITEMS_COUNT 4 +#else + #define ITEM_E0 0 + #define ITEM_BED 1 + #define ITEM_FAN 2 + #define ITEMS_COUNT 3 +#endif diff --git a/Marlin/src/module/endstops.cpp b/Marlin/src/module/endstops.cpp index 1328851752d1..b9d2c1cdf561 100644 --- a/Marlin/src/module/endstops.cpp +++ b/Marlin/src/module/endstops.cpp @@ -398,7 +398,7 @@ void Endstops::event_handler() { card.endFilePrint(); quickstop_stepper(); thermalManager.disable_all_heaters(); - print_job_timer.stop(); // Wait for planner before calling! + print_job_timer.stop(); } #endif } diff --git a/Marlin/src/module/printcounter.cpp b/Marlin/src/module/printcounter.cpp index 20bf175e7815..45072c8f0189 100644 --- a/Marlin/src/module/printcounter.cpp +++ b/Marlin/src/module/printcounter.cpp @@ -41,6 +41,10 @@ Stopwatch print_job_timer; // Global Print Job Timer instance #include "../libs/buzzer.h" #endif +#if PRINTCOUNTER_SYNC + #include "../module/planner.h" +#endif + // Service intervals #if HAS_SERVICE_INTERVALS #if SERVICE_INTERVAL_1 > 0 @@ -160,6 +164,8 @@ void PrintCounter::saveStats() { // Refuses to save data if object is not loaded if (!isLoaded()) return; + TERN_(PRINTCOUNTER_SYNC, planner.synchronize()); + // Saves the struct to EEPROM persistentStore.access_start(); persistentStore.write_data(address + sizeof(uint8_t), (uint8_t*)&data, sizeof(printStatistics)); @@ -224,9 +230,12 @@ void PrintCounter::tick() { millis_t now = millis(); - static uint32_t update_next; // = 0 + static millis_t update_next; // = 0 if (ELAPSED(now, update_next)) { + update_next = now + updateInterval; + TERN_(DEBUG_PRINTCOUNTER, debug(PSTR("tick"))); + millis_t delta = deltaDuration(); data.printTime += delta; @@ -239,16 +248,12 @@ void PrintCounter::tick() { #if SERVICE_INTERVAL_3 > 0 data.nextService3 -= _MIN(delta, data.nextService3); #endif - - update_next = now + updateInterval * 1000; } - // LPC1768 boards seem to lose steps when saving to EEPROM during print (issue #20785) - // TODO: Which other boards are incompatible? - #ifndef MCU_LPC1768 - static uint32_t eeprom_next; // = 0 + #if PRINTCOUNTER_SAVE_INTERVAL > 0 + static millis_t eeprom_next; // = 0 if (ELAPSED(now, eeprom_next)) { - eeprom_next = now + saveInterval * 1000; + eeprom_next = now + saveInterval; saveStats(); } #endif diff --git a/Marlin/src/module/printcounter.h b/Marlin/src/module/printcounter.h index 0d75e6e3f7a1..4deae45a656d 100644 --- a/Marlin/src/module/printcounter.h +++ b/Marlin/src/module/printcounter.h @@ -71,19 +71,18 @@ class PrintCounter: public Stopwatch { * @brief Interval in seconds between counter updates * @details This const value defines what will be the time between each * accumulator update. This is different from the EEPROM save interval. - * - * @note The max value for this option is 60(s), otherwise integer - * overflow will happen. */ - static constexpr uint16_t updateInterval = 10; + static constexpr millis_t updateInterval = SEC_TO_MS(10); - /** - * @brief Interval in seconds between EEPROM saves - * @details This const value defines what will be the time between each - * EEPROM save cycle, the development team recommends to set this value - * no lower than 3600 secs (1 hour). - */ - static constexpr uint16_t saveInterval = 3600; + #if PRINTCOUNTER_SAVE_INTERVAL > 0 + /** + * @brief Interval in seconds between EEPROM saves + * @details This const value defines what will be the time between each + * EEPROM save cycle, the development team recommends to set this value + * no lower than 3600 secs (1 hour). + */ + static constexpr millis_t saveInterval = MIN_TO_MS(PRINTCOUNTER_SAVE_INTERVAL); + #endif /** * @brief Timestamp of the last call to deltaDuration() diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index 052b8cd34a64..867ae5d9271d 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -828,7 +828,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a // Cool down with fan #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed; - gcode.dwell(toolchange_settings.fan_time * 1000); + gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time)); thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0; #endif @@ -1102,7 +1102,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) { // Cool down with fan #if HAS_FAN && TOOLCHANGE_FS_FAN >= 0 thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = toolchange_settings.fan_speed; - gcode.dwell(toolchange_settings.fan_time * 1000); + gcode.dwell(SEC_TO_MS(toolchange_settings.fan_time)); thermalManager.fan_speed[TOOLCHANGE_FS_FAN] = 0; #endif } diff --git a/buildroot/share/PlatformIO/scripts/common-dependencies.py b/buildroot/share/PlatformIO/scripts/common-dependencies.py index 4b8c339d460d..4500f529a66b 100644 --- a/buildroot/share/PlatformIO/scripts/common-dependencies.py +++ b/buildroot/share/PlatformIO/scripts/common-dependencies.py @@ -83,7 +83,7 @@ def add_to_feat_cnf(feature, flines): feat[name] = '='.join(parts) else: for dep in line.split(','): - lib_name = re.sub(r'([@~^=]|[<>]=?)[\d.]+', '', dep.strip()).split('=').pop(0) + lib_name = re.sub(r'@([~^]|[<>]=?)?[\d.]+', '', dep.strip()).split('=').pop(0) lib_re = re.compile('(?!^' + lib_name + '\\b)') feat['lib_deps'] = list(filter(lib_re.match, feat['lib_deps'])) + [dep]