diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp index a2a5a57e7fb0..4be663d44488 100644 --- a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp +++ b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp @@ -72,7 +72,6 @@ bool DGUSScreenHandler::HasSynchronousOperation; bool DGUSScreenHandler::HasScreenVersionMismatch; uint8_t DGUSScreenHandler::MeshLevelIndex = -1; uint8_t DGUSScreenHandler::MeshLevelIconIndex = -1; -float DGUSScreenHandler::feed_amount = 100; bool DGUSScreenHandler::fwretract_available = TERN(FWRETRACT, true, false); bool DGUSScreenHandler::HasRGBSettings = TERN(HAS_COLOR_LEDS, true, false); @@ -1394,18 +1393,6 @@ void DGUSScreenHandler::HandleStepPerMMExtruderChanged(DGUS_VP_Variable &var, vo } #endif -void DGUSScreenHandler::HandleFeedAmountChanged(DGUS_VP_Variable &var, void *val_ptr) { - int16_t movevalue = swap16(*(uint16_t*)val_ptr); - float target = movevalue * 0.1f; - - 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; -} - void DGUSScreenHandler::HandleFadeHeight(DGUS_VP_Variable &var, void *val_ptr) { DGUSLCD_SetFloatAsIntFromDisplay<1>(var, val_ptr); diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h index 5c8a5755dd54..7c4565343a7c 100644 --- a/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h +++ b/Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h @@ -110,7 +110,6 @@ class DGUSScreenHandler { // Hook for settings 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); static void HandleFadeHeight(DGUS_VP_Variable &var, void *val_ptr); // Hook for move to position @@ -392,7 +391,6 @@ class DGUSScreenHandler { static void SetViewMeshLevelState(); - static float feed_amount; static bool fwretract_available; private: diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.cpp b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.cpp index 93a626f5d3dc..9ad04eb6fcbe 100644 --- a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.cpp +++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.cpp @@ -31,6 +31,7 @@ #include "../DGUSScreenHandler.h" #include "../creality_touch/AxisSettingsHandler.h" #include "../creality_touch/EstepsHandler.h" +#include "../creality_touch/FilamentLoadUnloadHandler.h" #include "../creality_touch/PIDHandler.h" #include "../creality_touch/MeshValidationHandler.h" @@ -130,7 +131,8 @@ const uint16_t VPList_Control[] PROGMEM = { const uint16_t VPList_Feed[] PROGMEM = { VPList_CommonWithStatus, - VP_FEED_AMOUNT, + VP_FILCHANGE_NOZZLE_TEMP, + VP_FILCHANGE_LENGTH, 0x0000 }; @@ -647,9 +649,6 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { VPHELPER(VP_TOGGLE_PROBE_SETTINGS_NAV_BUTTON, nullptr, (ScreenHandler.DGUSLCD_NavigateToPage), nullptr), #endif - // Feed - VPHELPER(VP_FEED_AMOUNT, &ScreenHandler.feed_amount, ScreenHandler.HandleFeedAmountChanged, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>), - // 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), @@ -712,8 +711,6 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #if HAS_COLOR_LEDS VPHELPER(VP_RGB_NAV_BUTTON, nullptr, ScreenHandler.DGUSLCD_NavigateToPage, nullptr), - - VPHELPER(VP_RGB_NAV_BUTTON, nullptr, ScreenHandler.DGUSLCD_NavigateToPage, nullptr), VPHELPER(VP_RGB_CONTROL_R, &leds.color.r, ScreenHandler.HandleLED, ScreenHandler.SendLEDToDisplay), VPHELPER(VP_RGB_CONTROL_G, &leds.color.g, ScreenHandler.HandleLED, ScreenHandler.SendLEDToDisplay), @@ -728,6 +725,13 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = { #endif #endif + // Filament load/unload + VPHELPER(VP_FILCHANGE_NAV_BUTTON, nullptr, (ScreenHandler.DGUSLCD_NavigateToPage), nullptr), + + VPHELPER(VP_FILCHANGE_LENGTH, &FilamentLoadUnloadHandler::length, ScreenHandler.DGUSLCD_SetFloatAsIntFromDisplay<1>, ScreenHandler.DGUSLCD_SendFloatAsIntValueToDisplay<1>), + VPHELPER(VP_FILCHANGE_NOZZLE_TEMP, &FilamentLoadUnloadHandler::nozzle_temperature, FilamentLoadUnloadHandler::HandleTemperature, ScreenHandler.DGUSLCD_SendWordValueToDisplay), + VPHELPER(VP_FILCHANGE_ACTION_BUTTON, nullptr, FilamentLoadUnloadHandler::HandleLoadUnloadButton, nullptr), + // Icons VPHELPER(VP_LED_TOGGLE, &caselight.on, nullptr, (ScreenHandler.DGUSLCD_SendIconValue)), VPHELPER(VP_STANDBY_BACKLIGHT_ICON, &ScreenHandler.Settings.display_standby, nullptr, (ScreenHandler.DGUSLCD_SendIconValue)), diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.h b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.h index c2e2861e5fd1..6cfd9cb9287a 100644 --- a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.h +++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/DGUSDisplayDef.h @@ -309,10 +309,6 @@ constexpr uint16_t VP_BUTTON_HEATLOADSTARTKEY = 0x1056; constexpr uint16_t VP_FAN_TOGGLE = 0x101E; constexpr uint16_t VP_LED_TOGGLE = 0x101F; -// Feed / retract -constexpr uint16_t VP_FEED_AMOUNT = 0x1054; -constexpr uint16_t VP_FEED_PROGRESS = 0x108e; - // Axis settings constexpr uint16_t VP_AXIS_SETTINGS_NAV_BUTTON = 0x22D9; constexpr uint16_t AXIS_SETTINGS_NAV_BUTTON_VAL_X = 1; @@ -514,6 +510,15 @@ constexpr uint16_t VP_RGB_NAV_BUTTON_ICON = 0x239E; constexpr uint16_t ICON_RGB_SETTINGS_AVAILABLE = 28; constexpr uint16_t ICON_RGB_SETTINGS_UNAVAILABLE = 29; +// Filament load/unload +constexpr uint16_t VP_FILCHANGE_NAV_BUTTON = 0x23a6; + +constexpr uint16_t VP_FILCHANGE_NOZZLE_TEMP = 0x23a0; +constexpr uint16_t VP_FILCHANGE_LENGTH = 0x23a2; + +constexpr uint16_t VP_FILCHANGE_ACTION_BUTTON = 0x23a4; +constexpr uint16_t FILCHANGE_ACTION_UNLOAD_BUTTON = 1; +constexpr uint16_t FILCHANGE_ACTION_LOAD_BUTTON = 2; // Icons constexpr uint16_t ICON_TOGGLE_ON = 1; diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/FilamentLoadUnloadHandler.cpp b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/FilamentLoadUnloadHandler.cpp new file mode 100644 index 000000000000..837c6bbaa374 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/FilamentLoadUnloadHandler.cpp @@ -0,0 +1,106 @@ +#include "../../../../../inc/MarlinConfigPre.h" + +#if ENABLED(DGUS_LCD_UI_CREALITY_TOUCH) + +#include "../DGUSDisplayDef.h" +#include "../DGUSDisplay.h" +#include "../DGUSScreenHandler.h" + +#include "FilamentLoadUnloadHandler.h" + +#include "../../../ui_api.h" +#include "../../../../marlinui.h" + +#include "../../../../../module/temperature.h" +#include "../../../../../module/settings.h" +#include "../../../../../module/planner.h" +#include "../../../../../gcode/gcode.h" + +celsius_t FilamentLoadUnloadHandler::nozzle_temperature = 0; +float FilamentLoadUnloadHandler::length = 0; + +void FilamentLoadUnloadHandler::Init() { + nozzle_temperature = ui.material_preset[0].hotend_temp; + length = 150; + + if (ExtUI::isPrinting()) { + nozzle_temperature = ExtUI::getTargetTemp_celsius(ExtUI::extruder_t::E0); + } +} + +void FilamentLoadUnloadHandler::HandleTemperature(DGUS_VP_Variable &var, void *val_ptr) { + ScreenHandler.DGUSLCD_SetValueDirectly(var, val_ptr); + + ValidateTemperatures(); +} + +void FilamentLoadUnloadHandler::HandleLoadUnloadButton(DGUS_VP_Variable &var, void *val_ptr) { + // Common for load/unload -> determine minimum temperature + if (length < 0.1) { + SetStatusMessage("Invalid feed length"); + return; + } + + if (ExtUI::isPrinting() && !ExtUI::isPrintingPaused()) { + SetStatusMessage(PSTR("Please pause print first")); + return; + } + + DGUSSynchronousOperation syncOperation; + uint16_t button_value = uInt16Value(val_ptr); + switch (button_value) { + case FILCHANGE_ACTION_LOAD_BUTTON: + syncOperation.start(); + + ChangeFilamentWithTemperature(PSTR("M701 L%f P0")); + + syncOperation.done(); + break; + + case FILCHANGE_ACTION_UNLOAD_BUTTON: + syncOperation.start(); + + ChangeFilamentWithTemperature(PSTR("M702 U%f")); + + syncOperation.done(); + break; + } + +} + +void FilamentLoadUnloadHandler::ValidateTemperatures() { + LIMIT(nozzle_temperature, EXTRUDE_MINTEMP, HEATER_0_MAXTEMP - HOTEND_OVERSHOOT); +} + +void FilamentLoadUnloadHandler::ChangeFilamentWithTemperature(PGM_P command) { + // Heat if necessary + if (ExtUI::getActualTemp_celsius(ExtUI::E0) < nozzle_temperature && abs(ExtUI::getActualTemp_celsius(ExtUI::E0) - nozzle_temperature) > THERMAL_PROTECTION_HYSTERESIS) { + SetStatusMessage(PSTR("Heating up...")); + + uint16_t target_celsius = nozzle_temperature; + NOMORE(target_celsius, thermalManager.hotend_max_target(0)); + + thermalManager.setTargetHotend(target_celsius, ExtUI::H0); + thermalManager.wait_for_hotend(ExtUI::H0, false); + } + + // Inject load filament command + SetStatusMessage(PSTR("Filament load/unload...")); + + char cmd[64]; + sprintf_P(cmd, command, length); + + // Handle commands + SERIAL_ECHOPAIR("Injecting command: ", cmd); + GcodeSuite::process_subcommands_now(cmd); + SERIAL_ECHOPGM_P("- done"); + + if (ScreenHandler.Settings.display_sound) ScreenHandler.Buzzer(500, 100); + SetStatusMessage(PSTR("Filament load/unload complete")); +} + +void FilamentLoadUnloadHandler::SetStatusMessage(PGM_P statusMessage) { + ScreenHandler.setstatusmessagePGM(statusMessage); +} + +#endif \ No newline at end of file diff --git a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/FilamentLoadUnloadHandler.h b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/FilamentLoadUnloadHandler.h new file mode 100644 index 000000000000..531439a965d9 --- /dev/null +++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/FilamentLoadUnloadHandler.h @@ -0,0 +1,22 @@ + +#pragma once + +#include + +class FilamentLoadUnloadHandler { + public: + static void Init(); + + static void HandleTemperature(DGUS_VP_Variable &var, void *val_ptr); + static void HandleLoadUnloadButton(DGUS_VP_Variable &var, void *val_ptr); + + public: + static celsius_t nozzle_temperature; + static float length; + + private: + static void ValidateTemperatures(); + static void ChangeFilamentWithTemperature(PGM_P command); + static void SetStatusMessage(PGM_P statusMessage); +}; + 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 index 50628fede505..8f6e91bbbecc 100644 --- a/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.cpp +++ b/Marlin/src/lcd/extui/lib/dgus_creality/creality_touch/PageHandlers.cpp @@ -352,73 +352,6 @@ void PreheatSettingsScreenHandler(DGUS_VP_Variable &var, unsigned short buttonVa } } -void change_filament_with_temp(PGM_P command, const uint16_t celsius) { - // Heat if necessary - if (ExtUI::getActualTemp_celsius(ExtUI::E0) < celsius && abs(ExtUI::getActualTemp_celsius(ExtUI::E0) - celsius) > THERMAL_PROTECTION_HYSTERESIS) { - ScreenHandler.setstatusmessagePGM(PSTR("Heating up...")); - - uint16_t target_celsius = celsius; - NOMORE(target_celsius, thermalManager.hotend_max_target(0)); - - thermalManager.setTargetHotend(target_celsius, ExtUI::H0); - thermalManager.wait_for_hotend(ExtUI::H0, false); - } - - // Inject load filament command - ScreenHandler.setstatusmessagePGM(PSTR("Filament load/unload...")); - - char cmd[64]; - sprintf_P(cmd, command, ScreenHandler.feed_amount); - - SERIAL_ECHOPAIR("Injecting command: ", cmd); - ExtUI::injectCommands(cmd); - - // Handle commands - SERIAL_ECHOPGM_P("- waiting for queue"); - queue.advance(); - planner.synchronize(); - - SERIAL_ECHOPGM_P("- done"); - - if (ScreenHandler.Settings.display_sound) ScreenHandler.Buzzer(500, 100); - ScreenHandler.setstatusmessagePGM(PSTR("Filament load/unload complete")); -} - -void FeedHandler(DGUS_VP_Variable &var, unsigned short buttonValue) { - if (var.VP != VP_BUTTON_HEATLOADSTARTKEY) return; - - // Common for load/unload -> determine minimum temperature - uint16_t celsius = static_cast(ExtUI::getTargetTemp_celsius(ExtUI::H0)); - if (celsius < PREHEAT_1_TEMP_HOTEND) { - celsius = PREHEAT_1_TEMP_HOTEND; - } - - DGUSSynchronousOperation syncOperation; - switch (buttonValue) { - case 1: - syncOperation.start(); - dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(10)); - - change_filament_with_temp(PSTR("M701 L%f P0"), celsius); - - dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(0)); - syncOperation.done(); - break; - - case 2: - syncOperation.start(); - dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(10)); - - change_filament_with_temp(PSTR("M702 U%f"), celsius); - - dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast(0)); - syncOperation.done(); - break; - } - - ScreenHandler.ForceCompleteUpdate(); -} - void MoveHandler(DGUS_VP_Variable &var, unsigned short buttonValue) { if (var.VP == VP_BUTTON_MOVEKEY) { switch (buttonValue) { @@ -464,7 +397,6 @@ const struct PageHandler PageHandlers[] PROGMEM = { 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_MOVE01MM, MoveHandler) PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_MOVE1MM, MoveHandler) PAGE_HANDLER(DGUSLCD_Screens::DGUSLCD_SCREEN_MOVE10MM, MoveHandler)