diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h
index 374a420539..955a66be96 100644
--- a/Marlin/Configuration.h
+++ b/Marlin/Configuration.h
@@ -891,6 +891,12 @@
*/
//#define FIX_MOUNTED_PROBE
+/**
+ * Use the nozzle as the probe, with the hotend
+ * assembly attached to a sensitive strain gauge.
+ */
+//#define STRAIN_GAUGE_PROBE
+
/**
* Use the nozzle as the probe, as with a conductive
* nozzle system or a piezo-electric smart effector.
@@ -1270,10 +1276,21 @@
//#define MESH_BED_LEVELING
/**
- * Normally G28 leaves leveling disabled on completion. Enable
- * this option to have G28 restore the prior leveling state.
+ * Normally G28 leaves leveling disabled on completion. Enable one of
+ * these options to restore the prior leveling state or to always enable
+ * leveling immediately after G28.
*/
//#define RESTORE_LEVELING_AFTER_G28
+//#define ENABLE_LEVELING_AFTER_G28
+
+/**
+ * Auto-leveling needs preheating
+ */
+//#define PREHEAT_BEFORE_LEVELING
+#if ENABLED(PREHEAT_BEFORE_LEVELING)
+ #define LEVELING_NOZZLE_TEMP 120
+ #define LEVELING_BED_TEMP 50
+#endif
/**
* Enable detailed logging of G28, G29, M48, etc.
@@ -2198,6 +2215,11 @@
//#define DGUS_LCD_UI_FYSETC
//#define DGUS_LCD_UI_HIPRECY
+//
+// CR-6 OEM touch screen. A DWIN display with touch.
+//
+//#define DGUS_LCD_UI_CREALITY_TOUCH
+
//
// Touch-screen LCD for Malyan M200/M300 printers
//
diff --git a/Marlin/src/HAL/STM32F1/HAL.h b/Marlin/src/HAL/STM32F1/HAL.h
index b77539d7b6..ce72f9227a 100644
--- a/Marlin/src/HAL/STM32F1/HAL.h
+++ b/Marlin/src/HAL/STM32F1/HAL.h
@@ -109,6 +109,9 @@
#else
#error "LCD_SERIAL_PORT must be -1 or from 1 to 3. Please update your configuration."
#endif
+ #if HAS_DGUS_LCD
+ #define SERIAL_GET_TX_BUFFER_FREE() LCD_SERIAL.availableForWrite()
+ #endif
#endif
// Set interrupt grouping for this MCU
diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp
index f38ba35dd5..25c2407ef0 100644
--- a/Marlin/src/MarlinCore.cpp
+++ b/Marlin/src/MarlinCore.cpp
@@ -45,6 +45,7 @@
#include "core/utility.h"
#include "module/motion.h"
#include "module/planner.h"
+#include "module/probe.h"
#include "module/endstops.h"
#include "module/temperature.h"
#include "module/settings.h"
@@ -60,6 +61,7 @@
#include "sd/cardreader.h"
#include "lcd/marlinui.h"
+
#if HAS_TOUCH_XPT2046
#include "lcd/touch/touch_buttons.h"
#endif
@@ -77,6 +79,10 @@
#include "lcd/dwin/e3v2/rotary_encoder.h"
#endif
+#if ENABLED(EXTENSIBLE_UI)
+ #include "lcd/extui/ui_api.h"
+#endif
+
#if HAS_ETHERNET
#include "feature/ethernet.h"
#endif
@@ -356,6 +362,8 @@ void enable_all_steppers() {
ENABLE_AXIS_Y();
ENABLE_AXIS_Z();
enable_e_steppers();
+
+ TERN_(EXTENSIBLE_UI, ExtUI::onSteppersEnabled());
}
void disable_e_steppers() {
@@ -375,6 +383,8 @@ void disable_all_steppers() {
DISABLE_AXIS_Y();
DISABLE_AXIS_Z();
disable_e_steppers();
+
+ TERN_(EXTENSIBLE_UI, ExtUI::onSteppersDisabled());
}
#if ENABLED(G29_RETRY_AND_RECOVER)
@@ -751,6 +761,16 @@ void idle(TERN_(ADVANCED_PAUSE_FEATURE, bool no_stepper_sleep/*=false*/)) {
// Handle UI input / draw events
TERN(DWIN_CREALITY_LCD, DWIN_Update(), ui.update());
+ #if ENABLED(STRAIN_GAUGE_PROBE) && PIN_EXISTS(OPTO_SWITCH)
+ static bool optoSwitch;
+ const bool opto = READ(OPTO_SWITCH_PIN);
+ if (optoSwitch != opto) {
+ optoSwitch = opto;
+ //DEBUG_ECHOLNPAIR("Opto switch says: ", opto);
+ }
+ if (is_homing_z) endstops.enable_z_probe(!opto);
+ #endif
+
// Run i2c Position Encoders
#if ENABLED(I2C_POSITION_ENCODERS)
static millis_t i2cpem_next_update_ms;
@@ -1098,6 +1118,17 @@ void setup() {
SETUP_RUN(ui.reset_status()); // Load welcome message early. (Retained if no errors exist.)
#endif
+ #if ENABLED(STRAIN_GAUGE_PROBE)
+ #if PIN_EXISTS(COM)
+ SETUP_LOG("Init COM_PIN");
+ OUT_WRITE(COM_PIN, HIGH);
+ #endif
+ #if PIN_EXISTS(OPTO_SWITCH)
+ SETUP_LOG("Init OPTO_SWITCH_PIN");
+ SET_INPUT(OPTO_SWITCH_PIN);
+ #endif
+ #endif
+
#if BOTH(SDSUPPORT, SDCARD_EEPROM_EMULATION)
SETUP_RUN(card.mount()); // Mount media with settings before first_load
#endif
diff --git a/Marlin/src/core/boards.h b/Marlin/src/core/boards.h
index efccc3716d..78f4f7bae6 100644
--- a/Marlin/src/core/boards.h
+++ b/Marlin/src/core/boards.h
@@ -327,6 +327,7 @@
#define BOARD_TRIGORILLA_PRO 4037 // Trigorilla Pro (STM32F103ZET6)
#define BOARD_FLY_MINI 4038 // FLY MINI (STM32F103RCT6)
#define BOARD_FLSUN_HISPEED 4039 // FLSUN HiSpeedV1 (STM32F103VET6)
+#define BOARD_CREALITY_V452 4040 // Creality v4.5.2 (STM32F103RE)
//
// ARM Cortex-M4F
diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp
index f387dd9bd8..339694336f 100644
--- a/Marlin/src/gcode/bedlevel/abl/G29.cpp
+++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp
@@ -36,9 +36,12 @@
#include "../../../module/probe.h"
#include "../../queue.h"
+#if EITHER(PROBE_TEMP_COMPENSATION, PREHEAT_BEFORE_LEVELING)
+ #include "../../../module/temperature.h"
+#endif
+
#if ENABLED(PROBE_TEMP_COMPENSATION)
#include "../../../feature/probe_temp_comp.h"
- #include "../../../module/temperature.h"
#endif
#if HAS_DISPLAY
@@ -177,6 +180,20 @@ G29_TYPE GcodeSuite::G29() {
if (DISABLED(PROBE_MANUALLY) && seenQ) G29_RETURN(false);
#endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onMeshLevelingStart());
+
+ #if ENABLED(PREHEAT_BEFORE_LEVELING)
+ {
+ constexpr uint16_t hotendPreheat = LEVELING_NOZZLE_TEMP, bedPreheat = LEVELING_BED_TEMP;
+ if (DEBUGGING(LEVELING))
+ DEBUG_ECHOLNPAIR("Preheating hotend (", hotendPreheat, ") and bed (", bedPreheat, ")");
+ thermalManager.setTargetHotend(hotendPreheat, 0);
+ thermalManager.setTargetBed(bedPreheat);
+ if (hotendPreheat) thermalManager.wait_for_hotend(0);
+ if (bedPreheat) thermalManager.wait_for_bed_heating();
+ }
+ #endif
+
const bool seenA = TERN0(PROBE_MANUALLY, parser.seen('A')),
no_action = seenA || seenQ,
faux = ENABLED(DEBUG_LEVELING_FEATURE) && DISABLED(PROBE_MANUALLY) ? parser.boolval('C') : no_action;
@@ -392,6 +409,10 @@ G29_TYPE GcodeSuite::G29() {
planner.synchronize();
+ #if ENABLED(STRAIN_GAUGE_PROBE)
+ do_blocking_move_to_z(_MAX(Z_CLEARANCE_BETWEEN_PROBES, Z_CLEARANCE_DEPLOY_PROBE));
+ #endif
+
if (!faux) remember_feedrate_scaling_off();
// Disable auto bed leveling during G29.
@@ -656,8 +677,10 @@ G29_TYPE GcodeSuite::G29() {
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR)
- z_values[meshCount.x][meshCount.y] = measured_z + zoffset;
- TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(meshCount, z_values[meshCount.x][meshCount.y]));
+ #if ENABLED(EXTENSIBLE_UI)
+ const float z = z_values[meshCount.x][meshCount.y] = measured_z + zoffset;
+ ExtUI::onMeshUpdate(meshCount, z);
+ #endif
#endif
diff --git a/Marlin/src/gcode/calibrate/G28.cpp b/Marlin/src/gcode/calibrate/G28.cpp
index ef39290d2d..8040ce5900 100644
--- a/Marlin/src/gcode/calibrate/G28.cpp
+++ b/Marlin/src/gcode/calibrate/G28.cpp
@@ -50,6 +50,10 @@
#include "../../lcd/dwin/e3v2/dwin.h"
#endif
+#if ENABLED(EXTENSIBLE_UI)
+ #include "../../lcd/extui/ui_api.h"
+#endif
+
#if HAS_L64XX // set L6470 absolute position registers to counts
#include "../../libs/L64XX/L64XX_Marlin.h"
#endif
@@ -61,6 +65,10 @@
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../core/debug_out.h"
+#if ENABLED(STRAIN_GAUGE_PROBE)
+ bool is_homing, is_homing_z; // = false
+#endif
+
#if ENABLED(QUICK_HOME)
static void quick_home_xy() {
@@ -207,8 +215,6 @@ void GcodeSuite::G28() {
TERN_(LASER_MOVE_G28_OFF, cutter.set_inline_enabled(false)); // turn off laser
- TERN_(DWIN_CREALITY_LCD, HMI_flag.home_flag = true);
-
#if ENABLED(DUAL_X_CARRIAGE)
bool IDEX_saved_duplication_state = extruder_duplication_enabled;
DualXMode IDEX_saved_mode = dual_x_carriage_mode;
@@ -230,20 +236,25 @@ void GcodeSuite::G28() {
return;
}
+ TERN_(DWIN_CREALITY_LCD, DWIN_StartHoming());
+ TERN_(EXTENSIBLE_UI, ExtUI::onHomingStart());
+
+ TERN_(STRAIN_GAUGE_PROBE, is_homing = true);
+
planner.synchronize(); // Wait for planner moves to finish!
SET_SOFT_ENDSTOP_LOOSE(false); // Reset a leftover 'loose' motion state
// Disable the leveling matrix before homing
#if HAS_LEVELING
-
- // Cancel the active G29 session
- TERN_(PROBE_MANUALLY, g29_in_progress = false);
-
- TERN_(RESTORE_LEVELING_AFTER_G28, const bool leveling_was_active = planner.leveling_active);
+ TERN_(PROBE_MANUALLY, g29_in_progress = false); // Cancel the active G29 session
+ const bool leveling_restore_state = ENABLED(ENABLE_LEVELING_AFTER_G28) || TERN0(RESTORE_LEVELING_AFTER_G28, planner.leveling_active);
set_bed_leveling_enabled(false);
+ #else
+ constexpr bool leveling_restore_state = false;
#endif
+ // Reset to the XY plane
TERN_(CNC_WORKSPACE_PLANES, workspace_plane = PLANE_XY);
// Count this command as movement / activity
@@ -330,6 +341,8 @@ void GcodeSuite::G28() {
do_z_clearance(z_homing_height, true, DISABLED(UNKNOWN_Z_NO_RAISE));
}
+ TERN_(STRAIN_GAUGE_PROBE, is_homing = false);
+
#if ENABLED(QUICK_HOME)
if (doX && doY) quick_home_xy();
@@ -419,6 +432,11 @@ void GcodeSuite::G28() {
#endif // DUAL_X_CARRIAGE
+ #if ENABLED(STRAIN_GAUGE_PROBE)
+ endstops.enable_z_probe(false);
+ is_homing_z = false;
+ #endif
+
endstops.not_homing();
// Clear endstop state for polled stallGuard endstops
@@ -429,8 +447,6 @@ void GcodeSuite::G28() {
do_blocking_move_to_z(delta_clip_start_height);
#endif
- TERN_(RESTORE_LEVELING_AFTER_G28, set_bed_leveling_enabled(leveling_was_active));
-
restore_feedrate_and_scaling();
// Restore the active tool after homing
@@ -454,9 +470,12 @@ void GcodeSuite::G28() {
#endif
#endif
+ TERN_(HAS_LEVELING, set_bed_leveling_enabled(leveling_restore_state));
+
ui.refresh();
TERN_(DWIN_CREALITY_LCD, DWIN_CompletedHoming());
+ TERN_(EXTENSIBLE_UI, ExtUI::onHomingComplete());
report_current_position();
diff --git a/Marlin/src/gcode/sd/M1001.cpp b/Marlin/src/gcode/sd/M1001.cpp
index 4a461170bc..e4b7054bf2 100644
--- a/Marlin/src/gcode/sd/M1001.cpp
+++ b/Marlin/src/gcode/sd/M1001.cpp
@@ -96,6 +96,8 @@ void GcodeSuite::M1001() {
queue.inject_P(PSTR(SD_FINISHED_RELEASECOMMAND));
#endif
+ TERN_(EXTENSIBLE_UI, ExtUI::onPrintFinished());
+
// Re-select the last printed file in the UI
TERN_(SD_REPRINT_LAST_SELECTED_FILE, ui.reselect_last_file());
}
diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h
index 0bb98e9e06..48171acc9b 100644
--- a/Marlin/src/inc/Conditionals_LCD.h
+++ b/Marlin/src/inc/Conditionals_LCD.h
@@ -456,7 +456,7 @@
#endif
// Aliases for LCD features
-#if ANY(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY)
+#if ANY(DGUS_LCD_UI_ORIGIN, DGUS_LCD_UI_FYSETC, DGUS_LCD_UI_HIPRECY, DGUS_LCD_UI_CREALITY_TOUCH)
#define HAS_DGUS_LCD 1
#endif
diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h
index 9fb3e53c4e..0ee825e0d9 100644
--- a/Marlin/src/inc/Conditionals_post.h
+++ b/Marlin/src/inc/Conditionals_post.h
@@ -2211,7 +2211,7 @@
#define HAS_TEMPERATURE 1
#endif
-#if HAS_TEMPERATURE && EITHER(HAS_LCD_MENU, DWIN_CREALITY_LCD)
+#if HAS_TEMPERATURE && ANY(HAS_LCD_MENU, DWIN_CREALITY_LCD, DGUS_LCD_UI_CREALITY_TOUCH)
#ifdef PREHEAT_5_LABEL
#define PREHEAT_COUNT 5
#elif defined(PREHEAT_4_LABEL)
@@ -2621,7 +2621,7 @@
#endif
// Number of VFAT entries used. Each entry has 13 UTF-16 characters
-#if EITHER(SCROLL_LONG_FILENAMES, DWIN_CREALITY_LCD)
+#if ANY(SCROLL_LONG_FILENAMES, DWIN_CREALITY_LCD, DWIN_CREALITY_TOUCHLCD)
#define MAX_VFAT_ENTRIES (5)
#else
#define MAX_VFAT_ENTRIES (2)
diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h
index 2ef4cbb785..3571ce553e 100644
--- a/Marlin/src/inc/SanityCheck.h
+++ b/Marlin/src/inc/SanityCheck.h
@@ -1381,7 +1381,7 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS."
#elif !WITHIN(GRID_MAX_POINTS_X, 3, 15) || !WITHIN(GRID_MAX_POINTS_Y, 3, 15)
#error "GRID_MAX_POINTS_[XY] must be a whole number between 3 and 15."
- #elif !defined(RESTORE_LEVELING_AFTER_G28)
+ #elif !defined(RESTORE_LEVELING_AFTER_G28) && !defined(ENABLE_LEVELING_AFTER_G28)
#error "AUTO_BED_LEVELING_UBL used to enable RESTORE_LEVELING_AFTER_G28. To keep this behavior enable RESTORE_LEVELING_AFTER_G28. Otherwise define it as 'false'."
#endif
@@ -1409,6 +1409,10 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS
#endif
+#if ALL(HAS_LEVELING, RESTORE_LEVELING_AFTER_G28, ENABLE_LEVELING_AFTER_G28)
+ #error "Only enable RESTORE_LEVELING_AFTER_G28 or ENABLE_LEVELING_AFTER_G28, but not both."
+#endif
+
#if HAS_MESH && HAS_CLASSIC_JERK
static_assert(DEFAULT_ZJERK > 0.1, "Low DEFAULT_ZJERK values are incompatible with mesh-based leveling.");
#endif
@@ -2244,6 +2248,7 @@ static_assert(hbm[Z_AXIS] >= 0, "HOMING_BUMP_MM.Z must be greater than or equal
+ ENABLED(MKS_LCD12864) \
+ ENABLED(OLED_PANEL_TINYBOY2) \
+ ENABLED(OVERLORD_OLED) \
+ + ENABLED(DGUS_LCD_UI_CREALITY_TOUCH) \
+ ENABLED(PANEL_ONE) \
+ ENABLED(RA_CONTROL_PANEL) \
+ ENABLED(RADDS_DISPLAY) \
diff --git a/Marlin/src/lcd/dwin/e3v2/dwin.h b/Marlin/src/lcd/dwin/e3v2/dwin.h
index 5bff2e9f78..8f17c30609 100644
--- a/Marlin/src/lcd/dwin/e3v2/dwin.h
+++ b/Marlin/src/lcd/dwin/e3v2/dwin.h
@@ -369,5 +369,7 @@ void DWIN_Update();
void EachMomentUpdate();
void DWIN_HandleScreen();
+inline void DWIN_StartHoming() { HMI_flag.home_flag = true; }
+
void DWIN_CompletedHoming();
void DWIN_CompletedLeveling();
diff --git a/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp b/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp
index a7f9a7a0c3..06baa4c19d 100644
--- a/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp
+++ b/Marlin/src/lcd/extui/anycubic_chiron_lcd.cpp
@@ -62,6 +62,10 @@ namespace ExtUI {
void onUserConfirmRequired(const char * const msg) { Chiron.ConfirmationRequest(msg); }
void onStatusChanged(const char * const msg) { Chiron.StatusChange(msg); }
+ void onHomingStart() {}
+ void onHomingComplete() {}
+ void onPrintFinished() {}
+
void onFactoryReset() {}
void onStoreSettings(char *buff) {
@@ -95,6 +99,8 @@ namespace ExtUI {
}
#if HAS_MESH
+ void onMeshLevelingStart() {}
+
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
// Called when any mesh points are updated
//SERIAL_ECHOLNPAIR("onMeshUpdate() x:", xpos, " y:", ypos, " z:", zval);
@@ -116,6 +122,9 @@ namespace ExtUI {
// Called for temperature PID tuning result
}
#endif
+
+ void onSteppersDisabled() {}
+ void onSteppersEnabled() {}
}
#endif // ANYCUBIC_LCD_CHIRON
diff --git a/Marlin/src/lcd/extui/anycubic_i3mega_lcd.cpp b/Marlin/src/lcd/extui/anycubic_i3mega_lcd.cpp
index 15526d16fc..e2bd96068c 100644
--- a/Marlin/src/lcd/extui/anycubic_i3mega_lcd.cpp
+++ b/Marlin/src/lcd/extui/anycubic_i3mega_lcd.cpp
@@ -52,6 +52,11 @@ namespace ExtUI {
void onFilamentRunout(const extruder_t extruder) { AnycubicTFT.OnFilamentRunout(); }
void onUserConfirmRequired(const char * const msg) { AnycubicTFT.OnUserConfirmRequired(msg); }
void onStatusChanged(const char * const msg) {}
+
+ void onHomingStart() {}
+ void onHomingComplete() {}
+ void onPrintFinished() {}
+
void onFactoryReset() {}
void onStoreSettings(char *buff) {
@@ -84,9 +89,14 @@ namespace ExtUI {
// whether successful or not.
}
- void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
- // Called when any mesh points are updated
- }
+ #if HAS_MESH
+
+ void onMeshLevelingStart() {}
+
+ void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
+ // Called when any mesh points are updated
+ }
+ #endif
#if ENABLED(POWER_LOSS_RECOVERY)
void onPowerLossResume() {
@@ -99,6 +109,9 @@ namespace ExtUI {
// Called for temperature PID tuning result
}
#endif
+
+ void onSteppersDisabled() {}
+ void onSteppersEnabled() {}
}
#endif // ANYCUBIC_LCD_I3MEGA
diff --git a/Marlin/src/lcd/extui/dgus_creality_lcd.cpp b/Marlin/src/lcd/extui/dgus_creality_lcd.cpp
new file mode 100644
index 0000000000..42e9c2eb8c
--- /dev/null
+++ b/Marlin/src/lcd/extui/dgus_creality_lcd.cpp
@@ -0,0 +1,197 @@
+/**
+ * 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 .
+ *
+ */
+
+/**
+ * dgus_creality_lcd.cpp
+ *
+ * DGUS implementation written by coldtobi in 2019 for Marlin
+ */
+
+#include "../../inc/MarlinConfigPre.h"
+
+#if ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+
+#include "ui_api.h"
+#include "lib/dgus/DGUSDisplayDef.h"
+#include "lib/dgus_creality/DGUSDisplay.h"
+#include "lib/dgus_creality/DGUSScreenHandler.h"
+
+extern const char NUL_STR[];
+
+namespace ExtUI {
+
+ void onStartup() {
+ dgusdisplay.InitDisplay();
+ ScreenHandler.UpdateScreenVPData();
+ }
+
+ void onIdle() { ScreenHandler.loop(); }
+
+ void onPrinterKilled(PGM_P const error, PGM_P const component) {
+ ScreenHandler.sendinfoscreen(GET_TEXT(MSG_HALTED), error, GET_TEXT(MSG_PLEASE_RESET), NUL_STR, true, true, true, true);
+
+ if (strcmp_P(error, GET_TEXT(MSG_ERR_MAXTEMP)) == 0 || strcmp_P(error, GET_TEXT(MSG_THERMAL_RUNAWAY)) == 0) {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_THERMAL_RUNAWAY);
+ } else if (strcmp_P(error, GET_TEXT(MSG_HEATING_FAILED_LCD)) == 0) {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_HEATING_FAILED);
+ }else if (strcmp_P(error, GET_TEXT(MSG_ERR_MINTEMP)) == 0) {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_THERMISTOR_ERROR);
+ } else {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_KILL);
+ }
+
+ while (!ScreenHandler.loop()); // Wait while anything is left to be sent
+ }
+
+ void onMediaInserted() { TERN_(SDSUPPORT, ScreenHandler.SDCardInserted()); }
+ void onMediaError() { TERN_(SDSUPPORT, ScreenHandler.SDCardError()); }
+ void onMediaRemoved() { TERN_(SDSUPPORT, ScreenHandler.SDCardRemoved()); }
+
+ void onPlayTone(const uint16_t frequency, const uint16_t duration) {
+ ScreenHandler.Buzzer(frequency, duration);
+ }
+
+ void onPrintTimerStarted() {}
+
+ void onPrintTimerPaused() {
+ // Handle M28 Pause SD print - But only if we're not waiting on a user
+ if (ExtUI::isPrintingFromMediaPaused() && ScreenHandler.getCurrentScreen() == DGUSLCD_SCREEN_PRINT_RUNNING) {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_PRINT_PAUSED);
+ }
+ }
+
+ void onPrintTimerStopped() {}
+
+ void onFilamentRunout(const extruder_t extruder) { ScreenHandler.FilamentRunout(); }
+
+ void onUserConfirmed() {
+ SERIAL_ECHOLNPGM("User confirmation invoked");
+ ScreenHandler.SetupConfirmAction(nullptr);
+ ExtUI::setUserConfirmed();
+ }
+
+ void onUserConfirmRequired(const char * const msg) {
+ if (msg) {
+ SERIAL_ECHOLNPAIR("User confirmation requested: ", msg);
+
+ ScreenHandler.setstatusmessagePGM(msg);
+ ScreenHandler.SetupConfirmAction(onUserConfirmed);
+
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POPUP);
+
+ ScreenHandler.sendinfoscreen(PSTR("Confirmation required"), msg, NUL_STR, NUL_STR, true, true, false, true);
+ }
+ else if (ScreenHandler.getCurrentScreen() == DGUSLCD_SCREEN_POPUP) {
+ SERIAL_ECHOLNPGM("User confirmation canceled");
+
+ //ScreenHandler.SetupConfirmAction(nullptr);
+ ScreenHandler.setstatusmessagePGM(nullptr);
+ ScreenHandler.PopToOldScreen();
+ }
+ }
+
+ void onStatusChanged(const char * const msg) { ScreenHandler.setstatusmessage(msg); }
+
+ void onFactoryReset() { ScreenHandler.OnFactoryReset(); }
+
+ void onHomingStart() { ScreenHandler.OnHomingStart(); }
+ void onHomingComplete() { ScreenHandler.OnHomingComplete(); }
+
+ void onPrintFinished() { ScreenHandler.OnPrintFinished(); }
+
+ void onStoreSettings(char *buff) {
+ // Called when saving to EEPROM (i.e. M500). If the ExtUI needs
+ // permanent data to be stored, it can write up to eeprom_data_size bytes
+ // into buff.
+
+ // Example:
+ // static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
+ // memcpy(buff, &myDataStruct, sizeof(myDataStruct));
+ }
+
+ void onLoadSettings(const char *buff) {
+ // Called while loading settings from EEPROM. If the ExtUI
+ // needs to retrieve data, it should copy up to eeprom_data_size bytes
+ // from buff
+
+ // Example:
+ // static_assert(sizeof(myDataStruct) <= ExtUI::eeprom_data_size);
+ // memcpy(&myDataStruct, buff, sizeof(myDataStruct));
+ }
+
+ void onConfigurationStoreWritten(bool success) {
+ // Called after the entire EEPROM has been written,
+ // whether successful or not.
+ }
+
+ void onConfigurationStoreRead(bool success) {
+ // Called after the entire EEPROM has been read,
+ // whether successful or not.
+ }
+
+ #if HAS_MESH
+ void onMeshLevelingStart() { ScreenHandler.OnMeshLevelingStart(); }
+
+ void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
+ ScreenHandler.OnMeshLevelingUpdate(xpos, ypos);
+ }
+ void onMeshUpdate(const int8_t xpos, const int8_t ypos, const ExtUI::probe_state_t state) {
+ // Only called for UBL
+ if (state == MESH_START) ScreenHandler.OnMeshLevelingStart();
+ ScreenHandler.OnMeshLevelingUpdate(xpos, ypos);
+ }
+ #endif
+
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ void onPowerLossResume() {
+ // Called on resume from power-loss
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POWER_LOSS);
+ }
+ #endif
+
+
+ #if HAS_PID_HEATING
+ void onPidTuning(const result_t rst) {
+ // Called for temperature PID tuning result
+ // switch (rst) {
+ // case PID_BAD_EXTRUDER_NUM:
+ // ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_BAD_EXTRUDER_NUM));
+ // break;
+ // case PID_TEMP_TOO_HIGH:
+ // ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_TEMP_TOO_HIGH));
+ // break;
+ // case PID_TUNING_TIMEOUT:
+ // ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_TIMEOUT));
+ // break;
+ // case PID_DONE:
+ // ScreenHandler.setstatusmessagePGM(GET_TEXT(MSG_PID_AUTOTUNE_DONE));
+ // break;
+ // }
+ // ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
+ }
+ #endif
+
+ void onSteppersDisabled() { ScreenHandler.HandleStepperState(false); }
+ void onSteppersEnabled() { ScreenHandler.HandleStepperState(true); }
+
+}
+#endif // HAS_DGUS_LCD
diff --git a/Marlin/src/lcd/extui/dgus_lcd.cpp b/Marlin/src/lcd/extui/dgus_lcd.cpp
index d175b5acac..b01c3de15a 100644
--- a/Marlin/src/lcd/extui/dgus_lcd.cpp
+++ b/Marlin/src/lcd/extui/dgus_lcd.cpp
@@ -28,7 +28,7 @@
#include "../../inc/MarlinConfigPre.h"
-#if HAS_DGUS_LCD
+#if HAS_DGUS_LCD && DISABLED(DGUS_LCD_UI_CREALITY_TOUCH)
#include "ui_api.h"
#include "lib/dgus/DGUSDisplay.h"
@@ -76,7 +76,12 @@ namespace ExtUI {
void onStatusChanged(const char * const msg) { ScreenHandler.setstatusmessage(msg); }
+ void onHomingStart() {}
+ void onHomingComplete() {}
+ void onPrintFinished() {}
+
void onFactoryReset() {}
+
void onStoreSettings(char *buff) {
// Called when saving to EEPROM (i.e. M500). If the ExtUI needs
// permanent data to be stored, it can write up to eeprom_data_size bytes
@@ -108,6 +113,8 @@ namespace ExtUI {
}
#if HAS_MESH
+ void onMeshLevelingStart() {}
+
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
// Called when any mesh points are updated
}
@@ -146,5 +153,8 @@ namespace ExtUI {
}
#endif
+ void onSteppersDisabled() {}
+ void onSteppersEnabled() {}
}
+
#endif // HAS_DGUS_LCD
diff --git a/Marlin/src/lcd/extui/example.cpp b/Marlin/src/lcd/extui/example.cpp
index 592d67214d..dd4b3312eb 100644
--- a/Marlin/src/lcd/extui/example.cpp
+++ b/Marlin/src/lcd/extui/example.cpp
@@ -47,9 +47,9 @@ namespace ExtUI {
}
void onIdle() {}
void onPrinterKilled(PGM_P const error, PGM_P const component) {}
- void onMediaInserted() {};
- void onMediaError() {};
- void onMediaRemoved() {};
+ void onMediaInserted() {}
+ void onMediaError() {}
+ void onMediaRemoved() {}
void onPlayTone(const uint16_t frequency, const uint16_t duration) {}
void onPrintTimerStarted() {}
void onPrintTimerPaused() {}
@@ -57,6 +57,11 @@ namespace ExtUI {
void onFilamentRunout(const extruder_t extruder) {}
void onUserConfirmRequired(const char * const msg) {}
void onStatusChanged(const char * const msg) {}
+
+ void onHomingStart() {}
+ void onHomingComplete() {}
+ void onPrintFinished() {}
+
void onFactoryReset() {}
void onStoreSettings(char *buff) {
@@ -90,6 +95,8 @@ namespace ExtUI {
}
#if HAS_MESH
+ void onMeshLevelingStart() {}
+
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {
// Called when any mesh points are updated
}
@@ -110,6 +117,9 @@ namespace ExtUI {
// Called for temperature PID tuning result
}
#endif
+
+ void onSteppersDisabled() {}
+ void onSteppersEnabled() {}
}
#endif // EXTUI_EXAMPLE && EXTENSIBLE_UI
diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp
index 8577b76ce6..4ff35d0f83 100644
--- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp
+++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplay.cpp
@@ -24,7 +24,7 @@
#include "../../../../inc/MarlinConfigPre.h"
-#if HAS_DGUS_LCD
+#if HAS_DGUS_LCD && DISABLED(DGUS_LCD_UI_CREALITY_TOUCH)
#if HOTENDS > 2
#error "More than 2 hotends not implemented on the Display UI design."
diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h
index b34a04875d..19ddc5e9bf 100644
--- a/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h
+++ b/Marlin/src/lcd/extui/lib/dgus/DGUSDisplayDef.h
@@ -21,7 +21,7 @@
*/
#pragma once
-/* DGUS implementation written by coldtobi in 2019 for Marlin */
+/* DGUS implementation written by Sebastiaan Dammann in 2020 for Marlin */
#include "DGUSVPVariable.h"
@@ -51,4 +51,6 @@ extern const struct DGUS_VP_Variable ListOfVP[];
#include "fysetc/DGUSDisplayDef.h"
#elif ENABLED(DGUS_LCD_UI_HIPRECY)
#include "hiprecy/DGUSDisplayDef.h"
+#elif ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+ #include "creality/DGUSDisplayDef.h"
#endif
diff --git a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp
index 7988985c2e..7d105e551a 100644
--- a/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp
+++ b/Marlin/src/lcd/extui/lib/dgus/DGUSScreenHandler.cpp
@@ -22,7 +22,7 @@
#include "../../../../inc/MarlinConfigPre.h"
-#if HAS_DGUS_LCD
+#if HAS_DGUS_LCD && DISABLED(DGUS_LCD_UI_CREALITY_TOUCH)
#include "DGUSScreenHandler.h"
#include "DGUSDisplay.h"
diff --git a/Marlin/src/lcd/extui/lib/dgus/creality/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/creality/DGUSDisplayDef.cpp
new file mode 100644
index 0000000000..11c778f932
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus/creality/DGUSDisplayDef.cpp
@@ -0,0 +1,509 @@
+/**
+ * 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 .
+ *
+ */
+
+/* DGUS implementation written by Sebastiaan Dammann in 2020 for Marlin */
+
+#include "../../../../../inc/MarlinConfigPre.h"
+
+#if ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+
+#include "DGUSDisplayDef.h"
+#include "../DGUSDisplay.h"
+#include "../DGUSScreenHandler.h"
+
+#include "../../../../../module/temperature.h"
+#include "../../../../../module/motion.h"
+#include "../../../../../module/planner.h"
+
+#include "../../../../../feature/caselight.h"
+
+#include "../../../../marlinui.h"
+#include "../../../ui_api.h"
+
+#include "PageHandlers.h"
+
+#if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
+ uint16_t distanceToMove = 10;
+#endif
+using namespace ExtUI;
+
+const char MarlinVersion[] PROGMEM = SHORT_BUILD_VERSION;
+
+// ----- Which variables to auto-update on which screens
+const uint16_t VPList_None[] PROGMEM = {
+ 0x0000
+};
+
+const uint16_t VPList_DialogStop[] PROGMEM = {
+ 0x0000
+};
+
+const uint16_t VPList_Main[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+ #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
+ VP_PrintProgress_Percentage,
+ #endif
+ 0x0000
+};
+
+const uint16_t VPList_SDFileList[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+ #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
+ VP_PrintProgress_Percentage,
+ #endif
+
+ VP_SD_FileName0,
+ VP_SD_FileName1,
+ VP_SD_FileName2,
+ VP_SD_FileName3,
+ VP_SD_FileName4,
+ VP_SD_FileName5,
+
+ 0x0000
+};
+
+const uint16_t VPList_Control[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+ #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
+ VP_PrintProgress_Percentage,
+ #endif
+
+ VP_LED_TOGGLE,
+
+ 0x0000
+};
+
+const uint16_t VPList_Feed[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+
+ 0x0000
+};
+
+const uint16_t VPList_Temp[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+ #if ENABLED(LCD_SET_PROGRESS_MANUALLY)
+ VP_PrintProgress_Percentage,
+ #endif
+
+ VP_FAN_TOGGLE,
+
+ 0x0000
+};
+
+
+const uint16_t VPList_PreheatPLASettings[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_PREHEAT_PLA_HOTEND_TEMP,
+ VP_PREHEAT_PLA_BED_TEMP,
+
+ 0x0000
+};
+
+const uint16_t VPList_PreheatABSSettings[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_PREHEAT_ABS_HOTEND_TEMP,
+ VP_PREHEAT_ABS_BED_TEMP,
+
+ 0x0000
+};
+
+
+const uint16_t VPList_PrintPausingError[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_PrintProgress_Percentage,
+ VP_PrintTimeProgressBar,
+ VP_PrintTime,
+
+ 0x0000
+};
+
+const uint16_t VPList_PrintScreen[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ VP_M117,
+
+ VP_PrintTime,
+
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_PrintProgress_Percentage,
+ VP_PrintTimeProgressBar,
+ VP_PrintTime,
+
+ 0x0000
+};
+
+const uint16_t VPList_Leveling[] PROGMEM = {
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_MESH_LEVEL_TEMP,
+ VP_MESH_LEVEL_STATUS,
+
+ 0x0000
+};
+
+const uint16_t VPList_ZOffsetLevel[] PROGMEM = {
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ 0x0000
+};
+
+const uint16_t VPList_TuneScreen[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ VP_M117,
+
+ VP_PrintTime,
+
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_LED_TOGGLE,
+ VP_FAN_TOGGLE,
+
+
+ 0x0000
+};
+
+const uint16_t VPList_Prepare[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ VP_M117,
+
+ VP_PrintTime,
+
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_STEPPERS,
+
+ 0x0000
+};
+
+const uint16_t VPList_Info[] PROGMEM = {
+ /* VP_M117, for completeness, but it cannot be auto-uploaded. */
+ VP_M117,
+
+ VP_PrintTime,
+
+ #if HOTENDS >= 1
+ VP_T_E0_Is, VP_T_E0_Set,// VP_E0_STATUS,
+ #endif
+ #if HAS_HEATED_BED
+ VP_T_Bed_Is, VP_T_Bed_Set,// VP_BED_STATUS,
+ #endif
+ /*VP_XPos, VP_YPos,*/ VP_ZPos,
+ //VP_Fan0_Percentage,
+ VP_Feedrate_Percentage,
+
+ VP_PRINTER_BEDSIZE,
+ VP_MARLIN_VERSION,
+
+ 0x0000
+};
+
+// Toggle button handler
+void DGUSCrealityDisplay_HandleToggleButton(DGUS_VP_Variable &var, void *val_ptr) {
+ switch (*(uint16_t*)var.memadr) {
+ case ICON_TOGGLE_ON:
+ *((bool*)var.memadr) = true;
+ break;
+
+ case ICON_TOGGLE_OFF:
+ *((bool*)var.memadr) = true;
+ break;
+ }
+}
+
+void DGUSCrealityDisplay_SendToggleButton(DGUS_VP_Variable &var) {
+ dgusdisplay.WriteVariable(var.VP, *(bool*)var.memadr ? ICON_TOGGLE_ON : ICON_TOGGLE_OFF);
+}
+
+// -- Mapping from screen to variable list
+const struct VPMapping VPMap[] PROGMEM = {
+ { DGUSLCD_SCREEN_BOOT, VPList_None },
+ { DGUSLCD_SCREEN_MAIN, VPList_Main },
+
+ { DGUSLCD_SCREEN_SDFILELIST, VPList_SDFileList },
+
+ { DGUSLCD_SCREEN_FILAMENTRUNOUT1, VPList_PrintPausingError },
+ { DGUSLCD_SCREEN_FILAMENTRUNOUT2, VPList_PrintPausingError },
+
+ { DGUSLCD_SCREEN_PRINT_FINISH, VPList_PrintScreen },
+ { DGUSLCD_SCREEN_PRINT_RUNNING, VPList_PrintScreen },
+ { DGUSLCD_SCREEN_PRINT_PAUSED, VPList_PrintScreen },
+
+ { DGUSLCD_SCREEN_TUNING, VPList_TuneScreen },
+ { DGUSLCD_SCREEN_PREPARE, VPList_Prepare },
+
+ { DGUSLCD_SCREEN_INFO, VPList_Info },
+
+ { DGUSLCD_SCREEN_MOVE1MM, VPList_PrintScreen },
+ { DGUSLCD_SCREEN_MOVE10MM, VPList_PrintScreen },
+ { DGUSLCD_SCREEN_MOVE01MM, VPList_PrintScreen },
+
+ { DGUSLCD_SCREEN_FEED, VPList_Feed },
+ { DGUSLCD_SCREEN_CONTROL, VPList_Control },
+
+ { DGUSLCD_SCREEN_TEMP, VPList_Temp },
+ { DGUSLCD_SCREEN_TEMP_PLA, VPList_PreheatPLASettings },
+ { DGUSLCD_SCREEN_TEMP_ABS, VPList_PreheatABSSettings },
+
+ { DGUSLCD_SCREEN_INFO, VPList_PrintScreen },
+ { DGUSLCD_SCREEN_ZOFFSET_LEVEL, VPList_ZOffsetLevel },
+ { DGUSLCD_SCREEN_LEVELING, VPList_Leveling },
+
+ { DGUSLCD_SCREEN_POWER_LOSS, VPList_None },
+ { DGUSLCD_SCREEN_THERMAL_RUNAWAY, VPList_None },
+ { DGUSLCD_SCREEN_HEATING_FAILED, VPList_None },
+ { DGUSLCD_SCREEN_THERMISTOR_ERROR, VPList_None },
+
+ { DGUSLCD_SCREEN_AUTOHOME, VPList_None },
+
+ { DGUSLCD_SCREEN_DIALOG_PAUSE, VPList_None },
+ { DGUSLCD_SCREEN_DIALOG_STOP, VPList_DialogStop },
+
+ { DGUSLCD_SCREEN_CONFIRM, VPList_None },
+ { DGUSLCD_SCREEN_POPUP, VPList_None },
+
+
+ { 0 , nullptr } // List is terminated with an nullptr as table entry.
+};
+
+// Helper to define a DGUS_VP_Variable for common use cases.
+#define VPHELPER(VPADR, VPADRVAR, RXFPTR, TXFPTR ) { .VP=VPADR, .memadr=VPADRVAR, .size=sizeof(VPADRVAR), \
+ .set_by_display_handler = RXFPTR, .send_to_display_handler = TXFPTR }
+
+// Helper to define a DGUS_VP_Variable when the sizeo of the var cannot be determined automaticalyl (eg. a string)
+#define VPHELPER_STR(VPADR, VPADRVAR, STRLEN, RXFPTR, TXFPTR ) { .VP=VPADR, .memadr=VPADRVAR, .size=STRLEN, \
+ .set_by_display_handler = RXFPTR, .send_to_display_handler = TXFPTR }
+
+const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
+ // TODO:
+
+ #if HOTENDS >= 1
+ VPHELPER(VP_T_E0_Is, &thermalManager.temp_hotend[0].celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>),
+ VPHELPER(VP_T_E0_Set, &thermalManager.temp_hotend[0].target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
+ #endif
+
+ #if HAS_HEATED_BED
+ VPHELPER(VP_T_Bed_Is, &thermalManager.temp_bed.celsius, nullptr, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<0>),
+ VPHELPER(VP_T_Bed_Set, &thermalManager.temp_bed.target, ScreenHandler.HandleTemperatureChanged, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
+ #endif
+
+ VPHELPER(VP_MESH_LEVEL_TEMP, &thermalManager.temp_hotend[0].target, nullptr, &ScreenHandler.DGUSLCD_SendWordValueToDisplay),
+ VPHELPER(VP_MESH_LEVEL_STATUS, nullptr, nullptr, nullptr),
+
+ // Feedrate
+ VPHELPER(VP_Feedrate_Percentage, &feedrate_percentage, ScreenHandler.DGUSLCD_SetValueDirectly, &ScreenHandler.DGUSLCD_SendWordValueToDisplay ),
+
+ VPHELPER(VP_PrintProgress_Percentage, nullptr, nullptr, ScreenHandler.DGUSLCD_SendPrintProgressToDisplay),
+ VPHELPER(VP_PrintTimeProgressBar, nullptr, nullptr, ScreenHandler.DGUSLCD_SendPrintProgressToDisplay),
+
+ // Preheat settings
+ #ifdef PREHEAT_1_LABEL
+ VPHELPER(VP_PREHEAT_PLA_HOTEND_TEMP, &ui.material_preset[0].hotend_temp, ScreenHandler.DGUSLCD_SetValueDirectly, &ScreenHandler.DGUSLCD_SendWordValueToDisplay ),
+ VPHELPER(VP_PREHEAT_PLA_BED_TEMP, &ui.material_preset[0].bed_temp, ScreenHandler.DGUSLCD_SetValueDirectly, &ScreenHandler.DGUSLCD_SendWordValueToDisplay ),
+ #endif
+
+ #ifdef PREHEAT_2_LABEL
+ VPHELPER(VP_PREHEAT_ABS_HOTEND_TEMP, &ui.material_preset[1].hotend_temp, ScreenHandler.DGUSLCD_SetValueDirectly, &ScreenHandler.DGUSLCD_SendWordValueToDisplay ),
+ VPHELPER(VP_PREHEAT_ABS_BED_TEMP, &ui.material_preset[1].bed_temp, ScreenHandler.DGUSLCD_SetValueDirectly, &ScreenHandler.DGUSLCD_SendWordValueToDisplay ),
+ #endif
+
+ // About info
+ VPHELPER(VP_MARLIN_VERSION, nullptr, nullptr, ScreenHandler.DGUSLCD_SendAboutFirmwareVersion),
+ VPHELPER(VP_PRINTER_BEDSIZE, nullptr, nullptr, ScreenHandler.DGUSLCD_SendAboutPrintSize),
+
+ // Position Data
+ //VPHELPER(VP_XPos, ¤t_position.x, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
+ //VPHELPER(VP_YPos, ¤t_position.y, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
+ //VPHELPER(VP_YPos, ¤t_position.y, nullptr, ScreenHandler.DGUSLCD_SendFloatAsLongValueToDisplay<2>),
+
+ VPHELPER(VP_ZPos, &probe.offset.z, ScreenHandler.HandleZoffsetChange, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<2>),
+
+ VPHELPER(VP_FAN_TOGGLE, &thermalManager.fan_speed[0], ScreenHandler.HandleFanControl, ScreenHandler.DGUSLCD_SendFanStatusToDisplay),
+
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ VPHELPER(VP_POWER_LOSS_RECOVERY, nullptr, &ScreenHandler.HandlePowerLossRecovery, nullptr),
+ #endif
+
+ VPHELPER_STR(VP_PrintTime, nullptr, VP_PrintTime_LEN, nullptr, ScreenHandler.DGUSLCD_SendPrintTimeToDisplay ),
+ VPHELPER(VP_SCREENCHANGE, nullptr, ScreenHandler.ScreenChangeHook, nullptr),
+ VPHELPER(VP_CONFIRMED, nullptr, ScreenHandler.ScreenConfirmedOK, nullptr),
+
+ // Feed
+ VPHELPER(VP_FEED_AMOUNT, &ScreenHandler.feed_amount, ScreenHandler.HandleFeedAmountChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<2>),
+
+ // Creality has the same button ID mapped all over the place, so let the generic handler figure it out
+ VPHELPER(VP_BUTTON_MAINENTERKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_ADJUSTENTERKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_PREPAREENTERKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_RESUMEPRINTKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_SELECTFILEKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_STARTPRINTKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_STOPPRINTKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_PAUSEPRINTKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_COOLDOWN, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_TEMPCONTROL, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_BEDLEVELKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+ VPHELPER(VP_BUTTON_HEATLOADSTARTKEY, nullptr, DGUSCrealityDisplay_HandleReturnKeyEvent, nullptr),
+
+ // File listing
+ VPHELPER(VP_SD_ScrollEvent, nullptr, ScreenHandler.DGUSLCD_SD_ScrollFilelist, nullptr),
+ VPHELPER(VP_SD_FileSelected, nullptr, ScreenHandler.DGUSLCD_SD_FileSelected, nullptr),
+ VPHELPER(VP_SD_FileSelectConfirm, nullptr, ScreenHandler.DGUSLCD_SD_StartPrint, nullptr),
+ VPHELPER_STR(VP_SD_FileName0, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
+ VPHELPER_STR(VP_SD_FileName1, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
+ VPHELPER_STR(VP_SD_FileName2, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
+ VPHELPER_STR(VP_SD_FileName3, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
+ VPHELPER_STR(VP_SD_FileName4, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
+ VPHELPER_STR(VP_SD_FileName5, nullptr, VP_SD_FileName_LEN, nullptr, ScreenHandler.DGUSLCD_SD_SendFilename ),
+
+ // Icons
+ VPHELPER(VP_STEPPERS, &ScreenHandler.are_steppers_enabled, nullptr, (ScreenHandler.DGUSLCD_SendIconValue)),
+ VPHELPER(VP_LED_TOGGLE, &caselight.on, nullptr, (ScreenHandler.DGUSLCD_SendIconValue)),
+
+ // M117 LCD String (We don't need the string in memory but "just" push it to the display on demand, hence the nullptr
+ { .VP = VP_M117, .memadr = nullptr, .size = VP_M117_LEN, .set_by_display_handler = nullptr, .send_to_display_handler =&ScreenHandler.DGUSLCD_SendStringToDisplay },
+
+ // Messages for the User, shared by the popup and the kill screen. They cant be autouploaded as we do not buffer content.
+ { .VP = VP_MSGSTR1, .memadr = nullptr, .size = VP_MSGSTR1_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
+ { .VP = VP_MSGSTR2, .memadr = nullptr, .size = VP_MSGSTR2_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
+ { .VP = VP_MSGSTR3, .memadr = nullptr, .size = VP_MSGSTR3_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
+ //{ .VP = VP_MSGSTR4, .memadr = nullptr, .size = VP_MSGSTR4_LEN, .set_by_display_handler = nullptr, .send_to_display_handler = &ScreenHandler.DGUSLCD_SendStringToDisplayPGM },
+
+ VPHELPER(0, 0, 0, 0) // must be last entry.
+};
+
+#endif // DGUS_LCD_UI_ORIGIN
diff --git a/Marlin/src/lcd/extui/lib/dgus/creality/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus/creality/DGUSDisplayDef.h
new file mode 100644
index 0000000000..a5a6967129
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus/creality/DGUSDisplayDef.h
@@ -0,0 +1,357 @@
+/**
+ * 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 "../DGUSDisplayDef.h"
+
+enum DGUSLCD_Screens : uint8_t {
+ DGUSLCD_SCREEN_BOOT = 0,
+
+ DGUSLCD_SCREEN_MAIN = 28,
+
+ DGUSLCD_SCREEN_CONFIRM = 66,
+ DGUSLCD_SCREEN_SDPRINTMANIPULATION = 37 ,
+ DGUSLCD_SCREEN_SDPRINTTUNE = 41,
+ DGUSLCD_SCREEN_SDFILELIST = 67,
+
+ DGUSLCD_SCREEN_FILAMENTRUNOUT1 = 34, // DWINTouchPage::ERR_FILAMENTRUNOUT_HOTEND_COLD
+ DGUSLCD_SCREEN_FILAMENTRUNOUT2 = 35, // DWINTouchPage::ERR_FILAMENTRUNOUT_FILAMENT_LOADED
+
+ DGUSLCD_SCREEN_PRINT_FINISH = 36, // DWINTouchPage::PRINT_FINISHED
+ DGUSLCD_SCREEN_PRINT_RUNNING = 37, // DWINTouchPage::PRINT_PROGRESS_RUNNING
+ DGUSLCD_SCREEN_PRINT_PAUSED = 39, // DWINTouchPage::PRINT_PROGRESS_PAUSED
+
+ DGUSLCD_SCREEN_DIALOG_PAUSE = 38, // DWINTouchPage::DIALOG_PAUSE_PRINTING
+ DGUSLCD_SCREEN_DIALOG_STOP = 40, // DWINTouchPage::DIALOG_STOP_PRINTING
+
+ DGUSLCD_SCREEN_TUNING = 41, // DWINTouchPage::MENU_TUNING
+ DGUSLCD_SCREEN_PREPARE = 42, // DWINTouchPage::MENU_PREPARE
+
+ DGUSLCD_SCREEN_MOVE1MM = 43, // DWINTouchPage::MOVE_1MM
+ DGUSLCD_SCREEN_MOVE10MM = 44, // DWINTouchPage::MOVE_10MM
+ DGUSLCD_SCREEN_MOVE01MM = 45, // DWINTouchPage::MOVE_01MM
+
+ DGUSLCD_SCREEN_FEED = 46, // DWINTouchPage::FEED
+ DGUSLCD_SCREEN_CONTROL = 47, // DWINTouchPage::MENU_CONTROL
+
+ DGUSLCD_SCREEN_TEMP = 48, // DWINTouchPage::MENU_TEMP
+ DGUSLCD_SCREEN_TEMP_PLA = 49, // DWINTouchPage::MENU_PLA_TEMP
+ DGUSLCD_SCREEN_TEMP_ABS = 50, // DWINTouchPage::MENU_ABS_TEMP
+
+ DGUSLCD_SCREEN_INFO = 51, // DWINTouchPage::MENU_ABOUT
+
+ DGUSLCD_SCREEN_ZOFFSET_LEVEL = 52, // DWINTouchPage::MENU_ZOFFSET_LEVELING
+ DGUSLCD_SCREEN_LEVELING = 53, // DWINTouchPage::LEVELING
+
+ DGUSLCD_SCREEN_POWER_LOSS = 54, // DWINTouchPage::DIALOG_POWER_FAILURE
+ DGUSLCD_SCREEN_THERMAL_RUNAWAY = 57, // DWINTouchPage::ERR_THERMAL_RUNAWAY
+ DGUSLCD_SCREEN_HEATING_FAILED = 58, // DWINTouchPage::ERR_HEATING_FAILED
+ DGUSLCD_SCREEN_THERMISTOR_ERROR = 59, // DWINTouchPage::ERR_THERMISTOR
+
+ DGUSLCD_SCREEN_AUTOHOME = 61, // DWINTouchPage::AUTOHOME_IN_PROGRESS
+
+ DGUSLCD_SCREEN_POPUP = 63, // NEW - does not exist in original display
+ DGUSLCD_SCREEN_KILL = 64, // NEW - does not exist in original display
+};
+
+// Display Memory layout used (T5UID)
+// Except system variables this is arbitrary, just to organize stuff....
+
+// 0x0000 .. 0x0FFF -- System variables and reserved by the display
+// 0x1000 .. 0x1FFF -- Variables to never change location, regardless of UI Version
+// 0x2000 .. 0x2FFF -- Controls (VPs that will trigger some action)
+// 0x3000 .. 0x4FFF -- Marlin Data to be displayed
+// 0x5000 .. -- SPs (if we want to modify display elements, e.g change color or like) -- currently unused
+
+// As there is plenty of space (at least most displays have >8k RAM), we do not pack them too tight,
+// so that we can keep variables nicely together in the address space.
+
+// UI Version always on 0x1000...0x1002 so that the firmware can check this and bail out.
+// constexpr uint16_t VP_UI_VERSION_MAJOR = 0x1000; // Major -- incremented when incompatible
+// constexpr uint16_t VP_UI_VERSION_MINOR = 0x1001; // Minor -- incremented on new features, but compatible
+// constexpr uint16_t VP_UI_VERSION_PATCH = 0x1002; // Patch -- fixed which do not change functionality.
+// constexpr uint16_t VP_UI_FLAVOUR = 0x1010; // lets reserve 16 bytes here to determine if UI is suitable for this Marlin. tbd.
+
+#define VP_STARTPROGRESSBAR 0x1000
+
+// // Storage space for the Killscreen messages. Reused for the popup.
+constexpr uint16_t VP_MSGSTR1 = 0x2010;
+constexpr uint8_t VP_MSGSTR1_LEN = 0x20; // might be more place for it...
+constexpr uint16_t VP_MSGSTR2 = 0x2030;
+constexpr uint8_t VP_MSGSTR2_LEN = 0x40;
+constexpr uint16_t VP_MSGSTR3 = 0x2070;
+constexpr uint8_t VP_MSGSTR3_LEN = 0x40;
+//constexpr uint16_t VP_MSGSTR4 = 0x11C0;
+// constexpr uint8_t VP_MSGSTR4_LEN = 0x20;
+
+// // Screenchange request for screens that only make sense when printer is idle.
+// // e.g movement is only allowed if printer is not printing.
+// // Marlin must confirm by setting the screen manually.
+// constexpr uint16_t VP_SCREENCHANGE_ASK = 0x2000;
+constexpr uint16_t VP_SCREENCHANGE = 0x219f; // Key-Return button to new menu pressed. Data contains target screen in low byte and info in high byte.
+// constexpr uint16_t VP_TEMP_ALL_OFF = 0x2002; // Turn all heaters off. Value arbitrary ;)=
+// constexpr uint16_t VP_SCREENCHANGE_WHENSD = 0x2003; // "Print" Button touched -- go only there if there is an SD Card.
+
+constexpr uint16_t VP_CONFIRMED = 0x219E; // OK on confirm screen.
+
+// // Buttons on the SD-Card File listing.
+// constexpr uint16_t VP_SD_ScrollEvent = 0x2020; // Data: 0 for "up a directory", numbers are the amount to scroll, e.g -1 one up, 1 one down
+// constexpr uint16_t VP_SD_FileSelected = 0x2022; // Number of file field selected.
+constexpr uint16_t VP_SD_FileSelectConfirm = 0x2024; // (This is a virtual VP and emulated by the Confirm Screen when a file has been confirmed)
+
+// constexpr uint16_t VP_SD_ResumePauseAbort = 0x2026; // Resume(Data=0), Pause(Data=1), Abort(Data=2) SD Card prints
+constexpr uint16_t VP_SD_AbortPrintConfirmed = 0x2028; // Abort print confirmation (virtual, will be injected by the confirm dialog)
+// constexpr uint16_t VP_SD_Print_Setting = 0x2040;
+// constexpr uint16_t VP_SD_Print_LiveAdjustZ = 0x2050; // Data: 0 down, 1 up
+
+// // Controls for movement (we can't use the incremental / decremental feature of the display at this feature works only with 16 bit values
+// // (which would limit us to 655.35mm, which is likely not a problem for common setups, but i don't want to rule out hangprinters support)
+// // A word about the coding: The VP will be per axis and the return code will be an signed 16 bit value in 0.01 mm resolution, telling us
+// // the relative travel amount t he user wants to do. So eg. if the display sends us VP=2100 with value 100, the user wants us to move X by +1 mm.
+constexpr uint16_t VP_MOVE_X = 0x2100;
+constexpr uint16_t VP_MOVE_Y = 0x2102;
+constexpr uint16_t VP_MOVE_Z = 0x2104;
+constexpr uint16_t VP_MOVE_E0 = 0x2110;
+// constexpr uint16_t VP_MOVE_E1 = 0x2112;
+// //constexpr uint16_t VP_MOVE_E2 = 0x2114;
+// //constexpr uint16_t VP_MOVE_E3 = 0x2116;
+// //constexpr uint16_t VP_MOVE_E4 = 0x2118;
+// //constexpr uint16_t VP_MOVE_E5 = 0x211A;
+constexpr uint16_t VP_HOME_ALL = 0x2120;
+// constexpr uint16_t VP_MOTOR_LOCK_UNLOK = 0x2130;
+
+// // Power loss recovery
+// constexpr uint16_t VP_POWER_LOSS_RECOVERY = 0x2180;
+
+// // Fan Control Buttons , switch between "off" and "on"
+// constexpr uint16_t VP_FAN0_CONTROL = 0x2200;
+// constexpr uint16_t VP_FAN1_CONTROL = 0x2202;
+// //constexpr uint16_t VP_FAN2_CONTROL = 0x2204;
+// //constexpr uint16_t VP_FAN3_CONTROL = 0x2206;
+
+// // Heater Control Buttons , triged between "cool down" and "heat PLA" state
+constexpr uint16_t VP_E0_CONTROL = 0x2210;
+// constexpr uint16_t VP_E1_CONTROL = 0x2212;
+// //constexpr uint16_t VP_E2_CONTROL = 0x2214;
+// //constexpr uint16_t VP_E3_CONTROL = 0x2216;
+// //constexpr uint16_t VP_E4_CONTROL = 0x2218;
+// //constexpr uint16_t VP_E5_CONTROL = 0x221A;
+constexpr uint16_t VP_BED_CONTROL = 0x221C;
+
+// // Preheat
+// constexpr uint16_t VP_E0_BED_PREHEAT = 0x2220;
+// constexpr uint16_t VP_E1_BED_CONTROL = 0x2222;
+// //constexpr uint16_t VP_E2_BED_CONTROL = 0x2224;
+// //constexpr uint16_t VP_E3_BED_CONTROL = 0x2226;
+// //constexpr uint16_t VP_E4_BED_CONTROL = 0x2228;
+// //constexpr uint16_t VP_E5_BED_CONTROL = 0x222A;
+
+// // Filament load and unload
+// constexpr uint16_t VP_E0_FILAMENT_LOAD_UNLOAD = 0x2300;
+// constexpr uint16_t VP_E1_FILAMENT_LOAD_UNLOAD = 0x2302;
+
+// // Settings store , reset
+// constexpr uint16_t VP_SETTINGS = 0x2400;
+
+// // PID autotune
+constexpr uint16_t VP_PID_AUTOTUNE_E0 = 0x2410;
+// //constexpr uint16_t VP_PID_AUTOTUNE_E1 = 0x2412;
+// //constexpr uint16_t VP_PID_AUTOTUNE_E2 = 0x2414;
+// //constexpr uint16_t VP_PID_AUTOTUNE_E3 = 0x2416;
+// //constexpr uint16_t VP_PID_AUTOTUNE_E4 = 0x2418;
+// //constexpr uint16_t VP_PID_AUTOTUNE_E5 = 0x241A;
+constexpr uint16_t VP_PID_AUTOTUNE_BED = 0x2420;
+
+// // Firmware version on the boot screen.
+constexpr uint16_t VP_PRINTER_BEDSIZE = 0x1074;
+constexpr uint16_t VP_PRINTER_BEDSIZE_LEN = 12;
+constexpr uint16_t VP_MARLIN_VERSION = 0x2222;
+constexpr uint8_t VP_MARLIN_VERSION_LEN = 20; // there is more space on the display, if needed.
+
+// Material preheat settings
+constexpr uint16_t VP_PREHEAT_PLA_HOTEND_TEMP = 0x1102;
+constexpr uint16_t VP_PREHEAT_PLA_BED_TEMP = 0x1104;
+
+constexpr uint16_t VP_PREHEAT_ABS_HOTEND_TEMP = 0x1108;
+constexpr uint16_t VP_PREHEAT_ABS_BED_TEMP = 0x110a;
+
+// // Place for status messages.
+constexpr uint16_t VP_M117 = 0x21B3;
+constexpr uint8_t VP_M117_LEN = 0x20;
+
+// // Temperatures.
+constexpr uint16_t VP_T_E0_Is = 0x1036; // 4 Byte Integer - HEAD_CURRENT_TEMP_VP
+constexpr uint16_t VP_T_E0_Set = 0x1034; // 2 Byte Integer - HEAD_SET_TEMP_VP
+// constexpr uint16_t VP_T_E1_Is = 0x3064; // 4 Byte Integer
+
+// // reserved to support up to 6 Extruders:
+// //constexpr uint16_t VP_T_E1_Set = 0x3066; // 2 Byte Integer
+// //constexpr uint16_t VP_T_E2_Is = 0x3068; // 4 Byte Integer
+// //constexpr uint16_t VP_T_E2_Set = 0x306A; // 2 Byte Integer
+// //constexpr uint16_t VP_T_E3_Is = 0x306C; // 4 Byte Integer
+// //constexpr uint16_t VP_T_E3_Set = 0x306E; // 2 Byte Integer
+// //constexpr uint16_t VP_T_E4_Is = 0x3070; // 4 Byte Integer
+// //constexpr uint16_t VP_T_E4_Set = 0x3072; // 2 Byte Integer
+// //constexpr uint16_t VP_T_E4_Is = 0x3074; // 4 Byte Integer
+// //constexpr uint16_t VP_T_E4_Set = 0x3076; // 2 Byte Integer
+// //constexpr uint16_t VP_T_E5_Is = 0x3078; // 4 Byte Integer
+// //constexpr uint16_t VP_T_E5_Set = 0x307A; // 2 Byte Integer
+
+constexpr uint16_t VP_T_Bed_Is = 0x103c; // 4 Byte Integer - BED_SET_TEMP_VP
+constexpr uint16_t VP_T_Bed_Set = 0x103A; // 2 Byte Integer - BED_CURRENT_TEMP_VP
+
+constexpr uint16_t VP_Flowrate_E0 = 0x3090; // 2 Byte Integer
+// constexpr uint16_t VP_Flowrate_E1 = 0x3092; // 2 Byte Integer
+
+// constexpr uint16_t VP_Fan0_Percentage = 0x3100; // 2 Byte Integer (0..100)
+// constexpr uint16_t VP_Fan1_Percentage = 0x33A2; // 2 Byte Integer (0..100)
+// //constexpr uint16_t VP_Fan2_Percentage = 0x33A4; // 2 Byte Integer (0..100)
+// //constexpr uint16_t VP_Fan3_Percentage = 0x33A6; // 2 Byte Integer (0..100)
+
+constexpr uint16_t VP_Feedrate_Percentage = 0x1006; // 2 Byte Integer (0..100) - PRINT_SPEED_RATE_VP
+constexpr uint16_t VP_PrintProgress_Percentage = 0x1016; // 2 Byte Integer (0..100)
+
+constexpr uint16_t VP_PrintTimeProgressBar = 0x100E;
+
+constexpr uint16_t VP_PrintTime = 0x21a0;
+constexpr uint16_t VP_PrintTime_LEN = 6;
+
+// constexpr uint16_t VP_PrintAccTime = 0x3160;
+// constexpr uint16_t VP_PrintAccTime_LEN = 32;
+
+// constexpr uint16_t VP_PrintsTotal = 0x3180;
+// constexpr uint16_t VP_PrintsTotal_LEN = 16;
+
+// // Actual Position
+// constexpr uint16_t VP_XPos = 0x3110; // 4 Byte Fixed point number; format xxx.yy
+// constexpr uint16_t VP_YPos = 0x3112; // 4 Byte Fixed point number; format xxx.yy
+constexpr uint16_t VP_ZPos = 0x1026; // 4 Byte Fixed point number; format xxx.yy - AUTO_BED_LEVEL_ZOFFSET_VP [SD: this is actually Z-offset?]
+
+// constexpr uint16_t VP_EPos = 0x3120; // 4 Byte Fixed point number; format xxx.yy
+
+// // SDCard File Listing
+constexpr uint16_t VP_SD_ScrollEvent = 0x20D4; // Data: 0 for "up a directory", numbers are the amount to scroll, e.g -1 one up, 1 one down
+constexpr uint16_t VP_SD_FileSelected = 0x2200; // Number of file field selected.
+constexpr uint16_t VP_SD_FileName_LEN = 21; // LEN is shared for all entries.
+constexpr uint16_t VP_SD_FileName_CNT = 6; // LEN is shared for all entries.
+constexpr uint16_t DGUS_SD_FILESPERSCREEN = VP_SD_FileName_CNT; // FIXME move that info to the display and read it from there.
+constexpr uint16_t VP_SD_FileName0 = 0x20D5;
+constexpr uint16_t VP_SD_FileName1 = VP_SD_FileName0 + VP_SD_FileName_LEN;
+constexpr uint16_t VP_SD_FileName2 = VP_SD_FileName1 + VP_SD_FileName_LEN;
+constexpr uint16_t VP_SD_FileName3 = VP_SD_FileName2 + VP_SD_FileName_LEN;
+constexpr uint16_t VP_SD_FileName4 = VP_SD_FileName3 + VP_SD_FileName_LEN;
+constexpr uint16_t VP_SD_FileName5 = VP_SD_FileName4 + VP_SD_FileName_LEN;
+
+constexpr uint16_t VP_SD_Print_ProbeOffsetZ = 0x32A0; //
+constexpr uint16_t VP_SD_Print_Filename = 0x2000; //
+
+constexpr uint16_t VP_ICON_OVERLAY_CLEAR = 10;
+constexpr uint16_t VP_ICON_OVERLAY_SELECTED = 6;
+
+// // Fan status
+// constexpr uint16_t VP_FAN0_STATUS = 0x3300;
+// constexpr uint16_t VP_FAN1_STATUS = 0x3302;
+// //constexpr uint16_t VP_FAN2_STATUS = 0x3304;
+// //constexpr uint16_t VP_FAN3_STATUS = 0x3306;
+
+// // Heater status
+// constexpr uint16_t VP_E0_STATUS = 0x3310;
+// //constexpr uint16_t VP_E1_STATUS = 0x3312;
+// //constexpr uint16_t VP_E2_STATUS = 0x3314;
+// //constexpr uint16_t VP_E3_STATUS = 0x3316;
+// //constexpr uint16_t VP_E4_STATUS = 0x3318;
+// //constexpr uint16_t VP_E5_STATUS = 0x331A;
+// constexpr uint16_t VP_BED_STATUS = 0x331C;
+
+// constexpr uint16_t VP_MOVE_OPTION = 0x3400;
+
+// // Step per mm
+constexpr uint16_t VP_X_STEP_PER_MM = 0x3600; // at the moment , 2 byte unsigned int , 0~1638.4
+// //constexpr uint16_t VP_X2_STEP_PER_MM = 0x3602;
+constexpr uint16_t VP_Y_STEP_PER_MM = 0x3604;
+// //constexpr uint16_t VP_Y2_STEP_PER_MM = 0x3606;
+constexpr uint16_t VP_Z_STEP_PER_MM = 0x3608;
+// //constexpr uint16_t VP_Z2_STEP_PER_MM = 0x360A;
+constexpr uint16_t VP_E0_STEP_PER_MM = 0x3610;
+// //constexpr uint16_t VP_E1_STEP_PER_MM = 0x3612;
+// //constexpr uint16_t VP_E2_STEP_PER_MM = 0x3614;
+// //constexpr uint16_t VP_E3_STEP_PER_MM = 0x3616;
+// //constexpr uint16_t VP_E4_STEP_PER_MM = 0x3618;
+// //constexpr uint16_t VP_E5_STEP_PER_MM = 0x361A;
+
+// // PIDs
+constexpr uint16_t VP_E0_PID_P = 0x3700; // at the moment , 2 byte unsigned int , 0~1638.4
+constexpr uint16_t VP_E0_PID_I = 0x3702;
+constexpr uint16_t VP_E0_PID_D = 0x3704;
+constexpr uint16_t VP_BED_PID_P = 0x3710;
+constexpr uint16_t VP_BED_PID_I = 0x3712;
+constexpr uint16_t VP_BED_PID_D = 0x3714;
+
+// // Wating screen status
+// constexpr uint16_t VP_WAITING_STATUS = 0x3800;
+
+// // SPs for certain variables...
+
+// // located at 0x5000 and up
+// // Not used yet!
+// // This can be used e.g to make controls / data display invisible
+// constexpr uint16_t SP_T_E0_Is = 0x5000;
+// constexpr uint16_t SP_T_E0_Set = 0x5010;
+// constexpr uint16_t SP_T_E1_Is = 0x5020;
+// constexpr uint16_t SP_T_Bed_Is = 0x5030;
+// constexpr uint16_t SP_T_Bed_Set = 0x5040;
+
+// Power loss recovery
+constexpr uint16_t VP_POWER_LOSS_RECOVERY = 0x105F;
+
+// Buttons defined by Creality - Don't worry if you're confused by the naming, so am I
+constexpr uint16_t VP_BUTTON_MAINENTERKEY = 0x1002;
+constexpr uint16_t VP_BUTTON_ADJUSTENTERKEY = 0x1004;
+constexpr uint16_t VP_BUTTON_PAUSEPRINTKEY = 0x100A;
+constexpr uint16_t VP_BUTTON_TEMPCONTROL = 0x1030;
+constexpr uint16_t VP_BUTTON_COOLDOWN = 0x1032;
+constexpr uint16_t VP_BUTTON_PREPAREENTERKEY = 0x103E;
+
+constexpr uint16_t VP_BUTTON_SELECTFILEKEY = 0x20D3;
+constexpr uint16_t VP_BUTTON_STARTPRINTKEY = 0x20D2;
+constexpr uint16_t VP_BUTTON_STOPPRINTKEY = 0x1008;
+constexpr uint16_t VP_BUTTON_RESUMEPRINTKEY = 0x100C;
+constexpr uint16_t VP_BUTTON_BEDLEVELKEY = 0x1044;
+
+constexpr uint16_t VP_BUTTON_HEATLOADSTARTKEY = 0x1056;
+
+// Additional stuff defined by Creality
+constexpr uint16_t VP_FAN_TOGGLE = 0x101E;
+constexpr uint16_t VP_LED_TOGGLE = 0x101F;
+constexpr uint16_t VP_STEPPERS = 0x1200;
+constexpr uint16_t VP_MESH_LEVEL_TEMP = 0x108A;
+constexpr uint16_t VP_MESH_LEVEL_STATUS = 0x108D;
+constexpr uint16_t VP_FEED_AMOUNT = 0x1054;
+constexpr uint16_t VP_FEED_PROGRESS = 0x108e;
+
+// Icons
+constexpr uint16_t ICON_TOGGLE_ON = 1;
+constexpr uint16_t ICON_TOGGLE_OFF = 2;
+
+
+// Additional variables to migrate later
+extern bool LEDStatus;
diff --git a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp
index ed26cac3c5..536640ec95 100644
--- a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp
+++ b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.cpp
@@ -26,7 +26,7 @@
#if ENABLED(DGUS_LCD_UI_HIPRECY)
-#include "../DGUSDisplayDef.h"
+#include "DGUSDisplayDef.h"
#include "../DGUSDisplay.h"
#include "../DGUSScreenHandler.h"
diff --git a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.h
index 3ff5e06dc1..d18989a48b 100644
--- a/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.h
+++ b/Marlin/src/lcd/extui/lib/dgus/hiprecy/DGUSDisplayDef.h
@@ -21,6 +21,8 @@
*/
#pragma once
+#include "../DGUSDisplayDef.h"
+
enum DGUSLCD_Screens : uint8_t {
DGUSLCD_SCREEN_BOOT = 160,
DGUSLCD_SCREEN_MAIN = 1,
diff --git a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp
index 46e542a959..28e66e5d7c 100644
--- a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp
+++ b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.cpp
@@ -26,7 +26,7 @@
#if ENABLED(DGUS_LCD_UI_ORIGIN)
-#include "../DGUSDisplayDef.h"
+#include "DGUSDisplayDef.h"
#include "../DGUSDisplay.h"
#include "../DGUSScreenHandler.h"
diff --git a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.h
index 451c11adba..5c5a315de6 100644
--- a/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.h
+++ b/Marlin/src/lcd/extui/lib/dgus/origin/DGUSDisplayDef.h
@@ -21,6 +21,8 @@
*/
#pragma once
+#include "../DGUSDisplayDef.h"
+
enum DGUSLCD_Screens : uint8_t {
DGUSLCD_SCREEN_BOOT = 0,
DGUSLCD_SCREEN_MAIN = 10,
diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSDisplay.cpp b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSDisplay.cpp
new file mode 100644
index 0000000000..8144f5334d
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSDisplay.cpp
@@ -0,0 +1,332 @@
+/**
+ * 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 .
+ *
+ */
+
+//#define DEBUG_DGUSLCD
+//#define DEBUG_DGUSLCD_COMM
+
+/* DGUS implementation written by coldtobi in 2019 for Marlin */
+
+#include "../../../../inc/MarlinConfigPre.h"
+
+#if ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+
+#if HOTENDS > 2
+ #error "More than 2 hotends not implemented on the Display UI design."
+#endif
+
+#include "../../ui_api.h"
+
+#include "../../../../MarlinCore.h"
+#include "../../../../module/temperature.h"
+#include "../../../../module/motion.h"
+#include "../../../../gcode/queue.h"
+#include "../../../../module/planner.h"
+#include "../../../../sd/cardreader.h"
+#include "../../../../libs/duration_t.h"
+#include "../../../../module/printcounter.h"
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+ #include "../../../../feature/powerloss.h"
+#endif
+
+#include "DGUSDisplay.h"
+#include "../dgus/DGUSVPVariable.h"
+#include "../dgus/DGUSDisplayDef.h"
+
+#define DEBUG_OUT ENABLED(DEBUG_DGUSLCD)
+#include "../../../../core/debug_out.h"
+
+#if DEBUG_DGUSLCD_COMM
+ #define DEBUGLCDCOMM_ECHOPAIR DEBUG_ECHOPAIR
+ #define DEBUGLCDCOMM_ECHOPGM DEBUG_ECHOPGM
+#else
+ #define DEBUGLCDCOMM_ECHOPAIR(...) NOOP
+ #define DEBUGLCDCOMM_ECHOPGM(...) NOOP
+#endif
+
+// Preamble... 2 Bytes, usually 0x5A 0xA5, but configurable
+constexpr uint8_t DGUS_HEADER1 = 0x5A;
+constexpr uint8_t DGUS_HEADER2 = 0xA5;
+
+constexpr uint8_t DGUS_CMD_WRITEVAR = 0x82;
+constexpr uint8_t DGUS_CMD_READVAR = 0x83;
+
+#if ENABLED(DEBUG_DGUSLCD)
+ bool dguslcd_local_debug; // = false;
+#endif
+
+void DGUSDisplay::InitDisplay() {
+ LCD_SERIAL.begin(LCD_BAUDRATE);
+ /*
+ delay(500); // Attempt to fix possible handshake error
+ ResetDisplay(); // Reset for firmware update
+ delay(500); // Attempt to fix possible handshake error
+ */
+ if (TERN1(POWER_LOSS_RECOVERY, !recovery.valid())
+ RequestScreen(TERN_(SHOW_BOOTSCREEN, DGUSLCD_SCREEN_BOOT, DGUSLCD_SCREEN_MAIN));
+}
+
+void DGUSDisplay::ResetDisplay() {
+ DEBUG_ECHOLNPGM("ResetDisplay");
+ const unsigned char resetCommand[] = { 0x55, 0xAA, 0x5A, 0xA5 };
+ WriteVariable(0x04, resetCommand, sizeof(resetCommand));
+}
+
+void DGUSDisplay::ReadVariable(uint16_t adr) {
+ WriteHeader(adr, DGUS_CMD_READVAR, sizeof(uint8_t));
+
+ // Specify to read one byte
+ LCD_SERIAL.write(static_cast(1));
+}
+
+void DGUSDisplay::WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) {
+ const char* myvalues = static_cast(values);
+ bool strend = !myvalues;
+ WriteHeader(adr, DGUS_CMD_WRITEVAR, valueslen);
+ while (valueslen--) {
+ char x;
+ if (!strend) x = *myvalues++;
+ if ((isstr && !x) || strend) {
+ strend = true;
+ x = ' ';
+ }
+ LCD_SERIAL.write(x);
+ }
+}
+
+void DGUSDisplay::WriteVariable(uint16_t adr, uint16_t value) {
+ value = (value & 0xffU) << 8U | (value >> 8U);
+ WriteVariable(adr, static_cast(&value), sizeof(uint16_t));
+}
+
+void DGUSDisplay::WriteVariable(uint16_t adr, int16_t value) {
+ value = (value & 0xffU) << 8U | (value >> 8U);
+ WriteVariable(adr, static_cast(&value), sizeof(uint16_t));
+}
+
+void DGUSDisplay::WriteVariable(uint16_t adr, uint8_t value) {
+ WriteVariable(adr, static_cast(&value), sizeof(uint8_t));
+}
+
+void DGUSDisplay::WriteVariable(uint16_t adr, int8_t value) {
+ WriteVariable(adr, static_cast(&value), sizeof(int8_t));
+}
+
+void DGUSDisplay::WriteVariable(uint16_t adr, long value) {
+ union { long l; char lb[4]; } endian;
+ char tmp[4];
+ endian.l = value;
+ tmp[0] = endian.lb[3];
+ tmp[1] = endian.lb[2];
+ tmp[2] = endian.lb[1];
+ tmp[3] = endian.lb[0];
+ WriteVariable(adr, static_cast(&tmp), sizeof(long));
+}
+
+void DGUSDisplay::WriteVariablePGM(uint16_t adr, const void* values, uint8_t valueslen, bool isstr) {
+ const char* myvalues = static_cast(values);
+ bool strend = !myvalues;
+ WriteHeader(adr, DGUS_CMD_WRITEVAR, valueslen);
+ while (valueslen--) {
+ char x;
+ if (!strend) x = pgm_read_byte(myvalues++);
+ if ((isstr && !x) || strend) {
+ strend = true;
+ x = ' ';
+ }
+ LCD_SERIAL.write(x);
+ }
+}
+
+void DGUSDisplay::ProcessRx() {
+
+ #if ENABLED(DGUS_SERIAL_STATS_RX_BUFFER_OVERRUNS)
+ if (!LCD_SERIAL.available() && LCD_SERIAL.buffer_overruns()) {
+ // Overrun, but reset the flag only when the buffer is empty
+ // We want to extract as many as valid datagrams possible...
+ DEBUG_ECHOPGM("OVFL");
+ rx_datagram_state = DGUS_IDLE;
+ //LCD_SERIAL.reset_rx_overun();
+ LCD_SERIAL.flush();
+ }
+ #endif
+
+ uint8_t receivedbyte;
+ while (LCD_SERIAL.available()) {
+ switch (rx_datagram_state) {
+
+ case DGUS_IDLE: // Waiting for the first header byte
+ receivedbyte = LCD_SERIAL.read();
+ //DEBUGLCDCOMM_ECHOPAIR("< ",receivedbyte);
+ if (DGUS_HEADER1 == receivedbyte) rx_datagram_state = DGUS_HEADER1_SEEN;
+ break;
+
+ case DGUS_HEADER1_SEEN: // Waiting for the second header byte
+ receivedbyte = LCD_SERIAL.read();
+ //DEBUGLCDCOMM_ECHOPAIR(" ", receivedbyte);
+ rx_datagram_state = (DGUS_HEADER2 == receivedbyte) ? DGUS_HEADER2_SEEN : DGUS_IDLE;
+ break;
+
+ case DGUS_HEADER2_SEEN: // Waiting for the length byte
+ rx_datagram_len = LCD_SERIAL.read();
+ //DEBUGLCDCOMM_ECHOPAIR(" (", rx_datagram_len, ") ");
+
+ // Telegram min len is 3 (command and one word of payload)
+ rx_datagram_state = WITHIN(rx_datagram_len, 3, DGUS_RX_BUFFER_SIZE) ? DGUS_WAIT_TELEGRAM : DGUS_IDLE;
+ break;
+
+ case DGUS_WAIT_TELEGRAM: // wait for complete datagram to arrive.
+ if (LCD_SERIAL.available() < rx_datagram_len) return;
+
+ Initialized = true; // We've talked to it, so we defined it as initialized.
+ uint8_t command = LCD_SERIAL.read();
+
+ // DEBUGLCDCOMM_ECHOPAIR("# ", command);
+
+ uint8_t readlen = rx_datagram_len - 1; // command is part of len.
+ unsigned char tmp[rx_datagram_len - 1];
+ unsigned char *ptmp = tmp;
+ while (readlen--) {
+ receivedbyte = LCD_SERIAL.read();
+ //DEBUGLCDCOMM_ECHOPAIR(" ", receivedbyte);
+ *ptmp++ = receivedbyte;
+ }
+ //DEBUGLCDCOMM_ECHOPGM(" # ");
+ // mostly we'll get this: 5A A5 03 82 4F 4B -- ACK on 0x82, so discard it.
+ if (command == DGUS_CMD_WRITEVAR && 'O' == tmp[0] && 'K' == tmp[1]) {
+ //DEBUG_ECHOLNPGM(">");
+ rx_datagram_state = DGUS_IDLE;
+ break;
+ }
+
+ /* AutoUpload, (and answer to) Command 0x83 :
+ | tmp[0 1 2 3 4 ... ]
+ | Example 5A A5 06 83 20 01 01 78 01 ……
+ | / / | | \ / | \ \
+ | Header | | | | \_____\_ DATA (Words!)
+ | DatagramLen / VPAdr |
+ | Command DataLen (in Words) */
+ if (command == DGUS_CMD_READVAR) {
+ const uint16_t vp = tmp[0] << 8 | tmp[1];
+
+ if (vp == 0x14 /*PIC_Now*/) {
+ const uint16_t screen_id = tmp[3] << 8 | tmp[4];
+
+ // In the code below DGUSLCD_SCREEN_BOOT acts as a sentinel
+ if (screen_id == 255) {
+ // DGUS OS sometimes randomly sends 255 back as an answer. Possible buffer overrun?
+ ReadCurrentScreen(); // Request again
+ } else if (displayRequest != DGUSLCD_SCREEN_BOOT && screen_id != displayRequest) {
+ // A display was requested. If the screen didn't yet switch to that display, we won't give that value back, otherwise the code gets confused.
+ // The DWIN display mostly honours the PIC_SET requests from the firmware, so after a while we may want to nudge it to the correct screen
+ DEBUG_ECHOPAIR(" Got a response on the current screen: ", screen_id);
+ DEBUG_ECHOLNPAIR(" - however, we've requested screen ", displayRequest);
+ } else {
+ displayRequest = DGUSLCD_SCREEN_BOOT;
+
+ if (current_screen_update_callback != nullptr) {
+ current_screen_update_callback(static_cast(screen_id));
+ }
+ }
+ } else {
+ //const uint8_t dlen = tmp[2] << 1; // Convert to Bytes. (Display works with words)
+ //DEBUG_ECHOPAIR(" vp=", vp, " dlen=", dlen);
+ DGUS_VP_Variable ramcopy;
+ DEBUG_ECHOLNPAIR("VP received: ", vp , " - val ", tmp[3]);
+ if (populate_VPVar(vp, &ramcopy)) {
+ if (ramcopy.set_by_display_handler)
+ ramcopy.set_by_display_handler(ramcopy, &tmp[3]);
+ else
+ DEBUG_ECHOLNPGM(" VPVar found, no handler.");
+ }
+ else
+ DEBUG_ECHOLNPAIR(" VPVar not found:", vp);
+
+ // Always ask for a screen update so we can send a screen update earlier, this prevents a flash of unstyled screen
+ ReadCurrentScreen();
+ }
+
+ rx_datagram_state = DGUS_IDLE;
+ break;
+ }
+
+ // discard anything else
+ rx_datagram_state = DGUS_IDLE;
+ }
+ }
+}
+
+size_t DGUSDisplay::GetFreeTxBuffer() { return SERIAL_GET_TX_BUFFER_FREE(); }
+
+void DGUSDisplay::WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen) {
+ LCD_SERIAL.write(DGUS_HEADER1);
+ LCD_SERIAL.write(DGUS_HEADER2);
+ LCD_SERIAL.write(payloadlen + 3);
+ LCD_SERIAL.write(cmd);
+ LCD_SERIAL.write(adr >> 8);
+ LCD_SERIAL.write(adr & 0xFF);
+}
+
+void DGUSDisplay::WritePGM(const char str[], uint8_t len) {
+ while (len--) LCD_SERIAL.write(pgm_read_byte(str++));
+}
+
+void DGUSDisplay::loop() {
+ // protect against recursion… ProcessRx() may indirectly call idle() when injecting gcode commands.
+ if (!no_reentrance) {
+ no_reentrance = true;
+ ProcessRx();
+ no_reentrance = false;
+ }
+}
+
+void DGUSDisplay::RequestScreen(DGUSLCD_Screens screen) {
+ displayRequest = screen;
+
+ DEBUG_ECHOLNPAIR("GotoScreen ", screen);
+ const unsigned char gotoscreen[] = { 0x5A, 0x01, (unsigned char) (screen >> 8U), (unsigned char) (screen & 0xFFU) };
+ WriteVariable(0x84, gotoscreen, sizeof(gotoscreen));
+}
+
+void DGUSDisplay::ReadCurrentScreen() {
+ ReadVariable(0x14 /*PIC_NOW*/);
+}
+
+rx_datagram_state_t DGUSDisplay::rx_datagram_state = DGUS_IDLE;
+uint8_t DGUSDisplay::rx_datagram_len = 0;
+bool DGUSDisplay::Initialized = false;
+bool DGUSDisplay::no_reentrance = false;
+DGUSLCD_Screens DGUSDisplay::displayRequest = DGUSLCD_SCREEN_BOOT;
+
+// A SW memory barrier, to ensure GCC does not overoptimize loops
+#define sw_barrier() asm volatile("": : :"memory");
+
+bool populate_VPVar(const uint16_t VP, DGUS_VP_Variable * const ramcopy) {
+ //DEBUG_ECHOLNPAIR("populate_VPVar ", VP);
+ const DGUS_VP_Variable *pvp = DGUSLCD_FindVPVar(VP);
+ // DEBUG_ECHOLNPAIR(" pvp ", (uint16_t )pvp);
+ if (!pvp) return false;
+ memcpy_P(ramcopy, pvp, sizeof(DGUS_VP_Variable));
+ return true;
+}
+
+#endif // HAS_DGUS_LCD
diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSDisplay.h b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSDisplay.h
new file mode 100644
index 0000000000..f4e37e6c07
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSDisplay.h
@@ -0,0 +1,126 @@
+/**
+ * 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
+
+/* DGUS implementation written by coldtobi in 2019 for Marlin */
+
+#include "../../../../inc/MarlinConfigPre.h"
+
+#include "../../../../MarlinCore.h"
+#if HAS_BED_PROBE
+ #include "../../../../module/probe.h"
+#endif
+#include "../dgus/DGUSVPVariable.h"
+
+enum DGUSLCD_Screens : uint8_t;
+
+typedef enum : uint8_t {
+ DGUS_IDLE, //< waiting for DGUS_HEADER1.
+ DGUS_HEADER1_SEEN, //< DGUS_HEADER1 received
+ DGUS_HEADER2_SEEN, //< DGUS_HEADER2 received
+ DGUS_WAIT_TELEGRAM, //< LEN received, Waiting for to receive all bytes.
+} rx_datagram_state_t;
+
+typedef void (*screenUpdateCallback_t)(DGUSLCD_Screens screen);
+
+// Low-Level access to the display.
+class DGUSDisplay {
+public:
+
+ DGUSDisplay() = default;
+
+ static void InitDisplay();
+ static void ResetDisplay();
+
+ // Variable access.
+ static void WriteVariable(uint16_t adr, const void* values, uint8_t valueslen, bool isstr=false);
+ static void WriteVariablePGM(uint16_t adr, const void* values, uint8_t valueslen, bool isstr=false);
+ static void WriteVariable(uint16_t adr, int16_t value);
+ static void WriteVariable(uint16_t adr, uint16_t value);
+ static void WriteVariable(uint16_t adr, uint8_t value);
+ static void WriteVariable(uint16_t adr, int8_t value);
+ static void WriteVariable(uint16_t adr, long value);
+
+ static void ReadVariable(uint16_t adr);
+
+ // Utility functions for bridging ui_api and dgus
+ template
+ static void SetVariable(DGUS_VP_Variable &var) {
+ WriteVariable(var.VP, (WireType)Getter(selector));
+ }
+
+ template
+ static void GetVariable(DGUS_VP_Variable &var, void *val_ptr) {
+ uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
+ Setter(newvalue, selector);
+ }
+
+ // Until now I did not need to actively read from the display. That's why there is no ReadVariable
+ // (I extensively use the auto upload of the display)
+
+ // Force display into another screen.
+ // (And trigger update of containing VPs)
+ // (to implement a pop up message, which may not be nested)
+ static void RequestScreen(DGUSLCD_Screens screen);
+
+ // Request the current displayed screen - will be passed to current_screen_update_callback
+ static void ReadCurrentScreen();
+
+ // Periodic tasks, eg. Rx-Queue handling.
+ static void loop();
+
+public:
+ // Helper for users of this class to estimate if an interaction would be blocking.
+ static size_t GetFreeTxBuffer();
+
+ // Checks two things: Can we confirm the presence of the display and has we initiliazed it.
+ // (both boils down that the display answered to our chatting)
+ static inline bool isInitialized() { return Initialized; }
+
+ static screenUpdateCallback_t current_screen_update_callback;
+
+private:
+ static void WriteHeader(uint16_t adr, uint8_t cmd, uint8_t payloadlen);
+ static void WritePGM(const char str[], uint8_t len);
+ static void ProcessRx();
+
+ static inline uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
+ static rx_datagram_state_t rx_datagram_state;
+ static uint8_t rx_datagram_len;
+ static bool Initialized, no_reentrance;
+
+ static DGUSLCD_Screens displayRequest;
+};
+
+#define GET_VARIABLE(f, t, V...) (&DGUSDisplay::GetVariable)
+#define SET_VARIABLE(f, t, V...) (&DGUSDisplay::SetVariable)
+
+extern DGUSDisplay dgusdisplay;
+
+// compile-time x^y
+constexpr float cpow(const float x, const int y) { return y == 0 ? 1.0 : x * cpow(x, y - 1); }
+
+/// Find the flash address of a DGUS_VP_Variable for the VP.
+extern const DGUS_VP_Variable* DGUSLCD_FindVPVar(const uint16_t vp);
+
+/// Helper to populate a DGUS_VP_Variable for a given VP. Return false if not found.
+extern bool populate_VPVar(const uint16_t VP, DGUS_VP_Variable * const ramcopy);
diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp
new file mode 100644
index 0000000000..5b255fbcbf
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp
@@ -0,0 +1,1235 @@
+/**
+ * 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 ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+
+#include "DGUSScreenHandler.h"
+#include "DGUSDisplay.h"
+#include "../dgus/DGUSDisplayDef.h"
+#include "../dgus/DGUSVPVariable.h"
+
+#include "../../ui_api.h"
+#include "../../../../MarlinCore.h"
+#include "../../../../module/temperature.h"
+#include "../../../../module/motion.h"
+#include "../../../../module/settings.h"
+#include "../../../../gcode/queue.h"
+#include "../../../../module/planner.h"
+#include "../../../../sd/cardreader.h"
+#include "../../../../libs/duration_t.h"
+#include "../../../../module/printcounter.h"
+#include "../../../../feature/caselight.h"
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+ #include "../../../../feature/powerloss.h"
+#endif
+
+uint16_t DGUSScreenHandler::ConfirmVP;
+
+#if ENABLED(SDSUPPORT)
+ int16_t DGUSScreenHandler::top_file = 0;
+ int16_t DGUSScreenHandler::file_to_print = 0;
+ static ExtUI::FileList filelist;
+#endif
+
+void (*DGUSScreenHandler::confirm_action_cb)() = nullptr;
+
+DGUSLCD_Screens DGUSScreenHandler::current_screen;
+DGUSLCD_Screens DGUSScreenHandler::past_screens[NUM_PAST_SCREENS] = {DGUSLCD_SCREEN_MAIN};
+uint8_t DGUSScreenHandler::update_ptr;
+uint16_t DGUSScreenHandler::skipVP;
+bool DGUSScreenHandler::ScreenComplete;
+uint8_t DGUSScreenHandler::MeshLevelIndex = -1;
+bool DGUSScreenHandler::are_steppers_enabled = true;
+float DGUSScreenHandler::feed_amount = true;
+
+//DGUSDisplay dgusdisplay;
+screenUpdateCallback_t DGUSDisplay::current_screen_update_callback = &DGUSScreenHandler::updateCurrentScreen;
+
+// endianness swap
+uint16_t swap16(const uint16_t value) { return (value & 0xffU) << 8U | (value >> 8U); }
+
+void DGUSScreenHandler::sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool l4inflash) {
+ DGUS_VP_Variable ramcopy;
+ if (populate_VPVar(VP_MSGSTR1, &ramcopy)) {
+ ramcopy.memadr = (void*) line1;
+ l1inflash ? DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(ramcopy) : DGUSScreenHandler::DGUSLCD_SendStringToDisplay(ramcopy);
+ }
+ if (populate_VPVar(VP_MSGSTR2, &ramcopy)) {
+ ramcopy.memadr = (void*) line2;
+ l2inflash ? DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(ramcopy) : DGUSScreenHandler::DGUSLCD_SendStringToDisplay(ramcopy);
+ }
+ if (populate_VPVar(VP_MSGSTR3, &ramcopy)) {
+ ramcopy.memadr = (void*) line3;
+ l3inflash ? DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(ramcopy) : DGUSScreenHandler::DGUSLCD_SendStringToDisplay(ramcopy);
+ }
+ //if (populate_VPVar(VP_MSGSTR4, &ramcopy)) {
+ // ramcopy.memadr = (void*) line4;
+ // l4inflash ? DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(ramcopy) : DGUSScreenHandler::DGUSLCD_SendStringToDisplay(ramcopy);
+ //}
+}
+
+void DGUSScreenHandler::HandleUserConfirmationPopUp(uint16_t VP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1, bool l2, bool l3, bool l4) {
+ if (current_screen == DGUSLCD_SCREEN_CONFIRM) {
+ // Already showing a pop up, so we need to cancel that first.
+ PopToOldScreen();
+ }
+
+ ConfirmVP = VP;
+ ScreenHandler.SetupConfirmAction(nullptr);
+ sendinfoscreen(line1, line2, line3, line4, l1, l2, l3, l4);
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_CONFIRM);
+}
+
+void DGUSScreenHandler::setstatusmessage(const char *msg) {
+ DGUS_VP_Variable ramcopy;
+ if (populate_VPVar(VP_M117, &ramcopy)) {
+ ramcopy.memadr = (void*) msg;
+ DGUSLCD_SendStringToDisplay(ramcopy);
+ }
+}
+
+void DGUSScreenHandler::setstatusmessagePGM(PGM_P const msg) {
+ DGUS_VP_Variable ramcopy;
+ if (populate_VPVar(VP_M117, &ramcopy)) {
+ ramcopy.memadr = (void*) msg;
+ DGUSLCD_SendStringToDisplayPGM(ramcopy);
+ }
+}
+
+// Send an 8 bit or 16 bit value to the display.
+void DGUSScreenHandler::DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ //DEBUG_ECHOPAIR(" DGUS_LCD_SendWordValueToDisplay ", var.VP);
+ //DEBUG_ECHOLNPAIR(" data ", *(uint16_t *)var.memadr);
+ if (var.size > 1)
+ dgusdisplay.WriteVariable(var.VP, *(int16_t*)var.memadr);
+ else
+ dgusdisplay.WriteVariable(var.VP, *(int8_t*)var.memadr);
+ }
+}
+
+// Send an uint8_t between 0 and 255 to the display, but scale to a percentage (0..100)
+void DGUSScreenHandler::DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ //DEBUG_ECHOPAIR(" DGUS_LCD_SendWordValueToDisplay ", var.VP);
+ //DEBUG_ECHOLNPAIR(" data ", *(uint16_t *)var.memadr);
+ uint16_t tmp = *(uint8_t *) var.memadr +1 ; // +1 -> avoid rounding issues for the display.
+ tmp = map(tmp, 0, 255, 0, 100);
+ dgusdisplay.WriteVariable(var.VP, tmp);
+ }
+}
+
+// Send the current print progress to the display.
+void DGUSScreenHandler::DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var) {
+ //DEBUG_ECHOPAIR(" DGUSLCD_SendPrintProgressToDisplay ", var.VP);
+ uint16_t tmp = ExtUI::getProgress_percent();
+ //DEBUG_ECHOLNPAIR(" data ", tmp);
+ dgusdisplay.WriteVariable(var.VP, tmp);
+}
+
+// Send the current print time to the display.
+// It is using a hex display for that: It expects BSD coded data in the format xxyyzz
+void DGUSScreenHandler::DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var) {
+ duration_t elapsed = print_job_timer.duration();
+ char buf[32];
+ elapsed.toString(buf);
+ dgusdisplay.WriteVariable(VP_PrintTime, buf, var.size, true);
+}
+
+void DGUSScreenHandler::DGUSLCD_SendAboutFirmwareVersion(DGUS_VP_Variable &var) {
+ const char* fwVersion = PSTR(SHORT_BUILD_VERSION);
+ dgusdisplay.WriteVariablePGM(var.VP, fwVersion, strlen(fwVersion), true);
+}
+
+void DGUSScreenHandler::DGUSLCD_SendAboutPrintSize(DGUS_VP_Variable &var) {
+ char PRINTSIZE[VP_PRINTER_BEDSIZE_LEN] = {0};
+ sprintf_P(PRINTSIZE, PSTR("%dx%dx%d"), X_BED_SIZE, Z_BED_SIZE, Z_MAX_POS);
+ dgusdisplay.WriteVariablePGM(var.VP, &PRINTSIZE, sizeof(PRINTSIZE), true);
+}
+
+
+// Send an uint8_t between 0 and 100 to a variable scale to 0..255
+void DGUSScreenHandler::DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr) {
+ if (var.memadr) {
+ uint16_t value = swap16(*(uint16_t*)val_ptr);
+ *(uint8_t*)var.memadr = map(constrain(value, 0, 100), 0, 100, 0, 255);
+ }
+}
+
+// Sends a (RAM located) string to the DGUS Display
+// (Note: The DGUS Display does not clear after the \0, you have to
+// overwrite the remainings with spaces.// var.size has the display buffer size!
+void DGUSScreenHandler::DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var) {
+ char *tmp = (char*) var.memadr;
+ dgusdisplay.WriteVariable(var.VP, tmp, var.size, true);
+}
+
+// Sends a (flash located) string to the DGUS Display
+// (Note: The DGUS Display does not clear after the \0, you have to
+// overwrite the remainings with spaces.// var.size has the display buffer size!
+void DGUSScreenHandler::DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var) {
+ char *tmp = (char*) var.memadr;
+ dgusdisplay.WriteVariablePGM(var.VP, tmp, var.size, true);
+}
+
+#if HAS_PID_HEATING
+ void DGUSScreenHandler::DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var) {
+ float value = *(float *)var.memadr;
+ float valuesend = 0;
+ switch (var.VP) {
+ default: return;
+ #if HOTENDS >= 1
+ case VP_E0_PID_P: valuesend = value; break;
+ case VP_E0_PID_I: valuesend = unscalePID_i(value); break;
+ case VP_E0_PID_D: valuesend = unscalePID_d(value); break;
+ #endif
+ #if HAS_HEATED_BED
+ case VP_BED_PID_P: valuesend = value; break;
+ case VP_BED_PID_I: valuesend = unscalePID_i(value); break;
+ case VP_BED_PID_D: valuesend = unscalePID_d(value); break;
+ #endif
+ }
+
+ valuesend *= cpow(10, 1);
+ union { int16_t i; char lb[2]; } endian;
+
+ char tmp[2];
+ endian.i = valuesend;
+ tmp[0] = endian.lb[1];
+ tmp[1] = endian.lb[0];
+ dgusdisplay.WriteVariable(var.VP, tmp, 2);
+ }
+#endif
+
+#if ENABLED(PRINTCOUNTER)
+
+ // Send the accumulate print time to the display.
+ // It is using a hex display for that: It expects BSD coded data in the format xxyyzz
+ void DGUSScreenHandler::DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var) {
+ printStatistics state = print_job_timer.getStats();
+ char buf[21];
+ duration_t elapsed = state.printTime;
+ elapsed.toString(buf);
+ dgusdisplay.WriteVariable(VP_PrintAccTime, buf, var.size, true);
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var) {
+ printStatistics state = print_job_timer.getStats();
+ char buf[21];
+ sprintf_P(buf, PSTR("%u"), state.totalPrints);
+ dgusdisplay.WriteVariable(VP_PrintsTotal, buf, var.size, true);
+ }
+
+#endif
+
+// Send fan status value to the display.
+#if HAS_FAN
+ void DGUSScreenHandler::DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ DEBUG_ECHOPAIR(" DGUSLCD_SendFanStatusToDisplay ", var.VP);
+ DEBUG_ECHOLNPAIR(" data ", *(uint8_t *)var.memadr);
+ uint16_t data_to_send = ICON_TOGGLE_OFF;
+ if (*(uint8_t *) var.memadr) data_to_send = ICON_TOGGLE_ON;
+ dgusdisplay.WriteVariable(var.VP, data_to_send);
+ }
+ }
+#endif
+
+// Send heater status value to the display.
+void DGUSScreenHandler::DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ DEBUG_ECHOPAIR(" DGUSLCD_SendHeaterStatusToDisplay ", var.VP);
+ DEBUG_ECHOLNPAIR(" data ", *(int16_t *)var.memadr);
+ uint16_t data_to_send = 0;
+ if (*(int16_t *) var.memadr) data_to_send = 1;
+ dgusdisplay.WriteVariable(var.VP, data_to_send);
+ }
+}
+
+#if ENABLED(DGUS_UI_WAITING)
+ void DGUSScreenHandler::DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var) {
+ // In FYSETC UI design there are 10 statuses to loop
+ static uint16_t period = 0;
+ static uint16_t index = 0;
+ //DEBUG_ECHOPAIR(" DGUSLCD_SendWaitingStatusToDisplay ", var.VP);
+ //DEBUG_ECHOLNPAIR(" data ", swap16(index));
+ if (period++ > DGUS_UI_WAITING_STATUS_PERIOD) {
+ dgusdisplay.WriteVariable(var.VP, index);
+ //DEBUG_ECHOLNPAIR(" data ", swap16(index));
+ if (++index >= DGUS_UI_WAITING_STATUS) index = 0;
+ period = 0;
+ }
+ }
+#endif
+
+#if ENABLED(SDSUPPORT)
+
+ void DGUSScreenHandler::ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr) {
+ // default action executed when there is a SD card, but not printing
+ if (ExtUI::isMediaInserted() && !ExtUI::isPrintingFromMedia()) {
+ ScreenChangeHook(var, val_ptr);
+ GotoScreen(current_screen);
+ return;
+ }
+
+ // if we are printing, we jump to two screens after the requested one.
+ // This should host e.g a print pause / print abort / print resume dialog.
+ // This concept allows to recycle this hook for other file
+ if (ExtUI::isPrintingFromMedia() && !card.flag.abort_sd_printing) {
+ GotoScreen(DGUSLCD_SCREEN_SDPRINTMANIPULATION);
+ return;
+ }
+
+ // Don't let the user in the dark why there is no reaction.
+ if (!ExtUI::isMediaInserted()) {
+ setstatusmessagePGM(GET_TEXT(MSG_NO_MEDIA));
+ return;
+ }
+ if (card.flag.abort_sd_printing) {
+ setstatusmessagePGM(GET_TEXT(MSG_MEDIA_ABORTING));
+ return;
+ }
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable& var, void *val_ptr) {
+ auto old_top = top_file;
+ const int16_t scroll = (int16_t)swap16(*(uint16_t*)val_ptr);
+ if (scroll) {
+ top_file += scroll;
+ DEBUG_ECHOPAIR("new topfile calculated:", top_file);
+ if (top_file < 0) {
+ top_file = 0;
+ DEBUG_ECHOLNPGM("Top of filelist reached");
+ }
+ else {
+ int16_t max_top = filelist.count() - DGUS_SD_FILESPERSCREEN;
+ NOLESS(max_top, 0);
+ NOMORE(top_file, max_top);
+ }
+ DEBUG_ECHOPAIR("new topfile adjusted:", top_file);
+ }
+ else {
+ if (!filelist.isAtRootDir()) {
+ filelist.upDir();
+ top_file = 0;
+ ForceCompleteUpdate();
+ } else {
+ // Navigate back to home
+ GotoScreen(DGUSLCD_SCREEN_MAIN);
+ }
+ }
+
+ if (old_top != top_file) ForceCompleteUpdate();
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr) {
+ uint16_t touched_nr = (int16_t)swap16(*(uint16_t*)val_ptr) + top_file;
+
+ SERIAL_ECHOLNPAIR("Selected file: ", touched_nr);
+
+ if (touched_nr > filelist.count()) return;
+ if (!filelist.seek(touched_nr)) return;
+ if (filelist.isDir()) {
+ filelist.changeDir(filelist.shortFilename());
+ top_file = 0;
+ ForceCompleteUpdate();
+ return;
+ }
+
+ // Send print filename
+ dgusdisplay.WriteVariable(VP_SD_Print_Filename, filelist.filename(), VP_SD_FileName_LEN, true);
+
+ // Setup Confirmation screen
+ file_to_print = touched_nr;
+ HandleUserConfirmationPopUp(VP_SD_FileSelectConfirm, PSTR("Print file"), filelist.filename(), PSTR("from SD Card?"), nullptr, true, false, true, true);
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr) {
+ if (!filelist.seek(file_to_print)) return;
+ ExtUI::printFile(filelist.shortFilename());
+ ScreenHandler.GotoScreen(
+ DGUSLCD_SCREEN_SDPRINTMANIPULATION
+ );
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr) {
+ if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
+ switch (swap16(*(uint16_t*)val_ptr)) {
+ case 0: // Resume
+ if (ExtUI::isPrintingFromMediaPaused()) ExtUI::resumePrint();
+ break;
+ case 1: // Pause
+ if (!ExtUI::isPrintingFromMediaPaused()) ExtUI::pausePrint();
+ break;
+ case 2: // Abort
+ ScreenHandler.HandleUserConfirmationPopUp(VP_SD_AbortPrintConfirmed, nullptr, PSTR("Abort printing"), filelist.filename(), PSTR("?"), true, true, false, true);
+ break;
+ }
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr) {
+ ExtUI::stopPrint();
+ GotoScreen(DGUSLCD_SCREEN_MAIN);
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr) {
+ if (!ExtUI::isPrintingFromMedia()) return; // avoid race condition when user stays in this menu and printer finishes.
+ GotoScreen(DGUSLCD_SCREEN_SDPRINTTUNE);
+ }
+
+ void DGUSScreenHandler::DGUSLCD_SD_SendFilename(DGUS_VP_Variable& var) {
+ uint16_t target_line = (var.VP - VP_SD_FileName0) / VP_SD_FileName_LEN;
+ if (target_line > DGUS_SD_FILESPERSCREEN) return;
+ char tmpfilename[VP_SD_FileName_LEN + 1] = "";
+ var.memadr = (void*)tmpfilename;
+ if (filelist.seek(top_file + target_line))
+ snprintf_P(tmpfilename, VP_SD_FileName_LEN, PSTR("%s%c"), filelist.filename(), filelist.isDir() ? '/' : 0);
+ DGUSLCD_SendStringToDisplay(var);
+ }
+
+ void DGUSScreenHandler::SDCardInserted() {
+ top_file = 0;
+ filelist.refresh();
+ auto cs = ScreenHandler.getCurrentScreen();
+ if (cs == DGUSLCD_SCREEN_MAIN || cs == DGUSLCD_SCREEN_CONTROL)
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_SDFILELIST);
+ }
+
+ void DGUSScreenHandler::SDCardRemoved() {
+ if (current_screen == DGUSLCD_SCREEN_SDFILELIST
+ || (current_screen == DGUSLCD_SCREEN_CONFIRM && (ConfirmVP == VP_SD_AbortPrintConfirmed || ConfirmVP == VP_SD_FileSelectConfirm))
+ || current_screen == DGUSLCD_SCREEN_SDPRINTMANIPULATION
+ ) ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
+ }
+
+ void DGUSScreenHandler::SDCardError() {
+ DGUSScreenHandler::SDCardRemoved();
+ ScreenHandler.sendinfoscreen(PSTR("NOTICE"), nullptr, PSTR("SD card error"), nullptr, true, true, true, true);
+ ScreenHandler.SetupConfirmAction(nullptr);
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_POPUP);
+ }
+
+#endif // SDSUPPORT
+
+void DGUSScreenHandler::FilamentRunout() {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_FILAMENTRUNOUT1);
+}
+
+void DGUSScreenHandler::OnFactoryReset() {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
+}
+
+#if HAS_BUZZER
+void DGUSScreenHandler::Buzzer(const uint16_t frequency, const uint16_t duration) {
+ // Frequency is fixed - duration is not but in 8 ms steps
+ const uint8_t durationUnits = static_cast(duration / 8);
+
+ SERIAL_ECHOLNPAIR("Invoking buzzer with units: ", durationUnits);
+ const unsigned char buzzerCommand[] = { 0x00, durationUnits, 0x40 /*Volume*/, 0x02 };
+
+ // WAE_Music_Play_Set
+ dgusdisplay.WriteVariable(0xA0, buzzerCommand, sizeof(buzzerCommand));
+}
+#endif
+
+void DGUSScreenHandler::OnHomingStart() {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_AUTOHOME);
+}
+
+void DGUSScreenHandler::OnHomingComplete() {
+ ScreenHandler.PopToOldScreen();
+}
+
+void DGUSScreenHandler::OnPrintFinished() {
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_PRINT_FINISH);
+}
+
+void DGUSScreenHandler::ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr) {
+ DGUS_VP_Variable ramcopy;
+ if (!populate_VPVar(ConfirmVP, &ramcopy)) return;
+ if (ramcopy.set_by_display_handler) ramcopy.set_by_display_handler(ramcopy, val_ptr);
+}
+
+void DGUSScreenHandler::HandleZoffsetChange(DGUS_VP_Variable &var, void *val_ptr) {
+ if (current_screen != DGUSLCD_SCREEN_TUNING) {
+ HandleLiveAdjustZ(var, val_ptr);
+ } else {
+ HandleProbeOffsetZChanged(var, val_ptr);
+ }
+}
+
+
+
+void DGUSScreenHandler::OnMeshLevelingStart() {
+ GotoScreen(DGUSLCD_SCREEN_LEVELING);
+
+ MeshLevelIndex = 0;
+
+ dgusdisplay.WriteVariable(VP_MESH_LEVEL_STATUS, static_cast(1));
+ ForceCompleteUpdate();
+}
+
+void DGUSScreenHandler::OnMeshLevelingUpdate(const int8_t xpos, const int8_t ypos) {
+ MeshLevelIndex++;
+
+ SERIAL_ECHOLNPAIR("Mesh level index: ", MeshLevelIndex);
+
+ // Update icon
+ dgusdisplay.WriteVariable(VP_MESH_LEVEL_STATUS, static_cast(MeshLevelIndex + 1));
+ ForceCompleteUpdate();
+
+ if (MeshLevelIndex + 1 == GRID_MAX_POINTS) {
+ // Done
+ thermalManager.disable_all_heaters();
+
+ settings.save();
+
+ delay(1000);
+
+ GotoScreen(DGUSLCD_SCREEN_ZOFFSET_LEVEL);
+ } else {
+ // We've already updated the icon, so nothing left
+ }
+}
+
+const uint16_t* DGUSLCD_FindScreenVPMapList(uint8_t screen) {
+ const uint16_t *ret;
+ const struct VPMapping *map = VPMap;
+ while ((ret = (uint16_t*) pgm_read_ptr(&(map->VPList)))) {
+ if (pgm_read_byte(&(map->screen)) == screen) return ret;
+ map++;
+ }
+ return nullptr;
+}
+
+const DGUS_VP_Variable* DGUSLCD_FindVPVar(const uint16_t vp) {
+ const DGUS_VP_Variable *ret = ListOfVP;
+ do {
+ const uint16_t vpcheck = pgm_read_word(&(ret->VP));
+ if (vpcheck == 0) break;
+ if (vpcheck == vp) return ret;
+ ++ret;
+ } while (1);
+
+ DEBUG_ECHOLNPAIR("FindVPVar NOT FOUND ", vp);
+ return nullptr;
+}
+
+void DGUSScreenHandler::ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr) {
+ if (!ExtUI::isPrinting()) {
+ ScreenChangeHook(var, val_ptr);
+ GotoScreen(current_screen);
+ }
+}
+
+void DGUSScreenHandler::ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr) {
+ uint8_t *tmp = (uint8_t*)val_ptr;
+
+ // The keycode in target is coded as , so 0x0100A means
+ // from screen 1 (main) to 10 (temperature). DGUSLCD_SCREEN_POPUP is special,
+ // meaning "return to previous screen"
+ DGUSLCD_Screens target = (DGUSLCD_Screens)tmp[1];
+
+ SERIAL_ECHOLNPAIR("Current screen:", current_screen);
+ SERIAL_ECHOLNPAIR("Cancel target:", target);
+
+ if (confirm_action_cb && current_screen == DGUSLCD_SCREEN_POPUP) {
+ DEBUG_ECHOLNPGM("Executing confirmation action");
+ confirm_action_cb();
+ PopToOldScreen();
+ return;
+ }
+
+ if (target == DGUSLCD_SCREEN_POPUP || target == DGUSLCD_SCREEN_CONFIRM || target == 0 || target == 255 /*Buggy DWIN screen sometimes just returns 255*/) {
+ PopToOldScreen();
+ return;
+ }
+
+ UpdateNewScreen(target);
+
+ #ifdef DEBUG_DGUSLCD
+ if (!DGUSLCD_FindScreenVPMapList(target)) DEBUG_ECHOLNPAIR("WARNING: No screen Mapping found for ", target);
+ #endif
+}
+
+void DGUSScreenHandler::HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr) {
+ thermalManager.disable_all_heaters();
+ ScreenHandler.ForceCompleteUpdate(); // hint to send all data.
+}
+
+void DGUSScreenHandler::HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
+ uint16_t acceptedvalue;
+
+ switch (var.VP) {
+ default: return;
+ #if HOTENDS >= 1
+ case VP_T_E0_Set:
+ thermalManager.setTargetHotend(newvalue, 0);
+ acceptedvalue = thermalManager.temp_hotend[0].target;
+ break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_T_E1_Set:
+ thermalManager.setTargetHotend(newvalue, 1);
+ acceptedvalue = thermalManager.temp_hotend[1].target;
+ break;
+ #endif
+ #if HAS_HEATED_BED
+ case VP_T_Bed_Set:
+ thermalManager.setTargetBed(newvalue);
+ acceptedvalue = thermalManager.temp_bed.target;
+ break;
+ #endif
+ }
+
+ // reply to display the new value to update the view if the new value was rejected by the Thermal Manager.
+ if (newvalue != acceptedvalue && var.send_to_display_handler) var.send_to_display_handler(var);
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+}
+
+void DGUSScreenHandler::HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ #if EXTRUDERS
+ uint16_t newvalue = swap16(*(uint16_t*)val_ptr);
+ uint8_t target_extruder;
+ switch (var.VP) {
+ default: return;
+ #if HOTENDS >= 1
+ case VP_Flowrate_E0: target_extruder = 0; break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_Flowrate_E1: target_extruder = 1; break;
+ #endif
+ }
+
+ planner.set_flow(target_extruder, newvalue);
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+ #else
+ UNUSED(var); UNUSED(val_ptr);
+ #endif
+}
+
+void DGUSScreenHandler::HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleManualExtrude");
+
+ int16_t movevalue = swap16(*(uint16_t*)val_ptr);
+ float target = movevalue * 0.01f;
+ ExtUI::extruder_t target_extruder;
+
+ switch (var.VP) {
+ #if HOTENDS >= 1
+ case VP_MOVE_E0: target_extruder = ExtUI::extruder_t::E0; break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_MOVE_E1: target_extruder = ExtUI::extruder_t::E1; break;
+ #endif
+ default: return;
+ }
+
+ target += ExtUI::getAxisPosition_mm(target_extruder);
+ ExtUI::setAxisPosition_mm(target, target_extruder);
+ skipVP = var.VP;
+}
+
+#if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
+ void DGUSScreenHandler::HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleManualMoveOption");
+ *(uint16_t*)var.memadr = swap16(*(uint16_t*)val_ptr);
+ }
+#endif
+
+void DGUSScreenHandler::HandleManualMove(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleManualMove");
+
+ int16_t movevalue = swap16(*(uint16_t*)val_ptr);
+ #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
+ if (movevalue) {
+ const uint16_t choice = *(uint16_t*)var.memadr;
+ movevalue = movevalue < 0 ? -choice : choice;
+ }
+ #endif
+ char axiscode;
+ unsigned int speed = 1500; //FIXME: get default feedrate for manual moves, dont hardcode.
+
+ switch (var.VP) {
+ default: return;
+
+ case VP_MOVE_X:
+ axiscode = 'X';
+ if (!ExtUI::canMove(ExtUI::axis_t::X)) goto cannotmove;
+ break;
+
+ case VP_MOVE_Y:
+ axiscode = 'Y';
+ if (!ExtUI::canMove(ExtUI::axis_t::Y)) goto cannotmove;
+ break;
+
+ case VP_MOVE_Z:
+ axiscode = 'Z';
+ speed = 300; // default to 5mm/s
+ if (!ExtUI::canMove(ExtUI::axis_t::Z)) goto cannotmove;
+ break;
+
+ case VP_HOME_ALL: // only used for homing
+ axiscode = '\0';
+ movevalue = 0; // ignore value sent from display, this VP is _ONLY_ for homing.
+ break;
+ }
+
+ if (!movevalue) {
+ // homing
+ DEBUG_ECHOPAIR(" homing ", axiscode);
+ char buf[6] = "G28 X";
+ buf[4] = axiscode;
+ //DEBUG_ECHOPAIR(" ", buf);
+ queue.enqueue_one_now(buf);
+ //DEBUG_ECHOLNPGM(" ✓");
+ ScreenHandler.ForceCompleteUpdate();
+ return;
+ }
+ else {
+ //movement
+ DEBUG_ECHOPAIR(" move ", axiscode);
+ bool old_relative_mode = relative_mode;
+ if (!relative_mode) {
+ //DEBUG_ECHOPGM(" G91");
+ queue.enqueue_now_P(PSTR("G91"));
+ //DEBUG_ECHOPGM(" ✓ ");
+ }
+ char buf[32]; // G1 X9999.99 F12345
+ unsigned int backup_speed = MMS_TO_MMM(feedrate_mm_s);
+ char sign[]="\0";
+ int16_t value = movevalue / 100;
+ if (movevalue < 0) { value = -value; sign[0] = '-'; }
+ int16_t fraction = ABS(movevalue) % 100;
+ snprintf_P(buf, 32, PSTR("G0 %c%s%d.%02d F%d"), axiscode, sign, value, fraction, speed);
+ //DEBUG_ECHOPAIR(" ", buf);
+ queue.enqueue_one_now(buf);
+ //DEBUG_ECHOLNPGM(" ✓ ");
+ if (backup_speed != speed) {
+ snprintf_P(buf, 32, PSTR("G0 F%d"), backup_speed);
+ queue.enqueue_one_now(buf);
+ //DEBUG_ECHOPAIR(" ", buf);
+ }
+ //while (!enqueue_and_echo_command(buf)) idle();
+ //DEBUG_ECHOLNPGM(" ✓ ");
+ if (!old_relative_mode) {
+ //DEBUG_ECHOPGM("G90");
+ queue.enqueue_now_P(PSTR("G90"));
+ //DEBUG_ECHOPGM(" ✓ ");
+ }
+ }
+
+ ScreenHandler.ForceCompleteUpdate();
+ DEBUG_ECHOLNPGM("manmv done.");
+ return;
+
+ cannotmove:
+ DEBUG_ECHOLNPAIR(" cannot move ", axiscode);
+ return;
+}
+
+void DGUSScreenHandler::HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleMotorLockUnlock");
+
+ char buf[4];
+ const int16_t lock = swap16(*(uint16_t*)val_ptr);
+ strcpy_P(buf, lock ? PSTR("M18") : PSTR("M17"));
+
+ //DEBUG_ECHOPAIR(" ", buf);
+ queue.enqueue_one_now(buf);
+}
+
+#if ENABLED(POWER_LOSS_RECOVERY)
+
+ void DGUSScreenHandler::HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr) {
+ uint16_t value = swap16(*(uint16_t*)val_ptr);
+ if (value) {
+ queue.inject_P(PSTR("M1000"));
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_SDPRINTMANIPULATION);
+ }
+ else {
+ recovery.cancel();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
+ }
+ }
+
+#endif
+
+void DGUSScreenHandler::HandleSettings(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleSettings");
+ uint16_t value = swap16(*(uint16_t*)val_ptr);
+ switch (value) {
+ default: break;
+ case 1:
+ TERN_(PRINTCOUNTER, print_job_timer.initStats());
+ queue.inject_P(PSTR("M502\nM500"));
+ break;
+ case 2: queue.inject_P(PSTR("M501")); break;
+ case 3: queue.inject_P(PSTR("M500")); break;
+ }
+}
+
+void DGUSScreenHandler::HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleStepPerMMChanged");
+
+ uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
+ DEBUG_ECHOLNPAIR("value_raw:", value_raw);
+ float value = (float)value_raw/10;
+ ExtUI::axis_t axis;
+ switch (var.VP) {
+ case VP_X_STEP_PER_MM: axis = ExtUI::axis_t::X; break;
+ case VP_Y_STEP_PER_MM: axis = ExtUI::axis_t::Y; break;
+ case VP_Z_STEP_PER_MM: axis = ExtUI::axis_t::Z; break;
+ default: return;
+ }
+ DEBUG_ECHOLNPAIR_F("value:", value);
+ ExtUI::setAxisSteps_per_mm(value, axis);
+ DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(axis));
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+ return;
+}
+
+void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleStepPerMMExtruderChanged");
+
+ uint16_t value_raw = swap16(*(uint16_t*)val_ptr);
+ DEBUG_ECHOLNPAIR("value_raw:", value_raw);
+ float value = (float)value_raw/10;
+ ExtUI::extruder_t extruder;
+ switch (var.VP) {
+ default: return;
+ #if HOTENDS >= 1
+ case VP_E0_STEP_PER_MM: extruder = ExtUI::extruder_t::E0; break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_E1_STEP_PER_MM: extruder = ExtUI::extruder_t::E1; break;
+ #endif
+ }
+ DEBUG_ECHOLNPAIR_F("value:", value);
+ ExtUI::setAxisSteps_per_mm(value,extruder);
+ DEBUG_ECHOLNPAIR_F("value_set:", ExtUI::getAxisSteps_per_mm(extruder));
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+ return;
+}
+
+#if HAS_PID_HEATING
+ void DGUSScreenHandler::HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ uint16_t rawvalue = swap16(*(uint16_t*)val_ptr);
+ DEBUG_ECHOLNPAIR("V1:", rawvalue);
+ float value = (float)rawvalue / 10;
+ DEBUG_ECHOLNPAIR("V2:", value);
+ float newvalue = 0;
+
+ switch (var.VP) {
+ default: return;
+ #if HOTENDS >= 1
+ case VP_E0_PID_P: newvalue = value; break;
+ case VP_E0_PID_I: newvalue = scalePID_i(value); break;
+ case VP_E0_PID_D: newvalue = scalePID_d(value); break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_E1_PID_P: newvalue = value; break;
+ case VP_E1_PID_I: newvalue = scalePID_i(value); break;
+ case VP_E1_PID_D: newvalue = scalePID_d(value); break;
+ #endif
+ #if HAS_HEATED_BED
+ case VP_BED_PID_P: newvalue = value; break;
+ case VP_BED_PID_I: newvalue = scalePID_i(value); break;
+ case VP_BED_PID_D: newvalue = scalePID_d(value); break;
+ #endif
+ }
+
+ DEBUG_ECHOLNPAIR_F("V3:", newvalue);
+ *(float *)var.memadr = newvalue;
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+ }
+
+ void DGUSScreenHandler::HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandlePIDAutotune");
+
+ char buf[32] = {0};
+
+ switch (var.VP) {
+ default: break;
+ #if ENABLED(PIDTEMP)
+ #if HOTENDS >= 1
+ case VP_PID_AUTOTUNE_E0: // Autotune Extruder 0
+ sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E0);
+ break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_PID_AUTOTUNE_E1:
+ sprintf_P(buf, PSTR("M303 E%d C5 S210 U1"), ExtUI::extruder_t::E1);
+ break;
+ #endif
+ #endif
+ #if ENABLED(PIDTEMPBED)
+ case VP_PID_AUTOTUNE_BED:
+ sprintf_P(buf, PSTR("M303 E-1 C5 S70 U1"));
+ break;
+ #endif
+ }
+
+ if (buf[0]) queue.enqueue_one_now(buf);
+
+ #if ENABLED(DGUS_UI_WAITING)
+ sendinfoscreen(PSTR("PID is autotuning"), PSTR("please wait"), NUL_STR, NUL_STR, true, true, true, true);
+ GotoScreen(DGUSLCD_SCREEN_WAITING);
+ #endif
+ }
+#endif
+
+void DGUSScreenHandler::HandleFeedAmountChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ int16_t movevalue = swap16(*(uint16_t*)val_ptr);
+ float target = movevalue * 0.01f;
+
+ DEBUG_ECHOLNPAIR("HandleFeedAmountChanged ", target);
+
+
+ *(float *)var.memadr = target;
+
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+ return;
+ }
+
+#if HAS_BED_PROBE
+ void DGUSScreenHandler::HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleProbeOffsetZChanged");
+
+ const float offset = float(int16_t(swap16(*(uint16_t*)val_ptr))) / 100.0f;
+ ExtUI::setZOffset_mm(offset);
+ ScreenHandler.skipVP = var.VP; // don't overwrite value the next update time as the display might autoincrement in parallel
+ return;
+ }
+#endif
+
+#if ENABLED(BABYSTEPPING)
+ void DGUSScreenHandler::HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleLiveAdjustZ");
+
+ int16_t flag = swap16(*(uint16_t*)val_ptr);
+ int16_t steps = flag ? -5 : 5;
+ ExtUI::smartAdjustAxis_steps(steps, ExtUI::axis_t::Z, true);
+ ScreenHandler.ForceCompleteUpdate();
+ return;
+ }
+#endif
+
+#if HAS_FAN
+ void DGUSScreenHandler::HandleFanControl(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleFanControl");
+ *(uint8_t*)var.memadr = *(uint8_t*)var.memadr > 0 ? 0 : 255;
+ }
+#endif
+
+void DGUSScreenHandler::HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleHeaterControl");
+
+ uint8_t preheat_temp = 0;
+ switch (var.VP) {
+ #if HOTENDS >= 1
+ case VP_E0_CONTROL:
+ #endif
+ #if HOTENDS >= 2
+ case VP_E1_CONTROL:
+ #endif
+ #if HOTENDS >= 3
+ case VP_E2_CONTROL:
+ #endif
+ preheat_temp = PREHEAT_1_TEMP_HOTEND;
+ break;
+
+ case VP_BED_CONTROL:
+ preheat_temp = PREHEAT_1_TEMP_BED;
+ break;
+ }
+
+ *(int16_t*)var.memadr = *(int16_t*)var.memadr > 0 ? 0 : preheat_temp;
+}
+
+#if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
+
+ typedef struct {
+ ExtUI::extruder_t extruder; // which extruder to operate
+ uint8_t action; // load or unload
+ bool heated; // heating done ?
+ float purge_length; // the length to extrude before unload, prevent filament jam
+ } filament_data_t;
+
+ static filament_data_t filament_data;
+
+ void DGUSScreenHandler::HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr) {
+ DEBUG_ECHOLNPGM("HandleFilamentOption");
+
+ uint8_t e_temp = 0;
+ filament_data.heated = false;
+ uint16_t preheat_option = swap16(*(uint16_t*)val_ptr);
+ if (preheat_option <= 8) // Load filament type
+ filament_data.action = 1;
+ else if (preheat_option >= 10) { // Unload filament type
+ preheat_option -= 10;
+ filament_data.action = 2;
+ filament_data.purge_length = DGUS_FILAMENT_PURGE_LENGTH;
+ }
+ else // Cancel filament operation
+ filament_data.action = 0;
+
+ switch (preheat_option) {
+ case 0: // Load PLA
+ #ifdef PREHEAT_1_TEMP_HOTEND
+ e_temp = PREHEAT_1_TEMP_HOTEND;
+ #endif
+ break;
+ case 1: // Load ABS
+ TERN_(PREHEAT_2_TEMP_HOTEND, e_temp = PREHEAT_2_TEMP_HOTEND);
+ break;
+ case 2: // Load PET
+ #ifdef PREHEAT_3_TEMP_HOTEND
+ e_temp = PREHEAT_3_TEMP_HOTEND;
+ #endif
+ break;
+ case 3: // Load FLEX
+ #ifdef PREHEAT_4_TEMP_HOTEND
+ e_temp = PREHEAT_4_TEMP_HOTEND;
+ #endif
+ break;
+ case 9: // Cool down
+ default:
+ e_temp = 0;
+ break;
+ }
+
+ if (filament_data.action == 0) { // Go back to utility screen
+ #if HOTENDS >= 1
+ thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E0);
+ #endif
+ #if HOTENDS >= 2
+ thermalManager.setTargetHotend(e_temp, ExtUI::extruder_t::E1);
+ #endif
+ GotoScreen(DGUSLCD_SCREEN_UTILITY);
+ }
+ else { // Go to the preheat screen to show the heating progress
+ switch (var.VP) {
+ default: return;
+ #if HOTENDS >= 1
+ case VP_E0_FILAMENT_LOAD_UNLOAD:
+ filament_data.extruder = ExtUI::extruder_t::E0;
+ thermalManager.setTargetHotend(e_temp, filament_data.extruder);
+ break;
+ #endif
+ #if HOTENDS >= 2
+ case VP_E1_FILAMENT_LOAD_UNLOAD:
+ filament_data.extruder = ExtUI::extruder_t::E1;
+ thermalManager.setTargetHotend(e_temp, filament_data.extruder);
+ break;
+ #endif
+ }
+ GotoScreen(DGUSLCD_SCREEN_FILAMENT_HEATING);
+ }
+ }
+
+ void DGUSScreenHandler::HandleFilamentLoadUnload(DGUS_VP_Variable &var) {
+ DEBUG_ECHOLNPGM("HandleFilamentLoadUnload");
+ if (filament_data.action <= 0) return;
+
+ // If we close to the target temperature, we can start load or unload the filament
+ if (thermalManager.hotEnoughToExtrude(filament_data.extruder) && \
+ thermalManager.targetHotEnoughToExtrude(filament_data.extruder)) {
+ float movevalue = DGUS_FILAMENT_LOAD_LENGTH_PER_TIME;
+
+ if (filament_data.action == 1) { // load filament
+ if (!filament_data.heated) {
+ GotoScreen(DGUSLCD_SCREEN_FILAMENT_LOADING);
+ filament_data.heated = true;
+ }
+ movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder)+movevalue;
+ }
+ else { // unload filament
+ if (!filament_data.heated) {
+ GotoScreen(DGUSLCD_SCREEN_FILAMENT_UNLOADING);
+ filament_data.heated = true;
+ }
+ // Before unloading extrude to prevent jamming
+ if (filament_data.purge_length >= 0) {
+ movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) + movevalue;
+ filament_data.purge_length -= movevalue;
+ }
+ else
+ movevalue = ExtUI::getAxisPosition_mm(filament_data.extruder) - movevalue;
+ }
+ ExtUI::setAxisPosition_mm(movevalue, filament_data.extruder);
+ }
+ }
+#endif
+
+void DGUSScreenHandler::HandleStepperState(bool is_enabled) {
+ bool steppers_were_enabled = are_steppers_enabled;
+ are_steppers_enabled = is_enabled;
+
+ if (steppers_were_enabled != are_steppers_enabled) ForceCompleteUpdate();
+}
+
+void DGUSScreenHandler::HandleLEDToggle() {
+ bool newState = !caselight.on;
+
+ caselight.on = newState;
+ caselight.update(newState);
+
+ ForceCompleteUpdate();
+}
+
+void DGUSScreenHandler::UpdateNewScreen(DGUSLCD_Screens newscreen, bool save_current_screen) {
+ DEBUG_ECHOLNPAIR("SetNewScreen: ", newscreen);
+
+ if (save_current_screen && current_screen != DGUSLCD_SCREEN_POPUP && current_screen != DGUSLCD_SCREEN_CONFIRM) {
+ DEBUG_ECHOLNPAIR("SetNewScreen: ", newscreen);
+ memmove(&past_screens[1], &past_screens[0], sizeof(past_screens) - 1);
+ past_screens[0] = current_screen;
+ }
+
+ current_screen = newscreen;
+ skipVP = 0;
+ ForceCompleteUpdate();
+}
+
+void DGUSScreenHandler::PopToOldScreen() {
+ SERIAL_ECHOLNPAIR("PopToOldScreen s=", past_screens[0]);
+ GotoScreen(past_screens[0], false);
+ memmove(&past_screens[0], &past_screens[1], sizeof(past_screens) - 1);
+ past_screens[sizeof(past_screens) - 1] = DGUSLCD_SCREEN_MAIN;
+}
+
+void DGUSScreenHandler::updateCurrentScreen(DGUSLCD_Screens current) {
+ if (current_screen != current) {
+ SERIAL_ECHOPAIR("Screen updated at display side: Was ", current_screen);
+ SERIAL_ECHOLNPAIR(", is now: ", current);
+
+ UpdateNewScreen(current, current != DGUSLCD_SCREEN_POPUP && current != DGUSLCD_SCREEN_CONFIRM);
+ }
+}
+
+void DGUSScreenHandler::UpdateScreenVPData() {
+ if (!dgusdisplay.isInitialized()) {
+ return;
+ }
+
+ //DEBUG_ECHOPAIR(" UpdateScreenVPData Screen: ", current_screen);
+
+ const uint16_t *VPList = DGUSLCD_FindScreenVPMapList(current_screen);
+ if (!VPList) {
+ DEBUG_ECHOLNPAIR(" NO SCREEN FOR: ", current_screen);
+ ScreenComplete = true;
+ return; // nothing to do, likely a bug or boring screen.
+ }
+
+ // Round-robin updating of all VPs.
+ VPList += update_ptr;
+
+ bool sent_one = false;
+ do {
+ uint16_t VP = pgm_read_word(VPList);
+ DEBUG_ECHOPAIR(" VP: ", VP);
+ if (!VP) {
+ update_ptr = 0;
+ DEBUG_ECHOLNPGM(" UpdateScreenVPData done");
+ ScreenComplete = true;
+ return; // Screen completed.
+ }
+
+ if (VP == skipVP) { skipVP = 0; continue; }
+
+ DGUS_VP_Variable rcpy;
+ if (populate_VPVar(VP, &rcpy)) {
+ uint8_t expected_tx = 6 + rcpy.size; // expected overhead is 6 bytes + payload.
+ // Send the VP to the display, but try to avoid overrunning the Tx Buffer.
+ // But send at least one VP, to avoid getting stalled.
+ if (rcpy.send_to_display_handler && (!sent_one || expected_tx <= dgusdisplay.GetFreeTxBuffer())) {
+ DEBUG_ECHOPAIR(" calling handler for ", rcpy.VP);
+ sent_one = true;
+ rcpy.send_to_display_handler(rcpy);
+ }
+ else {
+ auto x = dgusdisplay.GetFreeTxBuffer();
+ DEBUG_ECHOLNPAIR(" tx almost full: ", x);
+ //DEBUG_ECHOPAIR(" update_ptr ", update_ptr);
+ ScreenComplete = false;
+ return; // please call again!
+ }
+ }
+
+ } while (++update_ptr, ++VPList, true);
+}
+
+void DGUSScreenHandler::GotoScreen(DGUSLCD_Screens screen, bool save_current_screen) {
+ SERIAL_ECHOLNPAIR("Issuing command to go to screen: ", screen);
+ dgusdisplay.RequestScreen(screen);
+ UpdateNewScreen(screen, save_current_screen);
+}
+
+bool DGUSScreenHandler::loop() {
+ dgusdisplay.loop();
+
+ const millis_t ms = millis();
+ static millis_t next_event_ms = 0;
+
+ if (wait_for_user && current_screen != DGUSLCD_SCREEN_POPUP) {
+ // In some occassions the display needs more time to handle a screen change, for instance,
+ // with ADVANCED_PAUSE_FEATURE, the calls to ExtUI::onUserConfirmRequired are quite fast
+ DEBUG_ECHOLNPGM("Nudging the display to update the current screen...");
+ GotoScreen(current_screen, true);
+ }
+
+ if (!IsScreenComplete() || ELAPSED(ms, next_event_ms)) {
+ next_event_ms = ms + DGUS_UPDATE_INTERVAL_MS;
+ UpdateScreenVPData();
+
+ // Read which screen is currently triggered - navigation at display side may occur
+ if (dgusdisplay.isInitialized()) dgusdisplay.ReadCurrentScreen();
+ }
+
+ if (dgusdisplay.isInitialized()) {
+ static bool booted = false;
+ if (!booted) {
+ int16_t percentage = static_cast(((float) ms / (float)BOOTSCREEN_TIMEOUT) * 100);
+ if (percentage > 100) percentage = 100;
+
+ dgusdisplay.WriteVariable(VP_STARTPROGRESSBAR, percentage);
+ }
+
+ if (!booted && TERN0(POWER_LOSS_RECOVERY, recovery.valid())) {
+ booted = true;
+ DEBUG_ECHOLNPGM("Power loss recovery...");
+ }
+
+ if (!booted && ELAPSED(ms, BOOTSCREEN_TIMEOUT)) {
+ booted = true;
+ GotoScreen(DGUSLCD_SCREEN_MAIN);
+ }
+ }
+
+ return IsScreenComplete();
+}
+
+#endif // HAS_DGUS_LCD
diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h
new file mode 100644
index 0000000000..8b709c11bd
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h
@@ -0,0 +1,282 @@
+/**
+ * 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
+
+//#define DEBUG_DGUS_SCREEN_HANDLER
+
+#include "DGUSDisplay.h"
+#include "../dgus/DGUSVPVariable.h"
+
+#include "../../../../inc/MarlinConfig.h"
+
+#define DEBUG_OUT ENABLED(DEBUG_DGUS_SCREEN_HANDLER)
+#include "../../../../core/debug_out.h"
+
+enum DGUSLCD_Screens : uint8_t;
+
+class DGUSScreenHandler {
+public:
+ DGUSScreenHandler() = default;
+
+ static bool loop();
+
+ /// Send all 4 strings that are displayed on the infoscreen, confirmation screen and kill screen
+ /// The bools specifing whether the strings are in RAM or FLASH.
+ static void sendinfoscreen(const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
+
+ static void HandleUserConfirmationPopUp(uint16_t ConfirmVP, const char* line1, const char* line2, const char* line3, const char* line4, bool l1inflash, bool l2inflash, bool l3inflash, bool liinflash);
+
+ /// "M117" Message -- msg is a RAM ptr.
+ static void setstatusmessage(const char* msg);
+ /// The same for messages from Flash
+ static void setstatusmessagePGM(PGM_P const msg);
+ // Callback for VP "Display wants to change screen on idle printer"
+ static void ScreenChangeHookIfIdle(DGUS_VP_Variable &var, void *val_ptr);
+ // Callback for VP "Screen has been changed"
+ static void ScreenChangeHook(DGUS_VP_Variable &var, void *val_ptr);
+ // Callback for VP "All Heaters Off"
+ static void HandleAllHeatersOff(DGUS_VP_Variable &var, void *val_ptr);
+ // Hook for "Change this temperature"
+ static void HandleTemperatureChanged(DGUS_VP_Variable &var, void *val_ptr);
+ // Hook for "Change Flowrate"
+ static void HandleFlowRateChanged(DGUS_VP_Variable &var, void *val_ptr);
+ #if ENABLED(DGUS_UI_MOVE_DIS_OPTION)
+ // Hook for manual move option
+ static void HandleManualMoveOption(DGUS_VP_Variable &var, void *val_ptr);
+ #endif
+ // Hook for manual move.
+ static void HandleManualMove(DGUS_VP_Variable &var, void *val_ptr);
+ // Hook for manual extrude.
+ static void HandleManualExtrude(DGUS_VP_Variable &var, void *val_ptr);
+ // Hook for motor lock and unlook
+ static void HandleMotorLockUnlock(DGUS_VP_Variable &var, void *val_ptr);
+ #if ENABLED(POWER_LOSS_RECOVERY)
+ // Hook for power loss recovery.
+ static void HandlePowerLossRecovery(DGUS_VP_Variable &var, void *val_ptr);
+ #endif
+ // Hook for settings
+ static void HandleSettings(DGUS_VP_Variable &var, void *val_ptr);
+ static void HandleStepPerMMChanged(DGUS_VP_Variable &var, void *val_ptr);
+ static void HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, void *val_ptr);
+
+ static void HandleFeedAmountChanged(DGUS_VP_Variable &var, void *val_ptr);
+
+ #if HAS_PID_HEATING
+ // Hook for "Change this temperature PID para"
+ static void HandleTemperaturePIDChanged(DGUS_VP_Variable &var, void *val_ptr);
+ // Hook for PID autotune
+ static void HandlePIDAutotune(DGUS_VP_Variable &var, void *val_ptr);
+ #endif
+ #if HAS_BED_PROBE
+ // Hook for "Change probe offset z"
+ static void HandleZoffsetChange(DGUS_VP_Variable &var, void *val_ptr);
+
+ static void HandleProbeOffsetZChanged(DGUS_VP_Variable &var, void *val_ptr);
+
+ static void OnMeshLevelingStart();
+
+ static void OnMeshLevelingUpdate(const int8_t xpos, const int8_t ypos);
+ #endif
+ #if ENABLED(BABYSTEPPING)
+ // Hook for live z adjust action
+ static void HandleLiveAdjustZ(DGUS_VP_Variable &var, void *val_ptr);
+ #endif
+ #if HAS_FAN
+ // Hook for fan control
+ static void HandleFanControl(DGUS_VP_Variable &var, void *val_ptr);
+ #endif
+ // Hook for heater control
+ static void HandleHeaterControl(DGUS_VP_Variable &var, void *val_ptr);
+ #if ENABLED(DGUS_PREHEAT_UI)
+ // Hook for preheat
+ static void HandlePreheat(DGUS_VP_Variable &var, void *val_ptr);
+ #endif
+ #if ENABLED(DGUS_FILAMENT_LOADUNLOAD)
+ // Hook for filament load and unload filament option
+ static void HandleFilamentOption(DGUS_VP_Variable &var, void *val_ptr);
+ // Hook for filament load and unload
+ static void HandleFilamentLoadUnload(DGUS_VP_Variable &var);
+ #endif
+
+ #if ENABLED(SDSUPPORT)
+ // Callback for VP "Display wants to change screen when there is a SD card"
+ static void ScreenChangeHookIfSD(DGUS_VP_Variable &var, void *val_ptr);
+ /// Scroll buttons on the file listing screen.
+ static void DGUSLCD_SD_ScrollFilelist(DGUS_VP_Variable &var, void *val_ptr);
+ /// File touched.
+ static void DGUSLCD_SD_FileSelected(DGUS_VP_Variable &var, void *val_ptr);
+ /// start print after confirmation received.
+ static void DGUSLCD_SD_StartPrint(DGUS_VP_Variable &var, void *val_ptr);
+ /// User hit the pause, resume or abort button.
+ static void DGUSLCD_SD_ResumePauseAbort(DGUS_VP_Variable &var, void *val_ptr);
+ /// User confirmed the abort action
+ static void DGUSLCD_SD_ReallyAbort(DGUS_VP_Variable &var, void *val_ptr);
+ /// User hit the tune button
+ static void DGUSLCD_SD_PrintTune(DGUS_VP_Variable &var, void *val_ptr);
+ /// Send a single filename to the display.
+ static void DGUSLCD_SD_SendFilename(DGUS_VP_Variable &var);
+ /// Marlin informed us that a new SD has been inserted.
+ static void SDCardInserted();
+ /// Marlin informed us that the SD Card has been removed().
+ static void SDCardRemoved();
+ /// Marlin informed us about a bad SD Card.
+ static void SDCardError();
+ #endif
+
+ static void HandleLEDToggle();
+
+ static void HandleStepperState(bool is_enabled);
+
+ static void FilamentRunout();
+
+ static void OnFactoryReset();
+
+#if HAS_BUZZER
+ static void Buzzer(const uint16_t frequency, const uint16_t duration);
+#endif
+
+ static void OnHomingStart();
+ static void OnHomingComplete();
+ static void OnPrintFinished();
+
+ // OK Button the Confirm screen.
+ static void ScreenConfirmedOK(DGUS_VP_Variable &var, void *val_ptr);
+
+ // Update data after went to new screen (by display or by GotoScreen)
+ // remember: store the last-displayed screen, so it can get returned to.
+ // (e.g for pop up messages)
+ static void UpdateNewScreen(DGUSLCD_Screens newscreen, bool save_current_screen=true);
+
+ // Recall the remembered screen.
+ static void PopToOldScreen();
+
+ // Make the display show the screen and update all VPs in it.
+ static void GotoScreen(DGUSLCD_Screens screen, bool save_current_screen = true);
+
+ static void UpdateScreenVPData();
+
+ // Helpers to convert and transfer data to the display.
+ static void DGUSLCD_SendWordValueToDisplay(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendStringToDisplay(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendStringToDisplayPGM(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendTemperaturePID(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendPercentageToDisplay(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendPrintProgressToDisplay(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendPrintTimeToDisplay(DGUS_VP_Variable &var);
+ #if ENABLED(PRINTCOUNTER)
+ static void DGUSLCD_SendPrintAccTimeToDisplay(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendPrintsTotalToDisplay(DGUS_VP_Variable &var);
+ #endif
+ #if HAS_FAN
+ static void DGUSLCD_SendFanStatusToDisplay(DGUS_VP_Variable &var);
+ #endif
+ static void DGUSLCD_SendHeaterStatusToDisplay(DGUS_VP_Variable &var);
+ #if ENABLED(DGUS_UI_WAITING)
+ static void DGUSLCD_SendWaitingStatusToDisplay(DGUS_VP_Variable &var);
+ #endif
+
+ static void DGUSLCD_SendAboutFirmwareVersion(DGUS_VP_Variable &var);
+ static void DGUSLCD_SendAboutPrintSize(DGUS_VP_Variable &var);
+
+ /// Send a value from 0..100 to a variable with a range from 0..255
+ static void DGUSLCD_PercentageToUint8(DGUS_VP_Variable &var, void *val_ptr);
+
+ template
+ static void DGUSLCD_SetValueDirectly(DGUS_VP_Variable &var, void *val_ptr) {
+ if (!var.memadr) return;
+ union { unsigned char tmp[sizeof(T)]; T t; } x;
+ unsigned char *ptr = (unsigned char*)val_ptr;
+ LOOP_L_N(i, sizeof(T)) x.tmp[i] = ptr[sizeof(T) - i - 1];
+ *(T*)var.memadr = x.t;
+ }
+
+ /// Send a float value to the display.
+ /// Display will get a 4-byte integer scaled to the number of digits:
+ /// Tell the display the number of digits and it cheats by displaying a dot between...
+ template
+ static void DGUSLCD_SendFloatAsLongValueToDisplay(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ float f = *(float *)var.memadr;
+ f *= cpow(10, decimals);
+ dgusdisplay.WriteVariable(var.VP, (long)f);
+ }
+ }
+
+ // Send an icon to the display, depending on whether it is true or false
+ template
+ static void DGUSLCD_SendIconValue(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ bool value = *(bool *)var.memadr;
+ uint16_t valueToSend = value ? value_if_true : value_if_false;
+ dgusdisplay.WriteVariable(var.VP, valueToSend);
+ }
+ }
+
+ /// Send a float value to the display.
+ /// Display will get a 2-byte integer scaled to the number of digits:
+ /// Tell the display the number of digits and it cheats by displaying a dot between...
+ template
+ static void DGUSLCD_SendFloatAsIntValueToDisplay(DGUS_VP_Variable &var) {
+ if (var.memadr) {
+ float f = *(float *)var.memadr;
+ DEBUG_ECHOLNPAIR_F(" >> ", f, 6);
+ f *= cpow(10, decimals);
+ dgusdisplay.WriteVariable(var.VP, (int16_t)f);
+ }
+ }
+
+ /// Force an update of all VP on the current screen.
+ static inline void ForceCompleteUpdate() { update_ptr = 0; ScreenComplete = false; }
+ /// Has all VPs sent to the screen
+ static inline bool IsScreenComplete() { return ScreenComplete; }
+
+ static inline DGUSLCD_Screens getCurrentScreen() { return current_screen; }
+
+ static void updateCurrentScreen(DGUSLCD_Screens current);
+
+ static inline void SetupConfirmAction( void (*f)()) { confirm_action_cb = f; }
+
+ static float feed_amount;
+ static bool are_steppers_enabled;
+
+private:
+ static DGUSLCD_Screens current_screen; ///< currently on screen
+ static constexpr uint8_t NUM_PAST_SCREENS = 4;
+ static DGUSLCD_Screens past_screens[NUM_PAST_SCREENS]; ///< LIFO with past screens for the "back" button.
+
+ static uint8_t update_ptr; ///< Last sent entry in the VPList for the actual screen.
+ static uint16_t skipVP; ///< When updating the screen data, skip this one, because the user is interacting with it.
+ static bool ScreenComplete; ///< All VPs sent to screen?
+
+ static uint16_t ConfirmVP; ///< context for confirm screen (VP that will be emulated-sent on "OK").
+
+ static uint8_t MeshLevelIndex;
+
+ #if ENABLED(SDSUPPORT)
+ static int16_t top_file; ///< file on top of file chooser
+ static int16_t file_to_print; ///< touched file to be confirmed
+ #endif
+
+ static void (*confirm_action_cb)();
+};
+
+extern DGUSScreenHandler ScreenHandler;
diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.cpp b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.cpp
new file mode 100644
index 0000000000..75ed2feb1c
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.cpp
@@ -0,0 +1,350 @@
+/**
+ * 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 ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+
+#include "../DGUSDisplayDef.h"
+#include "../DGUSDisplay.h"
+#include "../DGUSScreenHandler.h"
+
+#include "../../../../../module/temperature.h"
+#include "../../../../../module/motion.h"
+#include "../../../../../module/planner.h"
+#include "../../../../../feature/pause.h"
+#include "../../../../../feature/runout.h"
+#include "../../../../../module/settings.h"
+
+#include "../../../../marlinui.h"
+#include "../../../ui_api.h"
+
+#include "PageHandlers.h"
+
+// Definitions of page handlers
+
+void MainMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ // Nothing
+}
+
+void ControlMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_PREPAREENTERKEY:
+ switch (buttonValue) {
+ case 5: // About
+ // Automatically handled
+ break;
+
+ case 7: // Reset to factory settings
+ settings.reset();
+ settings.save();
+ break;
+
+ case 9: // Back button
+ // TODO: should navigate automatically
+ break;
+ }
+ break;
+
+ case VP_BUTTON_ADJUSTENTERKEY:
+ ScreenHandler.HandleLEDToggle();
+ break;
+ }
+}
+
+void LevelingModeHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_BEDLEVELKEY:
+ switch (buttonValue) {
+ case 1:
+ if (ExtUI::isAxisPositionKnown(ExtUI::axis_t::X) && ExtUI::isAxisPositionKnown(ExtUI::axis_t::Y))
+ ExtUI::injectCommands_P("G28 Z");
+ else
+ ExtUI::injectCommands_P("G28");
+ break;
+
+ case 2:
+ // Increase Z-offset
+ ExtUI::smartAdjustAxis_steps(5, ExtUI::axis_t::Z, true);
+ ScreenHandler.ForceCompleteUpdate();
+ break;
+
+ case 3:
+ // Decrease Z-offset
+ ExtUI::smartAdjustAxis_steps(-5, ExtUI::axis_t::Z, true);
+ ScreenHandler.ForceCompleteUpdate();
+ break;
+ }
+
+ break;
+
+ case VP_BUTTON_MAINENTERKEY:
+ // Go to leveling screen
+ ExtUI::injectCommands_P("G28\nG29");
+ break;
+ }
+}
+
+void LevelingHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_BEDLEVELKEY:
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_ZOFFSET_LEVEL);
+
+ break;
+ }
+}
+
+void TempMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_ADJUSTENTERKEY:
+ switch (buttonValue) {
+ case 3:
+ DGUSScreenHandler::HandleFanControl(var, &buttonValue);
+ break;
+ }
+
+ break;
+ }
+}
+
+void PrepareMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_PREPAREENTERKEY:
+ // Disable steppers
+ ScreenHandler.HandleMotorLockUnlock(var, &buttonValue);
+ break;
+
+ case VP_BUTTON_COOLDOWN:
+ ScreenHandler.HandleAllHeatersOff(var, &buttonValue);
+ break;
+
+ case VP_BUTTON_TEMPCONTROL:
+ switch (buttonValue) {
+ case 5:
+ thermalManager.setTargetHotend(ui.material_preset[0].hotend_temp, 0);
+ thermalManager.setTargetBed(ui.material_preset[0].bed_temp);
+
+ break;
+
+ case 6:
+ thermalManager.setTargetHotend(ui.material_preset[1].hotend_temp, 0);
+ thermalManager.setTargetBed(ui.material_preset[1].bed_temp);
+ break;
+ }
+ break;
+ }
+
+ ScreenHandler.ForceCompleteUpdate();
+}
+
+void TuneMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_ADJUSTENTERKEY:
+ switch (buttonValue) {
+ case 2:
+ ScreenHandler.GotoScreen(ExtUI::isPrintingFromMediaPaused() ? DGUSLCD_SCREEN_PRINT_PAUSED : DGUSLCD_SCREEN_PRINT_RUNNING);
+ break;
+
+ case 3:
+ DGUSScreenHandler::HandleFanControl(var, &buttonValue);
+ break;
+
+ case 4:
+ ScreenHandler.HandleLEDToggle();
+ break;
+ }
+ }
+}
+
+void PrintRunningMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ // There are actually no buttons to handle here: all buttons navigate to other screens (like confirmation screens)
+}
+
+void PrintPausedMenuHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_RESUMEPRINTKEY:
+ runout.reset();
+ ExtUI::resumePrint();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_PRINT_RUNNING);
+ break;
+ }
+}
+
+void PrintPauseDialogHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_PAUSEPRINTKEY:
+ switch (buttonValue) {
+ case 2:
+ ExtUI::pausePrint();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_PRINT_PAUSED);
+ break;
+
+ case 3:
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_PRINT_RUNNING);
+ break;
+ }
+ break;
+ }
+}
+
+void FilamentRunoutHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_RESUMEPRINTKEY:
+ ExtUI::resumePrint();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_PRINT_RUNNING);
+ break;
+
+ case VP_BUTTON_STOPPRINTKEY:
+ ExtUI::stopPrint();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
+ break;
+ }
+}
+
+void StopConfirmScreenHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_STOPPRINTKEY:
+ switch (buttonValue) {
+ case 2:
+ ExtUI::stopPrint();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_MAIN);
+ break;
+
+ case 3:
+ ScreenHandler.GotoScreen(ExtUI::isPrintingFromMediaPaused() ? DGUSLCD_SCREEN_PRINT_PAUSED : DGUSLCD_SCREEN_PRINT_RUNNING);
+ break;
+ }
+ break;
+ }
+}
+
+void PreheatSettingsScreenHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ switch (var.VP) {
+ case VP_BUTTON_PREPAREENTERKEY:
+ // Save button, save settings and go back
+ settings.save();
+ ScreenHandler.GotoScreen(DGUSLCD_SCREEN_TEMP);
+ break;
+
+ case VP_BUTTON_COOLDOWN:
+ // Back button, discard settings
+ settings.load();
+ break;
+ }
+}
+
+void FeedHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
+ if (var.VP != VP_BUTTON_HEATLOADSTARTKEY) return;
+
+ switch (buttonValue) {
+ case 1:
+ if (ExtUI::getActualTemp_celsius(ExtUI::H0) < PREHEAT_1_TEMP_HOTEND) {
+ ExtUI::setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, ExtUI::H0);
+ thermalManager.wait_for_hotend(0);
+ }
+
+ dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(10));
+
+ load_filament(
+ FILAMENT_CHANGE_SLOW_LOAD_LENGTH,
+ FILAMENT_CHANGE_FAST_LOAD_LENGTH,
+ ScreenHandler.feed_amount,
+ FILAMENT_CHANGE_ALERT_BEEPS,
+ false,
+ thermalManager.still_heating(0),
+ PAUSE_MODE_LOAD_FILAMENT
+ );
+
+ dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(0));
+ break;
+
+ case 2:
+ if (ExtUI::getActualTemp_celsius(ExtUI::H0) < PREHEAT_1_TEMP_HOTEND) {
+ ExtUI::setTargetTemp_celsius(PREHEAT_1_TEMP_HOTEND, ExtUI::H0);
+ thermalManager.wait_for_hotend(0);
+ }
+
+ dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(10));
+
+ unload_filament(ScreenHandler.feed_amount, false, PAUSE_MODE_UNLOAD_FILAMENT);
+
+ dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(0));
+ break;
+ }
+
+ ScreenHandler.ForceCompleteUpdate();
+}
+
+// Register the page handlers
+#define PAGE_HANDLER(SCRID, HDLRPTR) { .ScreenID = SCRID, .Handler = HDLRPTR },
+
+const struct PageHandler PageHandlers[] PROGMEM = {
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_MAIN, MainMenuHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_CONTROL, ControlMenuHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_ZOFFSET_LEVEL, LevelingModeHandler)
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_LEVELING, LevelingHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_TEMP, TempMenuHandler)
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_TEMP_PLA, PreheatSettingsScreenHandler)
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_TEMP_ABS, PreheatSettingsScreenHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_TUNING, TuneMenuHandler)
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_FEED, FeedHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_FILAMENTRUNOUT1, FilamentRunoutHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_DIALOG_STOP, StopConfirmScreenHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_PRINT_RUNNING, PrintRunningMenuHandler)
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_PRINT_PAUSED, PrintPausedMenuHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_DIALOG_PAUSE, PrintPauseDialogHandler)
+
+ PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_PREPARE, PrepareMenuHandler)
+
+ // Terminating
+ PAGE_HANDLER(static_cast(0), 0)
+};
+
+void DGUSCrealityDisplay_HandleReturnKeyEvent(DGUS_VP_Variable &var, void *val_ptr) {
+ const struct PageHandler *map = PageHandlers;
+ const uint16_t *ret;
+ const DGUSLCD_Screens current_screen = DGUSScreenHandler::getCurrentScreen();
+
+ while ((ret = (uint16_t*) pgm_read_ptr(&(map->Handler)))) {
+ if (map->ScreenID == current_screen) {
+ unsigned short button_value = *static_cast(val_ptr);
+ button_value = (button_value & 0xffU) << 8U | (button_value >> 8U);
+
+ SERIAL_ECHOPAIR("Invoking handler for screen ", current_screen);
+ SERIAL_ECHOLNPAIR("with VP=", var.VP, " value=", button_value);
+
+ map->Handler(var, button_value);
+ return;
+ }
+
+ map++;
+ }
+}
+
+#endif // DGUS_LCD_UI_CREALITY_TOUCH
diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.h b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.h
new file mode 100644
index 0000000000..b0ac14f48a
--- /dev/null
+++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.h
@@ -0,0 +1,11 @@
+#pragma once
+
+// Mapping of handlers per page. This construction is necessary because the CR-6 touch screen re-uses the same button IDs all over the place.
+typedef void (*DGUS_CREALITY_SCREEN_BUTTON_HANDLER)(DGUS_VP_Variable &var, unsigned short buttonValue);
+
+struct PageHandler {
+ DGUSLCD_Screens ScreenID;
+ DGUS_CREALITY_SCREEN_BUTTON_HANDLER Handler;
+};
+
+void DGUSCrealityDisplay_HandleReturnKeyEvent(DGUS_VP_Variable &var, void *val_ptr);
\ No newline at end of file
diff --git a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/marlin_events.cpp b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/marlin_events.cpp
index ed7e653af1..ce37256fad 100644
--- a/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/marlin_events.cpp
+++ b/Marlin/src/lcd/extui/lib/ftdi_eve_touch_ui/marlin_events.cpp
@@ -134,6 +134,8 @@ namespace ExtUI {
}
#if HAS_LEVELING && HAS_MESH
+ void onMeshLevelingStart() {}
+
void onMeshUpdate(const int8_t x, const int8_t y, const float val) {
BedMeshScreen::onMeshUpdate(x, y, val);
}
diff --git a/Marlin/src/lcd/extui/malyan_lcd.cpp b/Marlin/src/lcd/extui/malyan_lcd.cpp
index 5505a0dff7..bdbf3802ab 100644
--- a/Marlin/src/lcd/extui/malyan_lcd.cpp
+++ b/Marlin/src/lcd/extui/malyan_lcd.cpp
@@ -511,12 +511,15 @@ namespace ExtUI {
// Not needed for Malyan LCD
void onStatusChanged(const char * const) {}
- void onMediaInserted() {};
- void onMediaError() {};
- void onMediaRemoved() {};
+ void onMediaInserted() {}
+ void onMediaError() {}
+ void onMediaRemoved() {}
void onPlayTone(const uint16_t, const uint16_t) {}
void onFilamentRunout(const extruder_t extruder) {}
void onUserConfirmRequired(const char * const) {}
+ void onHomingStart() {}
+ void onHomingComplete() {}
+ void onPrintFinished() {}
void onFactoryReset() {}
void onStoreSettings(char*) {}
void onLoadSettings(const char*) {}
@@ -524,6 +527,7 @@ namespace ExtUI {
void onConfigurationStoreRead(bool) {}
#if HAS_MESH
+ void onMeshLevelingStart() {}
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval) {}
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const ExtUI::probe_state_t state) {}
#endif
@@ -531,6 +535,9 @@ namespace ExtUI {
#if ENABLED(POWER_LOSS_RECOVERY)
void onPowerLossResume() {}
#endif
+
+ void onSteppersDisabled() {}
+ void onSteppersEnabled() {}
}
#endif // MALYAN_LCD
diff --git a/Marlin/src/lcd/extui/ui_api.h b/Marlin/src/lcd/extui/ui_api.h
index c429a0aade..cdf9b4412a 100644
--- a/Marlin/src/lcd/extui/ui_api.h
+++ b/Marlin/src/lcd/extui/ui_api.h
@@ -140,6 +140,7 @@ namespace ExtUI {
bed_mesh_t& getMeshArray();
float getMeshPoint(const xy_uint8_t &pos);
void setMeshPoint(const xy_uint8_t &pos, const float zval);
+ void onMeshLevelingStart();
void onMeshUpdate(const int8_t xpos, const int8_t ypos, const float zval);
inline void onMeshUpdate(const xy_int8_t &pos, const float zval) { onMeshUpdate(pos.x, pos.y, zval); }
@@ -344,11 +345,16 @@ namespace ExtUI {
void onPrintTimerStarted();
void onPrintTimerPaused();
void onPrintTimerStopped();
+ void onPrintFinished();
void onFilamentRunout(const extruder_t extruder);
void onUserConfirmRequired(const char * const msg);
void onUserConfirmRequired_P(PGM_P const pstr);
void onStatusChanged(const char * const msg);
void onStatusChanged_P(PGM_P const pstr);
+ void onHomingStart();
+ void onHomingComplete();
+ void onSteppersDisabled();
+ void onSteppersEnabled();
void onFactoryReset();
void onStoreSettings(char *);
void onLoadSettings(const char *);
diff --git a/Marlin/src/libs/buzzer.h b/Marlin/src/libs/buzzer.h
index e901660c87..794ca2ed6d 100644
--- a/Marlin/src/libs/buzzer.h
+++ b/Marlin/src/libs/buzzer.h
@@ -115,9 +115,16 @@
// Buzz directly via the BEEPER pin tone queue
#define BUZZ(d,f) buzzer.tone(d, f)
+#elif ENABLED(DGUS_LCD_UI_CREALITY_TOUCH)
+
+ // Let extensible UI handle it
+ #include "../lcd/extui/ui_api.h"
+ #define BUZZ(d,f) ExtUI::onPlayTone(f, d)
+
#elif HAS_BUZZER
// Buzz indirectly via the MarlinUI instance
+ #include "../lcd/marlinui.h"
#define BUZZ(d,f) ui.buzz(d,f)
#else
diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp
index 03c8ddc462..e7a75ef377 100644
--- a/Marlin/src/module/motion.cpp
+++ b/Marlin/src/module/motion.cpp
@@ -1313,6 +1313,15 @@ void do_homing_move(const AxisEnum axis, const float distance, const feedRate_t
DEBUG_ECHOLNPGM(")");
}
+ #if ENABLED(STRAIN_GAUGE_PROBE) && PIN_EXISTS(OPTO_SWITCH)
+ if (axis == Z_AXIS) {
+ const bool in_probing_zone = READ(OPTO_SWITCH_PIN) == LOW;
+ probe.set_deployed(in_probing_zone);
+ endstops.enable_z_probe(in_probing_zone);
+ DEBUG_ECHOLNPAIR("Is in probing zone: ", int(in_probing_zone));
+ }
+ #endif
+
#if ALL(HOMING_Z_WITH_PROBE, HAS_HEATED_BED, WAIT_FOR_BED_HEATER)
// Wait for bed to heat back up between probing points
if (axis == Z_AXIS && distance < 0)
@@ -1593,6 +1602,13 @@ void homeaxis(const AxisEnum axis) {
}
#endif
+ #if ENABLED(STRAIN_GAUGE_PROBE) && PIN_EXISTS(OPTO_SWITCH)
+ if (axis == Z_AXIS) {
+ DEBUG_ECHOLNPAIR(">>> is_homing_z (", int(READ(OPTO_SWITCH_PIN)), ")");
+ is_homing_z = true;
+ }
+ #endif
+
// Fast move towards endstop until triggered
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("Home 1 Fast:");
diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h
index abc59f92b8..0296e41fd1 100644
--- a/Marlin/src/module/motion.h
+++ b/Marlin/src/module/motion.h
@@ -47,6 +47,10 @@ FORCE_INLINE bool homing_needed() {
return !TERN(HOME_AFTER_DEACTIVATE, all_axes_known, all_axes_homed)();
}
+#if ENABLED(STRAIN_GAUGE_PROBE)
+ extern bool is_homing_z;
+#endif
+
// Error margin to work around float imprecision
constexpr float fslop = 0.0001;
diff --git a/Marlin/src/module/probe.cpp b/Marlin/src/module/probe.cpp
index ff80063d65..c0c21b6904 100644
--- a/Marlin/src/module/probe.cpp
+++ b/Marlin/src/module/probe.cpp
@@ -556,6 +556,17 @@ float Probe::run_z_probe(const bool sanity_check/*=true*/) {
float probes[TOTAL_PROBING];
#endif
+ #if ENABLED(STRAIN_GAUGE_PROBE) && PINS_EXIST(OPTO_SWITCH, COM)
+ if (READ(OPTO_SWITCH_PIN) == LOW && is_homing_z) {
+ DEBUG_ECHOLNPGM("STRAIN_GAUGE_PROBE: Considering homing complete");
+ WRITE(COM_PIN, HIGH);
+ delay(200);
+ WRITE(COM_PIN, LOW);
+ delay(200);
+ is_homing_z = false;
+ }
+ #endif
+
#if TOTAL_PROBING > 2
float probes_z_sum = 0;
for (
@@ -684,6 +695,15 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
// Move the probe to the starting XYZ
do_blocking_move_to(npos);
+ #if ENABLED(STRAIN_GAUGE_PROBE) && PINS_EXIST(OPTO_SWITCH, COM)
+ if (READ(OPTO_SWITCH_PIN) == LOW) {
+ DEBUG_ECHOLNPGM("FIX_MOUNTED_PROBE: Setting COM_PIN low");
+ safe_delay(100);
+ WRITE(COM_PIN, LOW);
+ safe_delay(200);
+ }
+ #endif
+
float measured_z = NAN;
if (!deploy()) measured_z = run_z_probe(sanity_check) + offset.z;
if (!isnan(measured_z)) {
@@ -697,6 +717,11 @@ float Probe::probe_at_point(const float &rx, const float &ry, const ProbePtRaise
SERIAL_ECHOLNPAIR("Bed X: ", LOGICAL_X_POSITION(rx), " Y: ", LOGICAL_Y_POSITION(ry), " Z: ", measured_z);
}
+ #if ENABLED(STRAIN_GAUGE_PROBE) && PIN_EXISTS(COM)
+ DEBUG_ECHOLNPGM("STRAIN_GAUGE_PROBE: Setting COM_PIN high");
+ WRITE(COM_PIN, HIGH);
+ #endif
+
feedrate_mm_s = old_feedrate_mm_s;
if (isnan(measured_z)) {
diff --git a/Marlin/src/pins/pins.h b/Marlin/src/pins/pins.h
index 5eb4717e78..ce4a3e107d 100644
--- a/Marlin/src/pins/pins.h
+++ b/Marlin/src/pins/pins.h
@@ -579,6 +579,8 @@
#include "stm32f1/pins_CREALITY_V4.h" // STM32F1 env:STM32F103RET6_creality
#elif MB(CREALITY_V427)
#include "stm32f1/pins_CREALITY_V427.h" // STM32F1 env:STM32F103RET6_creality
+#elif MB(CREALITY_V452)
+ #include "stm32f1/pins_CREALITY_V452.h" // STM32F1 env:STM32F103RET6_creality
#elif MB(TRIGORILLA_PRO)
#include "stm32f1/pins_TRIGORILLA_PRO.h" // STM32F1 env:trigorilla_pro
#elif MB(FLY_MINI)
diff --git a/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h b/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h
new file mode 100644
index 0000000000..e6cdd1104c
--- /dev/null
+++ b/Marlin/src/pins/stm32f1/pins_CREALITY_V452.h
@@ -0,0 +1,150 @@
+/**
+ * Marlin 3D Printer Firmware
+ * Copyright (C) 2016 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 .
+ *
+ */
+
+/**
+ * Creality v4.5.2 (STM32F103) board pin assignments
+ */
+
+#if NOT_TARGET(__STM32F1__)
+ #error "Oops! Select an STM32F1 board in 'Tools > Board.'"
+#endif
+
+#if HOTENDS > 1 || E_STEPPERS > 1
+ #error "CREALITY supports up to 1 hotends / E-steppers. Comment out this line to continue."
+#endif
+
+#define BOARD_NAME "Creality v4.5.2"
+#define DEFAULT_MACHINE_NAME "Creality3D"
+
+//
+// EEPROM
+//
+#if NO_EEPROM_SELECTED
+ #define IIC_BL24CXX_EEPROM // EEPROM on I2C-0 used only for display settings
+ #if ENABLED(IIC_BL24CXX_EEPROM)
+ #define IIC_EEPROM_SDA PA11
+ #define IIC_EEPROM_SCL PA12
+ #define MARLIN_EEPROM_SIZE 0x800 // 2Kb (24C16)
+ #else
+ #define SDCARD_EEPROM_EMULATION // SD EEPROM until all EEPROM is BL24CXX
+ #define MARLIN_EEPROM_SIZE 0x800 // 2Kb
+ #endif
+#endif
+
+/* SPI */
+//#define SPI_EEPROM // EEPROM on SPI-0
+//#define SPI_CHAN_EEPROM1 ?
+//#define SPI_EEPROM1_CS ?
+// 2K EEPROM
+//#define SPI_EEPROM2_CS ?
+// 32Mb FLASH
+//#define SPI_FLASH_CS ?
+
+//
+// Limit Switches
+//
+#define X_MIN_PIN PC4
+//#define X_MAX_PIN PA7
+#define Y_MIN_PIN PC5
+#define Z_MIN_PIN PA4
+#define COM_PIN PA5
+
+//
+// Steppers
+//
+#define X_ENABLE_PIN PC3
+#define X_STEP_PIN PB8
+#define X_DIR_PIN PB7
+
+#define Y_ENABLE_PIN PC3
+#define Y_STEP_PIN PB6
+#define Y_DIR_PIN PB5
+
+#define Z_ENABLE_PIN PC3
+#define Z_STEP_PIN PB4
+#define Z_DIR_PIN PB3
+
+#define E0_ENABLE_PIN PC3
+#define E0_STEP_PIN PC2
+#define E0_DIR_PIN PB9
+
+#if HAS_TMC220x
+
+ //
+ // TMC2208 mode
+ //
+ //#define TMC2208_STANDALONE
+
+ #define X_HARDWARE_SERIAL MSerial2
+ #define Y_HARDWARE_SERIAL MSerial2
+ #define Z_HARDWARE_SERIAL MSerial2
+ #define E0_HARDWARE_SERIAL MSerial2
+
+ //
+ // TMC2208 Software serial
+ //
+ //#define HAVE_SW_SERIAL
+
+ // Reduce baud rate to improve software serial reliability
+ //#define TMC_BAUD_RATE 19200
+
+#endif
+
+//
+// Release PB4 (Z_STEP_PIN) from JTAG NRST role
+//
+#define DISABLE_DEBUG
+
+//
+// Temperature Sensors
+//
+#define TEMP_0_PIN PB1 // TH1
+#define TEMP_BED_PIN PB0 // TB1
+
+//
+// Heaters / Fans
+//
+//#define HEATER_0_PIN PB14 // HEATER1
+//#define HEATER_BED_PIN PB13 // HOT BED
+
+//#define FAN_PIN PB15 // FAN
+//#define FAN_SOFT_PWM
+
+#define HEATER_0_PIN PA1 // HEATER1
+#define HEATER_BED_PIN PA2 // HOT BED
+
+#define FAN_PIN PA0 // FAN
+#define FAN_SOFT_PWM
+
+#define SD_DETECT_PIN PC7
+#define NO_SD_HOST_DRIVE // This board's SD is only seen by the printer
+
+#define SDIO_SUPPORT // Extra added by Creality
+#define SDIO_CLOCK 6000000 // In original source code overridden by Creality in sdio.h
+
+#define CASE_LIGHT_PIN PA6
+
+#define FIL_RUNOUT_PIN PA7
+//#define OPTO_SWITCH_PIN PB2 // certification
+#define OPTO_SWITCH_PIN PC6
+
+#define TEMP_TIMER_CHAN 4 // Channel of the timer to use for compare and interrupts
diff --git a/buildroot/tests/STM32F103RET6_creality-tests b/buildroot/tests/STM32F103RET6_creality-tests
index ca723c7aa2..3076f54a05 100644
--- a/buildroot/tests/STM32F103RET6_creality-tests
+++ b/buildroot/tests/STM32F103RET6_creality-tests
@@ -13,4 +13,7 @@ use_example_configs "Creality/Ender-3 V2"
opt_enable MARLIN_DEV_MODE
exec_test $1 $2 "Ender 3 v2"
+use_example_configs "Creality/CR-6 SE"
+exec_test $1 $2 "Creality CR-6 SE"
+
restore_configs
diff --git a/platformio.ini b/platformio.ini
index 360a02f420..060ccfd029 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -237,6 +237,7 @@ HAS_GRAPHICAL_TFT = src_filter=+
DWIN_CREALITY_LCD = src_filter=+
IS_TFTGLCD_PANEL = src_filter=+
HAS_TOUCH_XPT2046 = src_filter=+
+DWIN_CREALITY_TOUCHLCD = src_filter=+
HAS_LCD_MENU = src_filter=+
HAS_GAMES = src_filter=+
MARLIN_BRICKOUT = src_filter=+