Skip to content

Commit

Permalink
🚸 ProUI MPC menu (MarlinFirmware#25232)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
mriscoc and thinkyhead authored Jan 17, 2023
1 parent 99d1b04 commit b3f65b6
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 175 deletions.
8 changes: 7 additions & 1 deletion Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2504,9 +2504,15 @@
// PID heating
#if ANY(PIDTEMP, PIDTEMPBED, PIDTEMPCHAMBER)
#define HAS_PID_HEATING 1
#if ENABLED(DWIN_LCD_PROUI) && EITHER(PIDTEMP, PIDTEMPBED)
#endif

#if ENABLED(DWIN_LCD_PROUI)
#if EITHER(PIDTEMP, PIDTEMPBED)
#define DWIN_PID_TUNE 1
#endif
#if EITHER(DWIN_PID_TUNE, MPCTEMP) && DISABLED(DISABLE_TUNING_GRAPH)
#define SHOW_TUNING_GRAPH 1
#endif
#endif

// Thermal protection
Expand Down
200 changes: 136 additions & 64 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,37 +31,6 @@

#if ENABLED(DWIN_LCD_PROUI)

#if DISABLED(LIMITED_MAX_FR_EDITING)
#warning "LIMITED_MAX_FR_EDITING is recommended with ProUI."
#endif
#if DISABLED(LIMITED_MAX_ACCEL_EDITING)
#warning "LIMITED_MAX_ACCEL_EDITING is recommended with ProUI."
#endif
#if ENABLED(CLASSIC_JERK) && DISABLED(LIMITED_JERK_EDITING)
#warning "LIMITED_JERK_EDITING is recommended with ProUI."
#endif
#if DISABLED(INDIVIDUAL_AXIS_HOMING_SUBMENU)
#warning "INDIVIDUAL_AXIS_HOMING_SUBMENU is recommended with ProUI."
#endif
#if DISABLED(SET_PROGRESS_MANUALLY)
#warning "SET_PROGRESS_MANUALLY is recommended with ProUI."
#endif
#if DISABLED(STATUS_MESSAGE_SCROLLING)
#warning "STATUS_MESSAGE_SCROLLING is recommended with ProUI."
#endif
#if DISABLED(BAUD_RATE_GCODE)
#warning "BAUD_RATE_GCODE is recommended with ProUI."
#endif
#if DISABLED(SOUND_MENU_ITEM)
#warning "SOUND_MENU_ITEM is recommended with ProUI."
#endif
#if DISABLED(PRINTCOUNTER)
#warning "PRINTCOUNTER is recommended with ProUI."
#endif
#if HAS_MESH && DISABLED(MESH_EDIT_MENU)
#warning "MESH_EDIT_MENU is recommended with ProUI."
#endif

#include "../../fontutils.h"
#include "../../marlinui.h"

Expand Down Expand Up @@ -142,7 +111,7 @@
#include "endstop_diag.h"
#endif

#if HAS_PIDPLOT
#if SHOW_TUNING_GRAPH
#include "plot.h"
#endif

Expand Down Expand Up @@ -297,6 +266,9 @@ MenuClass *MaxAccelMenu = nullptr;
MenuClass *MaxJerkMenu = nullptr;
#endif
MenuClass *StepsMenu = nullptr;
#if ENABLED(MPCTEMP)
MenuClass *HotendMPCMenu = nullptr;
#endif
#if ENABLED(PIDTEMP)
MenuClass *HotendPIDMenu = nullptr;
#endif
Expand Down Expand Up @@ -1275,8 +1247,8 @@ void EachMomentUpdate() {
#if HAS_ESDIAG
if (checkkey == ESDiagProcess) ESDiag.Update();
#endif
#if HAS_PIDPLOT
if (checkkey == PidProcess) Plot.Update((HMI_value.pidresult == PIDTEMP_START) ? thermalManager.wholeDegHotend(0) : thermalManager.wholeDegBed());
#if SHOW_TUNING_GRAPH
if (checkkey == PidProcess) plot.Update((HMI_value.pidresult == PIDTEMP_START) ? thermalManager.wholeDegHotend(0) : thermalManager.wholeDegBed());
#endif
}

Expand Down Expand Up @@ -1498,36 +1470,64 @@ void DWIN_LevelingDone() {
}
#endif

// PID process
// PID/MPC process

#if BOTH(HAS_PIDPLOT, DWIN_PID_TUNE)
#if SHOW_TUNING_GRAPH

#include "plot.h"

void DWIN_Draw_PIDPopup() {
frame_rect_t gfrm = { 40, 180, DWIN_WIDTH - 80, 120 };
celsius_t _maxtemp, _target;
void DWIN_Draw_PID_MPC_Popup() {
constexpr frame_rect_t gfrm = { 40, 180, DWIN_WIDTH - 80, 120 };
DWINUI::ClearMainArea();
Draw_Popup_Bkgd();
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_PID_AUTOTUNE));
DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("PID target: Celsius"));
switch (HMI_value.pidresult) {
#if ENABLED(PIDTEMP)

#if ENABLED(MPCTEMP)

switch (HMI_value.pidresult) {
case MPCTEMP_START:
_maxtemp = thermalManager.hotend_maxtemp[0];
_target = 200;
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_MPC_AUTOTUNE));
DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("MPC target: Celsius"));
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for Nozzle is running."));
break;
case PIDTEMPBED_START:
_maxtemp = BED_MAXTEMP;
_target = HMI_data.BedPidT;
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_PID_AUTOTUNE));
DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("PID target: Celsius"));
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for BED is running."));
break;
default: return;
}

#else // PID

DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 100, GET_TEXT_F(MSG_PID_AUTOTUNE));
DWINUI::Draw_String(HMI_data.PopupTxt_Color, gfrm.x, gfrm.y - DWINUI::fontHeight() - 4, F("PID target: Celsius"));

switch (HMI_value.pidresult) {
case PIDTEMP_START:
_maxtemp = thermalManager.hotend_maxtemp[0];
_target = HMI_data.HotendPidT;
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for Nozzle is running."));
Plot.Draw(gfrm, thermalManager.hotend_maxtemp[0], HMI_data.HotendPidT);
DWINUI::Draw_Int(HMI_data.PopupTxt_Color, 3, gfrm.x + 90, gfrm.y - DWINUI::fontHeight() - 4, HMI_data.HotendPidT);
break;
#endif
#if ENABLED(PIDTEMPBED)
case PIDTEMPBED_START:
_maxtemp = BED_MAXTEMP;
_target = HMI_data.BedPidT;
DWINUI::Draw_CenteredString(HMI_data.PopupTxt_Color, 120, F("for BED is running."));
Plot.Draw(gfrm, BED_MAXTEMP, HMI_data.BedPidT);
DWINUI::Draw_Int(HMI_data.PopupTxt_Color, 3, gfrm.x + 90, gfrm.y - DWINUI::fontHeight() - 4, HMI_data.BedPidT);
break;
#endif
default: break;
}
default: return;
}

#endif // PID

plot.Draw(gfrm, _maxtemp, _target);
DWINUI::Draw_Int(HMI_data.PopupTxt_Color, 3, gfrm.x + 90, gfrm.y - DWINUI::fontHeight() - 4, _target);
}

#endif
#endif // SHOW_TUNING_GRAPH

#if DWIN_PID_TUNE

Expand All @@ -1542,40 +1542,40 @@ void DWIN_LevelingDone() {
}
}

void DWIN_PidTuning(pidresult_t result) {
void DWIN_PidTuning(tempcontrol_t result) {
HMI_value.pidresult = result;
switch (result) {
#if ENABLED(PIDTEMP)
case PIDTEMP_START:
HMI_SaveProcessID(PidProcess);
#if HAS_PIDPLOT
DWIN_Draw_PIDPopup();
#if SHOW_TUNING_GRAPH
DWIN_Draw_PID_MPC_Popup();
#else
DWIN_Draw_Popup(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE), F("for Nozzle is running."));
#endif
break;
case PID_BAD_HEATER_ID:
case PID_TEMP_TOO_HIGH:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), GET_TEXT_F(MSG_BAD_HEATER_ID));
DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), GET_TEXT_F(MSG_TEMP_TOO_HIGH));
break;
#endif
#if ENABLED(PIDTEMPBED)
case PIDTEMPBED_START:
HMI_SaveProcessID(PidProcess);
#if HAS_PIDPLOT
DWIN_Draw_PIDPopup();
#if SHOW_TUNING_GRAPH
DWIN_Draw_PID_MPC_Popup();
#else
DWIN_Draw_Popup(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE), F("for BED is running."));
#endif
break;
#endif
case PID_TUNING_TIMEOUT:
case PID_BAD_HEATER_ID:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_ERROR), GET_TEXT_F(MSG_PID_TIMEOUT));
DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), GET_TEXT_F(MSG_PID_BAD_HEATER_ID));
break;
case PID_TEMP_TOO_HIGH:
case PID_TUNING_TIMEOUT:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), GET_TEXT_F(MSG_TEMP_TOO_HIGH));
DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_ERROR), GET_TEXT_F(MSG_PID_TIMEOUT));
break;
case PID_DONE:
checkkey = last_checkkey;
Expand All @@ -1589,6 +1589,43 @@ void DWIN_LevelingDone() {

#endif // DWIN_PID_TUNE

#if ENABLED(MPCTEMP)

void DWIN_MPCTuning(tempcontrol_t result) {
HMI_value.pidresult = result;
switch (result) {
case MPCTEMP_START:
HMI_SaveProcessID(MPCProcess);
#if SHOW_TUNING_GRAPH
DWIN_Draw_PID_MPC_Popup();
#else
DWIN_Draw_Popup(ICON_TempTooHigh, GET_TEXT_F(MSG_MPC_AUTOTUNE), F("for Nozzle is running."));
#endif
break;
case MPC_TEMP_ERROR:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_PID_AUTOTUNE_FAILED), F(STR_MPC_TEMPERATURE_ERROR));
ui.reset_alert_level();
break;
case MPC_INTERRUPTED:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooHigh, GET_TEXT_F(MSG_ERROR), F(STR_MPC_AUTOTUNE STR_MPC_AUTOTUNE_INTERRUPTED));
ui.reset_alert_level();
break;
case MPC_DONE:
checkkey = last_checkkey;
DWIN_Popup_Confirm(ICON_TempTooLow, GET_TEXT_F(MSG_MPC_AUTOTUNE), GET_TEXT_F(MSG_BUTTON_DONE));
ui.reset_alert_level();
break;
default:
checkkey = last_checkkey;
ui.reset_alert_level();
break;
}
}

#endif // MPCTEMP

// Started a Print Job
void DWIN_Print_Started() {
DEBUG_ECHOLNPGM("DWIN_Print_Started: ", SD_Printing());
Expand Down Expand Up @@ -3054,7 +3091,7 @@ void Draw_Control_Menu() {

void Draw_AdvancedSettings_Menu() {
checkkey = Menu;
if (SET_MENU(AdvancedSettings, MSG_ADVANCED_SETTINGS, 18)) {
if (SET_MENU(AdvancedSettings, MSG_ADVANCED_SETTINGS, 19)) {
BACK_ITEM(Goto_Main_Menu);
#if ENABLED(EEPROM_SETTINGS)
MENU_ITEM(ICON_WriteEEPROM, MSG_STORE_EEPROM, onDrawMenuItem, WriteEeprom);
Expand All @@ -3069,6 +3106,9 @@ void Draw_AdvancedSettings_Menu() {
#if ENABLED(PIDTEMP)
MENU_ITEM_F(ICON_PIDNozzle, STR_HOTEND_PID " Settings", onDrawSubMenu, Draw_HotendPID_Menu);
#endif
#if ENABLED(MPCTEMP)
MENU_ITEM_F(ICON_MPCNozzle, STR_MPC_AUTOTUNE " Settings", onDrawSubMenu, Draw_HotendMPC_Menu);
#endif
#if ENABLED(PIDTEMPBED)
MENU_ITEM_F(ICON_PIDBed, STR_BED_PID " Settings", onDrawSubMenu, Draw_BedPID_Menu);
#endif
Expand Down Expand Up @@ -3500,6 +3540,38 @@ void Draw_Steps_Menu() {

#endif

#if ENABLED(MPCTEMP)

void HotendMPC() { thermalManager.MPC_autotune(); }
void SetHeaterPower() { SetPFloatOnClick(1, 200, 1); }
void SetBlkHeatCapacity() { SetPFloatOnClick(0, 40, 2); }
void SetSensorRespons() { SetPFloatOnClick(0, 1, 4); }
void SetAmbientXfer() { SetPFloatOnClick(0, 1, 4); }
#if ENABLED(MPC_INCLUDE_FAN)
void onDrawFanAdj(MenuItemClass* menuitem, int8_t line) { onDrawFloatMenu(menuitem, line, 4, thermalManager.temp_hotend[0].fanCoefficient()); }
void ApplyFanAdj() { thermalManager.temp_hotend[0].applyFanAdjustment(MenuData.Value / POW(10, 4)); }
void SetFanAdj() { SetFloatOnClick(0, 1, 4, thermalManager.temp_hotend[0].fanCoefficient(), ApplyFanAdj); }
#endif

void Draw_HotendMPC_Menu() {
checkkey = Menu;
if (SET_MENU_F(HotendMPCMenu, STR_MPC_AUTOTUNE " Settings", 7)) {
MPC_t &mpc = thermalManager.temp_hotend[0].mpc;
BACK_ITEM(Draw_AdvancedSettings_Menu);
MENU_ITEM(ICON_MPCNozzle, MSG_MPC_AUTOTUNE, onDrawMenuItem, HotendMPC);
EDIT_ITEM(ICON_MPCHeater, MSG_MPC_POWER, onDrawPFloatMenu, SetHeaterPower, &mpc.heater_power);
EDIT_ITEM(ICON_MPCHeatCap, MSG_MPC_BLOCK_HEAT_CAPACITY, onDrawPFloat2Menu, SetBlkHeatCapacity, &mpc.block_heat_capacity);
EDIT_ITEM(ICON_MPCValue, MSG_SENSOR_RESPONSIVENESS, onDrawPFloat4Menu, SetSensorRespons, &mpc.sensor_responsiveness);
EDIT_ITEM(ICON_MPCValue, MSG_MPC_AMBIENT_XFER_COEFF, onDrawPFloat4Menu, SetAmbientXfer, &mpc.ambient_xfer_coeff_fan0);
#if ENABLED(MPC_INCLUDE_FAN)
EDIT_ITEM(ICON_MPCFan, MSG_MPC_AMBIENT_XFER_COEFF_FAN, onDrawFanAdj, SetFanAdj, &mpc.fan255_adjustment);
#endif
}
UpdateMenu(HotendMPCMenu);
}

#endif // MPCTEMP

#if ENABLED(PIDTEMPBED)

void Draw_BedPID_Menu() {
Expand Down
39 changes: 29 additions & 10 deletions Marlin/src/lcd/e3v2/proui/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,30 @@ enum processID : uint8_t {
WaitResponse,
Homing,
PidProcess,
MPCProcess,
NothingToDo
};

enum pidresult_t : uint8_t {
PIDTEMP_START = 0,
PIDTEMPBED_START,
PID_BAD_HEATER_ID,
PID_TEMP_TOO_HIGH,
PID_TUNING_TIMEOUT,
PID_DONE,
};
#if EITHER(DWIN_PID_TUNE, MPCTEMP)

enum tempcontrol_t : uint8_t {
#if DWIN_PID_TUNE
PID_DONE,
PIDTEMP_START,
PIDTEMPBED_START,
PID_BAD_HEATER_ID,
PID_TEMP_TOO_HIGH,
PID_TUNING_TIMEOUT,
#endif
#if ENABLED(MPCTEMP)
MPC_DONE,
MPCTEMP_START,
MPC_TEMP_ERROR,
MPC_INTERRUPTED
#endif
};

#endif

#define DWIN_CHINESE 123
#define DWIN_ENGLISH 0
Expand Down Expand Up @@ -142,7 +155,7 @@ static constexpr size_t eeprom_data_size = sizeof(HMI_data_t);
typedef struct {
int8_t Color[3]; // Color components
#if DWIN_PID_TUNE
pidresult_t pidresult = PID_DONE;
tempcontrol_t pidresult = PID_DONE;
#endif
uint8_t Select = 0; // Auxiliary selector variable
AxisEnum axis = X_AXIS; // Axis Select
Expand Down Expand Up @@ -361,11 +374,17 @@ void Draw_Steps_Menu();
#if DWIN_PID_TUNE
#include "../../../module/temperature.h"
void DWIN_StartM303(const bool seenC, const int c, const bool seenS, const heater_id_t hid, const celsius_t temp);
void DWIN_PidTuning(pidresult_t result);
void DWIN_PidTuning(tempcontrol_t result);
#if ENABLED(PIDTEMP)
void Draw_HotendPID_Menu();
#endif
#if ENABLED(PIDTEMPBED)
void Draw_BedPID_Menu();
#endif
#endif

// MPC
#if ENABLED(MPCTEMP)
void DWIN_MPCTuning(tempcontrol_t result);
void Draw_HotendMPC_Menu();
#endif
Loading

0 comments on commit b3f65b6

Please sign in to comment.