Skip to content

Commit

Permalink
🚸 Fix, clean up ProUI (#26434)
Browse files Browse the repository at this point in the history
Co-authored-by: Scott Lahteine <thinkyhead@users.noreply.github.com>
  • Loading branch information
classicrocker883 and thinkyhead authored Nov 21, 2023
1 parent 20445b8 commit cc8f7c8
Show file tree
Hide file tree
Showing 14 changed files with 141 additions and 99 deletions.
8 changes: 1 addition & 7 deletions Marlin/src/inc/Conditionals_post.h
Original file line number Diff line number Diff line change
Expand Up @@ -2491,15 +2491,9 @@
// PID heating
#if ANY(PIDTEMP, PIDTEMPBED, PIDTEMPCHAMBER)
#define HAS_PID_HEATING 1
#endif

#if ENABLED(DWIN_LCD_PROUI)
#if ANY(PIDTEMP, PIDTEMPBED)
#if ENABLED(DWIN_LCD_PROUI) && ANY(PIDTEMP, PIDTEMPBED)
#define PROUI_PID_TUNE 1
#endif
#if ANY(PROUI_PID_TUNE, MPC_AUTOTUNE) && DISABLED(DISABLE_TUNING_GRAPH)
#define PROUI_TUNING_GRAPH 1
#endif
#endif

// Thermal protection
Expand Down
16 changes: 3 additions & 13 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -1533,15 +1533,15 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
* Allow only one bed leveling option to be defined
*/
#if MANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL, MESH_BED_LEVELING)
#error "Select only one of: MESH_BED_LEVELING, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
#error "Select only one of: MESH_BED_LEVELING, AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL."
#endif

/**
* Bed Leveling Requirements
*/

#if IS_SCARA && ANY(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_3POINT, AUTO_BED_LEVELING_UBL)
#error "SCARA machines can only use AUTO_BED_LEVELING_BILINEAR or MESH_BED_LEVELING leveling."
#error "SCARA machines can only use AUTO_BED_LEVELING_BILINEAR or MESH_BED_LEVELING."
#elif ENABLED(AUTO_BED_LEVELING_LINEAR) && !(WITHIN(GRID_MAX_POINTS_X, 2, 255) && WITHIN(GRID_MAX_POINTS_Y, 2, 255))
#error "GRID_MAX_POINTS_[XY] must be between 2 and 255 with AUTO_BED_LEVELING_LINEAR."
#elif ENABLED(AUTO_BED_LEVELING_BILINEAR) && !(WITHIN(GRID_MAX_POINTS_X, 3, 255) && WITHIN(GRID_MAX_POINTS_Y, 3, 255))
Expand Down Expand Up @@ -1610,7 +1610,7 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
#elif !(ENABLED(MESH_BED_LEVELING) || HAS_ABL_NOT_UBL)
#error "LCD_BED_LEVELING requires MESH_BED_LEVELING or AUTO_BED_LEVELING."
#elif ENABLED(MESH_EDIT_MENU) && !HAS_MESH
#error "MESH_EDIT_MENU requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR or AUTO_BED_LEVELING_UBL."
#error "MESH_EDIT_MENU requires MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, or AUTO_BED_LEVELING_UBL."
#endif
#endif

Expand Down Expand Up @@ -2746,16 +2746,6 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
#error "DWIN_LCD_PROUI requires SDSUPPORT to be enabled."
#elif ALL(LCD_BED_LEVELING, PROBE_MANUALLY)
#error "DWIN_LCD_PROUI does not support LCD_BED_LEVELING with PROBE_MANUALLY."
#elif ENABLED(MEDIASORT_MENU_ITEM) && DISABLED(SDCARD_SORT_ALPHA)
#error "MEDIASORT_MENU_ITEM requires SDCARD_SORT_ALPHA."
#elif ENABLED(RUNOUT_TUNE_ITEM) && DISABLED(HAS_FILAMENT_SENSOR)
#error "RUNOUT_TUNE_ITEM requires HAS_FILAMENT_SENSOR."
#elif ENABLED(PLR_TUNE_ITEM) && DISABLED(POWER_LOSS_RECOVERY)
#error "PLR_TUNE_ITEM requires POWER_LOSS_RECOVERY."
#elif ENABLED(JD_TUNE_ITEM) && DISABLED(HAS_JUNCTION_DEVIATION)
#error "JD_TUNE_ITEM requires HAS_JUNCTION_DEVIATION."
#elif ENABLED(ADVK_TUNE_ITEM) && DISABLED(LIN_ADVANCE)
#error "ADVK_TUNE_ITEM requires LIN_ADVANCE."
#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/lcd/e3v2/jyersui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ class TextScroller {

// Draw value text on
if (viewer_print_value) {
xy_int8_t offset { 0, cell_height_px / 2 - 6 };
xy_int_t offset { 0, cell_height_px / 2 - 6 };
if (isnan(bedlevel.z_values[x][y])) { // undefined
dwinDrawString(false, font6x12, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + cell_width_px / 2 - 5, start_y_px + offset.y, F("X"));
}
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/lcd/e3v2/proui/bedlevel_tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ float BedLevelTools::getMinValue() {
bool BedLevelTools::meshValidate() {
GRID_LOOP(x, y) {
const float v = bedlevel.z_values[x][y];
if (isnan(v) || !WITHIN(v, UBL_Z_OFFSET_MIN, UBL_Z_OFFSET_MAX)) return false;
if (isnan(v) || !WITHIN(v, Z_OFFSET_MIN, Z_OFFSET_MAX)) return false;
}
return true;
}
Expand Down Expand Up @@ -247,7 +247,7 @@ bool BedLevelTools::meshValidate() {
// Draw value text on
const uint8_t fs = DWINUI::fontWidth(meshfont);
if (viewer_print_value) {
xy_int8_t offset { 0, cell_height_px / 2 - fs };
xy_int_t offset { 0, cell_height_px / 2 - fs };
if (isnan(bedlevel.z_values[x][y])) { // undefined
dwinDrawString(false, meshfont, COLOR_WHITE, COLOR_BG_BLUE, start_x_px + cell_width_px / 2 - 5, start_y_px + offset.y, F("X"));
}
Expand Down
3 changes: 0 additions & 3 deletions Marlin/src/lcd/e3v2/proui/bedlevel_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,6 @@

#include "../../../inc/MarlinConfigPre.h"

#define UBL_Z_OFFSET_MIN -3.0
#define UBL_Z_OFFSET_MAX 3.0

class BedLevelTools {
public:
#if ENABLED(USE_GRID_MESHVIEWER)
Expand Down
69 changes: 30 additions & 39 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

#if ENABLED(DWIN_LCD_PROUI)

#include "dwin.h"
#include "menus.h"
#include "dwin_popup.h"

#include "../../utf8.h"
#include "../../marlinui.h"
#include "../../../MarlinCore.h"
Expand Down Expand Up @@ -105,10 +109,6 @@
#include "../../../feature/tmc_util.h"
#endif

#include "dwin.h"
#include "menus.h"
#include "dwin_popup.h"

#if HAS_GCODE_PREVIEW
#include "gcode_preview.h"
#endif
Expand Down Expand Up @@ -268,7 +268,7 @@ Menu *stepsMenu = nullptr;
#endif
#if HAS_MESH
Menu *meshMenu = nullptr;
#if ENABLED(MESH_EDIT_MENU)
#if ENABLED(PROUI_MESH_EDIT)
Menu *editMeshMenu = nullptr;
#endif
#endif
Expand Down Expand Up @@ -847,7 +847,7 @@ void updateVariable() {

bool DWIN_lcd_sd_status = false;

#if ENABLED(MEDIASORT_MENU_ITEM)
#if ENABLED(PROUI_MEDIASORT)
void setMediaSort() {
toggleCheckboxLine(hmiData.mediaSort);
card.setSortOn(hmiData.mediaSort ? TERN(SDSORT_REVERSE, AS_REV, AS_FWD) : AS_OFF);
Expand Down Expand Up @@ -985,9 +985,8 @@ void drawPrintFileMenu() {
if (card.isMounted()) {
if (SET_MENU(fileMenu, MSG_MEDIA_MENU, nr_sd_menu_items() + 1)) {
BACK_ITEM(gotoMainMenu);
for (uint8_t i = 0; i < nr_sd_menu_items(); ++i) {
for (uint8_t i = 0; i < nr_sd_menu_items(); ++i)
menuItemAdd(onDrawFileName, onClickSDItem);
}
}
updateMenu(fileMenu);
TERN_(DASH_REDRAW, dwinRedrawDash());
Expand Down Expand Up @@ -1022,7 +1021,6 @@ void hmiSDCardUpdate() {
*/

void dwinDrawDashboard() {

dwinDrawRectangle(1, hmiData.colorBackground, 0, STATUS_Y + 21, DWIN_WIDTH, DWIN_HEIGHT - 1);
dwinDrawRectangle(1, hmiData.colorSplitLine, 0, 449, DWIN_WIDTH, 451);

Expand Down Expand Up @@ -1067,7 +1065,7 @@ void dwinDrawDashboard() {
void drawInfoMenu() {
DWINUI::clearMainArea();
if (hmiIsChinese())
title.frameCopy(30, 17, 28, 13); // "Info"
title.frameCopy(30, 17, 28, 13); // "Info"
else
title.showCaption(GET_TEXT_F(MSG_INFO_SCREEN));
drawMenuLine(0, ICON_Back, GET_TEXT_F(MSG_BACK), false, true);
Expand Down Expand Up @@ -1124,7 +1122,7 @@ void hmiMainMenu() {
if (hmiData.mediaAutoMount) {
card.mount();
safe_delay(800);
};
}
drawPrintFileMenu();
break;
case PAGE_PREPARE: drawPrepareMenu(); break;
Expand Down Expand Up @@ -1759,7 +1757,7 @@ void dwinSetDataDefaults() {
#if ALL(LCD_BED_TRAMMING, HAS_BED_PROBE)
hmiData.fullManualTramming = DISABLED(BED_TRAMMING_USE_PROBE);
#endif
#if ENABLED(MEDIASORT_MENU_ITEM)
#if ENABLED(PROUI_MEDIASORT)
hmiData.mediaSort = true;
card.setSortOn(TERN(SDSORT_REVERSE, AS_REV, AS_FWD));
#endif
Expand Down Expand Up @@ -2710,7 +2708,7 @@ void onDrawGetColorItem(MenuItem* menuitem, int8_t line) {
dwinDrawRectangle(0, hmiData.colorHighlight, ICOX + 1, MBASE(line) - 1 + 1, ICOX + 18, MBASE(line) - 1 + 18);
dwinDrawRectangle(1, color, ICOX + 2, MBASE(line) - 1 + 2, ICOX + 17, MBASE(line) - 1 + 17);
DWINUI::drawString(LBLX, MBASE(line) - 1, menuitem->caption);
drawMenuIntValue(hmiData.colorBackground, line, 4, hmiValue.Color[i]);
drawMenuIntValue(hmiData.colorBackground, line, 4, hmiValue.color[i]);
dwinDrawHLine(hmiData.colorSplitLine, 16, MYPOS(line + 1), 240);
}

Expand Down Expand Up @@ -2976,10 +2974,6 @@ void onDrawAcc(MenuItem* menuitem, int8_t line) {

#endif

#if HAS_ONESTEP_LEVELING
void onDrawManualTramming(MenuItem* menuitem, int8_t line) { onDrawChkbMenu(menuitem, line, hmiData.fullManualTramming); }
#endif

// Menu Creation and Drawing functions ======================================================

frame_rect_t selrect(frame_rect_t) {
Expand Down Expand Up @@ -3130,7 +3124,7 @@ void drawAdvancedSettingsMenu() {
#if HAS_GCODE_PREVIEW
EDIT_ITEM(ICON_File, MSG_HAS_PREVIEW, onDrawChkbMenu, setPreview, &hmiData.enablePreview);
#endif
#if ENABLED(MEDIASORT_MENU_ITEM)
#if ENABLED(PROUI_MEDIASORT)
EDIT_ITEM(ICON_File, MSG_MEDIA_SORT, onDrawChkbMenu, setMediaSort, &hmiData.mediaSort);
#endif
EDIT_ITEM(ICON_File, MSG_MEDIA_UPDATE, onDrawChkbMenu, setMediaAutoMount, &hmiData.mediaAutoMount);
Expand Down Expand Up @@ -3323,16 +3317,16 @@ void drawTuneMenu() {
#if HAS_FILAMENT_SENSOR
EDIT_ITEM(ICON_Runout, MSG_RUNOUT_ENABLE, onDrawChkbMenu, setRunoutEnable, &runout.enabled);
#endif
#if ENABLED(PLR_TUNE_ITEM)
#if ENABLED(PROUI_ITEM_PLR)
EDIT_ITEM(ICON_Pwrlossr, MSG_OUTAGE_RECOVERY, onDrawChkbMenu, setPwrLossr, &recovery.enabled);
#endif
#if ENABLED(FWRETRACT)
MENU_ITEM(ICON_FWRetract, MSG_FWRETRACT, onDrawSubMenu, drawFWRetractMenu);
#endif
#if ENABLED(JD_TUNE_ITEM)
#if ENABLED(PROUI_ITEM_JD)
EDIT_ITEM(ICON_JDmm, MSG_JUNCTION_DEVIATION, onDrawPFloat3Menu, setJDmm, &planner.junction_deviation_mm);
#endif
#if ENABLED(ADVK_TUNE_ITEM)
#if ENABLED(PROUI_ITEM_ADVK)
EDIT_ITEM(ICON_MaxAccelerated, MSG_ADVANCE_K, onDrawPFloat3Menu, setLA_K, &planner.extruder_advance_K[0]);
#endif
#if HAS_LOCKSCREEN
Expand Down Expand Up @@ -3669,24 +3663,24 @@ void drawStepsMenu() {

void selColor() {
menuData.intPtr = (int16_t*)static_cast<MenuItemPtr*>(currentMenu->selectedItem())->value;
hmiValue.Color[0] = GetRColor(*menuData.intPtr); // Red
hmiValue.Color[1] = GetGColor(*menuData.intPtr); // Green
hmiValue.Color[2] = GetBColor(*menuData.intPtr); // Blue
hmiValue.color.r = GetRColor(*menuData.intPtr); // Red
hmiValue.color.g = GetGColor(*menuData.intPtr); // Green
hmiValue.color.b = GetBColor(*menuData.intPtr); // Blue
drawGetColorMenu();
}

void liveRGBColor() {
hmiValue.Color[currentMenu->line() - 2] = menuData.value;
uint16_t color = RGB(hmiValue.Color[0], hmiValue.Color[1], hmiValue.Color[2]);
hmiValue.color[currentMenu->line() - 2] = menuData.value;
const uint16_t color = RGB(hmiValue.color.r, hmiValue.color.g, hmiValue.color.b);
dwinDrawRectangle(1, color, 20, 315, DWIN_WIDTH - 20, 335);
}
void setRGBColor() {
const uint8_t color = static_cast<MenuItem*>(currentMenu->selectedItem())->icon;
setIntOnClick(0, (color == 1) ? 63 : 31, hmiValue.Color[color], nullptr, liveRGBColor);
setIntOnClick(0, (color == 1) ? 63 : 31, hmiValue.color[color], nullptr, liveRGBColor);
}

void dwinApplyColor() {
*menuData.intPtr = RGB(hmiValue.Color[0], hmiValue.Color[1], hmiValue.Color[2]);
*menuData.intPtr = RGB(hmiValue.color.r, hmiValue.color.g, hmiValue.color.b);
DWINUI::setColors(hmiData.colorText, hmiData.colorBackground, hmiData.colorStatusBg);
drawSelectColorsMenu();
hash_changed = true;
Expand Down Expand Up @@ -3952,16 +3946,13 @@ void drawStepsMenu() {
void setBedLevT() { setPIntOnClick(MIN_BEDTEMP, MAX_BEDTEMP); }
#endif

#if ENABLED(MESH_EDIT_MENU)
#define Z_OFFSET_MIN -3
#define Z_OFFSET_MAX 3

void LiveEditMesh() { ((MenuItemPtr*)editZValueItem)->value = &bedlevel.z_values[hmiValue.select ? bedLevelTools.mesh_x : menuData.value][hmiValue.select ? menuData.value : bedLevelTools.mesh_y]; editZValueItem->redraw(); }
#if ENABLED(PROUI_MESH_EDIT)
void liveEditMesh() { ((MenuItemPtr*)editZValueItem)->value = &bedlevel.z_values[hmiValue.select ? bedLevelTools.mesh_x : menuData.value][hmiValue.select ? menuData.value : bedLevelTools.mesh_y]; editZValueItem->redraw(); }
void applyEditMeshX() { bedLevelTools.mesh_x = menuData.value; }
void applyEditMeshY() { bedLevelTools.mesh_y = menuData.value; }
void ResetMesh() { bedLevelTools.meshReset(); LCD_MESSAGE(MSG_MESH_RESET); }
void setEditMeshX() { hmiValue.select = 0; setIntOnClick(0, GRID_MAX_POINTS_X - 1, bedLevelTools.mesh_x, applyEditMeshX, LiveEditMesh); }
void setEditMeshY() { hmiValue.select = 1; setIntOnClick(0, GRID_MAX_POINTS_Y - 1, bedLevelTools.mesh_y, applyEditMeshY, LiveEditMesh); }
void resetMesh() { bedLevelTools.meshReset(); LCD_MESSAGE(MSG_MESH_RESET); }
void setEditMeshX() { hmiValue.select = 0; setIntOnClick(0, GRID_MAX_POINTS_X - 1, bedLevelTools.mesh_x, applyEditMeshX, liveEditMesh); }
void setEditMeshY() { hmiValue.select = 1; setIntOnClick(0, GRID_MAX_POINTS_Y - 1, bedLevelTools.mesh_y, applyEditMeshY, liveEditMesh); }
void setEditZValue() { setPFloatOnClick(Z_OFFSET_MIN, Z_OFFSET_MAX, 3); }
#endif

Expand Down Expand Up @@ -4029,16 +4020,16 @@ void drawStepsMenu() {
MENU_ITEM(ICON_UBLTiltGrid, MSG_UBL_TILT_MESH, onDrawMenuItem, ublMeshTilt);
MENU_ITEM(ICON_UBLSmartFill, MSG_UBL_SMART_FILLIN, onDrawMenuItem, ublSmartFillMesh);
#endif
#if ENABLED(MESH_EDIT_MENU)
MENU_ITEM(ICON_MeshReset, MSG_MESH_RESET, onDrawMenuItem, ResetMesh);
#if ENABLED(PROUI_MESH_EDIT)
MENU_ITEM(ICON_MeshReset, MSG_MESH_RESET, onDrawMenuItem, resetMesh);
MENU_ITEM(ICON_MeshEdit, MSG_EDIT_MESH, onDrawSubMenu, drawEditMeshMenu);
#endif
MENU_ITEM(ICON_MeshViewer, MSG_MESH_VIEW, onDrawSubMenu, dwinMeshViewer);
}
updateMenu(meshMenu);
}

#if ENABLED(MESH_EDIT_MENU)
#if ENABLED(PROUI_MESH_EDIT)
void drawEditMeshMenu() {
if (!leveling_is_valid()) { LCD_MESSAGE(MSG_UBL_MESH_INVALID); return; }
set_bed_leveling_enabled(false);
Expand Down
38 changes: 29 additions & 9 deletions Marlin/src/lcd/e3v2/proui/dwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,30 +134,50 @@ typedef struct {
#if ENABLED(BAUD_RATE_GCODE)
bool baud115K = false;
#endif

bool fullManualTramming = false;
bool mediaSort = true;
#if ALL(LCD_BED_TRAMMING, HAS_BED_PROBE)
bool fullManualTramming = false;
#endif
#if ENABLED(PROUI_MEDIASORT)
bool mediaSort = true;
#endif
bool mediaAutoMount = ENABLED(HAS_SD_EXTENDER);
#if ALL(INDIVIDUAL_AXIS_HOMING_SUBMENU, MESH_BED_LEVELING)
uint8_t zAfterHoming = DEF_Z_AFTER_HOMING;
#endif
#if ALL(LED_CONTROL_MENU, HAS_COLOR_LEDS)
LEDColor ledColor = defColorLeds;
#endif
bool adaptiveStepSmoothing = true;
bool enablePreview = true;
#if ENABLED(ADAPTIVE_STEP_SMOOTHING)
bool adaptiveStepSmoothing = true;
#endif
#if HAS_GCODE_PREVIEW
bool enablePreview = true;
#endif
} hmi_data_t;

extern hmi_data_t hmiData;
static constexpr size_t eeprom_data_size = sizeof(hmi_data_t);

typedef struct {
int8_t Color[3]; // Color components
int8_t r, g, b;
void set(int8_t _r, int8_t _g, int8_t _b) { r = _r; g = _g; b = _b; }
int8_t& operator[](const int i) {
switch (i) {
default:
case 0: return r;
case 1: return g;
case 2: return b;
}
}
} rgb_t;

typedef struct {
rgb_t color; // Color
#if ANY(PROUI_PID_TUNE, MPCTEMP)
tempcontrol_t tempControl = AUTOTUNE_DONE;
#endif
uint8_t select = 0; // Auxiliary selector variable
AxisEnum axis = X_AXIS; // Axis Select
uint8_t select = 0; // Auxiliary selector variable
AxisEnum axis = X_AXIS; // Axis Select
} hmi_value_t;

typedef struct {
Expand Down Expand Up @@ -336,7 +356,7 @@ void drawStepsMenu();
#endif
#if HAS_MESH
void drawMeshSetMenu();
#if ENABLED(MESH_EDIT_MENU)
#if ENABLED(PROUI_MESH_EDIT)
void drawEditMeshMenu();
#endif
#endif
Expand Down
Loading

0 comments on commit cc8f7c8

Please sign in to comment.