Skip to content

Commit

Permalink
Rework filament load/unload screen, make available from extra tuning …
Browse files Browse the repository at this point in the history
…screen #234
  • Loading branch information
Sebazzz committed Apr 12, 2021
1 parent 0387b2d commit 231aa74
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 93 deletions.
13 changes: 0 additions & 13 deletions Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions Marlin/src/lcd/extui/lib/dgus_creality/DGUSScreenHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -392,7 +391,6 @@ class DGUSScreenHandler {

static void SetViewMeshLevelState();

static float feed_amount;
static bool fwretract_available;

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
};
Expand Down Expand Up @@ -647,9 +649,6 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {
VPHELPER(VP_TOGGLE_PROBE_SETTINGS_NAV_BUTTON, nullptr, (ScreenHandler.DGUSLCD_NavigateToPage<DGUSLCD_SCREEN_LEVELING_SETTINGS>), 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),
Expand Down Expand Up @@ -712,8 +711,6 @@ const struct DGUS_VP_Variable ListOfVP[] PROGMEM = {

#if HAS_COLOR_LEDS
VPHELPER(VP_RGB_NAV_BUTTON, nullptr, ScreenHandler.DGUSLCD_NavigateToPage<DGUSLCD_SCREEN_RGB>, nullptr),

VPHELPER(VP_RGB_NAV_BUTTON, nullptr, ScreenHandler.DGUSLCD_NavigateToPage<DGUSLCD_SCREEN_RGB>, 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),
Expand All @@ -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<DGUSLCD_SCREEN_FEED, FilamentLoadUnloadHandler>), 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<ICON_LED_TOGGLE_ON, ICON_LED_TOGGLE_OFF>)),
VPHELPER(VP_STANDBY_BACKLIGHT_ICON, &ScreenHandler.Settings.display_standby, nullptr, (ScreenHandler.DGUSLCD_SendIconValue<ICON_TOGGLE_ON, ICON_TOGGLE_OFF>)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<uint16_t>(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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

#pragma once

#include <cstdint>

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);
};

Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(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<int16_t>(10));

change_filament_with_temp(PSTR("M701 L%f P0"), celsius);

dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast<int16_t>(0));
syncOperation.done();
break;

case 2:
syncOperation.start();
dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast<int16_t>(10));

change_filament_with_temp(PSTR("M702 U%f"), celsius);

dgusdisplay.WriteVariable(VP_FEED_PROGRESS, static_cast<int16_t>(0));
syncOperation.done();
break;
}

ScreenHandler.ForceCompleteUpdate();
}

void MoveHandler(DGUS_VP_Variable &var, unsigned short buttonValue) {
if (var.VP == VP_BUTTON_MOVEKEY) {
switch (buttonValue) {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 231aa74

Please sign in to comment.