update mesh_bed_leveling + mesh_inset menu

This commit is contained in:
classicrocker883 2024-11-21 11:18:15 -05:00
parent c1bc79581a
commit e62c9d6a6e
No known key found for this signature in database
GPG Key ID: 11D10A09D3B1FFC2
8 changed files with 109 additions and 66 deletions

View File

@ -34,18 +34,12 @@
mesh_bed_leveling bedlevel;
float mesh_bed_leveling::z_offset,
mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X],
float mesh_bed_leveling::z_offset;
float mesh_bed_leveling::index_to_xpos[GRID_MAX_POINTS_X],
mesh_bed_leveling::index_to_ypos[GRID_MAX_POINTS_Y];
bed_mesh_t mesh_bed_leveling::z_values;
float mesh_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
mesh_bed_leveling::mesh_bed_leveling() {
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
for (uint8_t i = 0; i < GRID_MAX_POINTS_Y; ++i)
index_to_ypos[i] = MESH_MIN_Y + i * (MESH_Y_DIST);
reset();
}
mesh_bed_leveling::mesh_bed_leveling() { initialize(); }
void mesh_bed_leveling::reset() {
z_offset = 0;
@ -55,6 +49,19 @@
#endif
}
void mesh_bed_leveling::initialize() {
for (uint8_t i = 0; i < GRID_MAX_POINTS_X; ++i)
index_to_xpos[i] = MESH_MIN_X + i * (MESH_X_DIST);
for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; ++j)
index_to_ypos[j] = MESH_MIN_Y + j * (MESH_Y_DIST);
reset();
}
void mesh_bed_leveling::report_mesh() {
SERIAL_ECHOLN(F(STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh. Z offset: "), p_float_t(z_offset, 5), F("\nMeasured points:"));
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]);
}
#if IS_CARTESIAN && DISABLED(SEGMENT_LEVELED_MOVES)
/**
@ -122,9 +129,4 @@
#endif // IS_CARTESIAN && !SEGMENT_LEVELED_MOVES
void mesh_bed_leveling::report_mesh() {
SERIAL_ECHOLN(F(STRINGIFY(GRID_MAX_POINTS_X) "x" STRINGIFY(GRID_MAX_POINTS_Y) " mesh. Z offset: "), p_float_t(z_offset, 5), F("\nMeasured points:"));
print_2d_array(GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y, 5, z_values[0]);
}
#endif // MESH_BED_LEVELING

View File

@ -37,17 +37,19 @@ enum MeshLevelingState : char {
class mesh_bed_leveling {
public:
static float z_offset,
z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
index_to_xpos[GRID_MAX_POINTS_X],
static float z_offset;
static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
static float index_to_xpos[GRID_MAX_POINTS_X],
index_to_ypos[GRID_MAX_POINTS_Y];
mesh_bed_leveling();
static void report_mesh();
static void reset();
static void initialize();
static void report_mesh();
FORCE_INLINE static bool has_mesh() {
GRID_LOOP(x, y) if (z_values[x][y]) return true;
return false;

View File

@ -74,14 +74,6 @@ bool drawing_mesh = false;
#if ENABLED(AUTO_BED_LEVELING_UBL)
void BedLevelTools::manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y, bool undefined/*=false*/) {
MString<MAX_CMD_SIZE> cmd;
cmd.set(F("M421 I"), mesh_x, 'J', mesh_y, 'Z', p_float_t(current_position.z, 3));
if (undefined) cmd += F(" N");
gcode.process_subcommands_now(cmd);
planner.synchronize();
}
bool BedLevelTools::createPlaneFromMesh() {
struct linear_fit_data lsf_results;
incremental_LSF_reset(&lsf_results);
@ -121,17 +113,16 @@ bool drawing_mesh = false;
return false;
}
#else
void BedLevelTools::manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y) {
gcode.process_subcommands_now(
TS(F("G29 I"), mesh_x, 'J', mesh_y, 'Z', p_float_t(current_position.z, 3))
);
planner.synchronize();
}
#endif
void BedLevelTools::manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y, bool reset/*=false*/) {
float zval;
if (reset) { zval = 0; }
else { zval = current_position.z; }
gcode.process_subcommands_now(TS(F("M421I"), mesh_x, F("J"), mesh_y, F("Z"), p_float_t(zval, 3)));
planner.synchronize();
}
void BedLevelTools::manualMove(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
gcode.process_subcommands_now(F("G28O"));
if (!zmove) {

View File

@ -55,11 +55,9 @@ public:
static uint8_t tilt_grid;
#if ENABLED(AUTO_BED_LEVELING_UBL)
static void manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y, bool undefined=false);
static bool createPlaneFromMesh();
#else
static void manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y);
#endif
static void manualValueUpdate(const uint8_t mesh_x, const uint8_t mesh_y, bool undefined=false);
static void manualMove(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove=false);
static void moveToXYZ();
static void moveToXY();

View File

@ -280,6 +280,7 @@ Menu *stepsMenu = nullptr;
#if HAS_MESH
Menu *meshMenu = nullptr;
#if ENABLED(PROUI_MESH_EDIT)
Menu *meshInsetMenu = nullptr;
Menu *editMeshMenu = nullptr;
#endif
#endif
@ -2392,17 +2393,6 @@ void setMoveZ() { hmiValue.axis = Z_AXIS; setPFloatOnClick(Z_MIN_POS, Z_MAX_POS,
void setBedLevT() { setPIntOnClick(MIN_BEDTEMP, MAX_BEDTEMP); }
#endif
#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 setEditZValue() { setPFloatOnClick(Z_OFFSET_MIN, Z_OFFSET_MAX, 3); }
void applyMeshInset() { TERN_(AUTO_BED_LEVELING_UBL, set_bed_leveling_enabled(false)); reset_bed_level(); redrawItem(); }
void setMeshInset() { setPFloatOnClick(X_MIN_POS, X_MAX_POS, UNITFDIGITS, applyMeshInset); }
#endif
#endif // HAS_MESH
@ -3297,9 +3287,6 @@ void drawAdvancedSettingsMenu() {
#if ENABLED(EEPROM_SETTINGS)
MENU_ITEM(ICON_WriteEEPROM, MSG_STORE_EEPROM, onDrawMenuItem, writeEEPROM);
#endif
#if HAS_MESH
MENU_ITEM(ICON_Mesh, MSG_MESH_LEVELING, onDrawSubMenu, drawMeshSetMenu);
#endif
#if HAS_BED_PROBE
MENU_ITEM(ICON_Probe, MSG_ZPROBE_SETTINGS, onDrawSubMenu, drawProbeSetMenu);
#endif
@ -4257,8 +4244,11 @@ void drawMaxAccelMenu() {
void drawMeshSetMenu() {
checkkey = ID_Menu;
if (SET_MENU(meshMenu, MSG_MESH_SETTINGS, 5)) {
if (SET_MENU(meshMenu, MSG_MESH_SETTINGS, 6)) {
BACK_ITEM(drawLevelMenu);
#if ENABLED(PROUI_MESH_EDIT)
MENU_ITEM(ICON_ProbeMargin, MSG_MESH_INSET, onDrawSubMenu, drawMeshInsetMenu);
#endif
#if ENABLED(PREHEAT_BEFORE_LEVELING)
EDIT_ITEM(ICON_Temperature, MSG_UBL_SET_TEMP_BED, onDrawPIntMenu, setBedLevT, &hmiData.bedLevT);
#endif
@ -4272,22 +4262,76 @@ void drawMaxAccelMenu() {
}
#if ENABLED(PROUI_MESH_EDIT)
bool autoMovToMesh = false;
void setAutoMovToMesh() { toggleCheckboxLine(autoMovToMesh); }
// Mesh Points
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; if (autoMovToMesh) { bedLevelTools.moveToXY(); } }
void applyEditMeshY() { bedLevelTools.mesh_y = menuData.value; if (autoMovToMesh) { bedLevelTools.moveToXY(); } }
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); }
void zeroPoint() { bedLevelTools.manualValueUpdate(bedLevelTools.mesh_x, bedLevelTools.mesh_y, true); editZValueItem->redraw(); LCD_MESSAGE(MSG_ZERO_MESH); }
void resetMesh() { bedLevelTools.meshReset(); LCD_MESSAGE(MSG_MESH_RESET); }
// Mesh Inset
void resetMeshInset() { set_bed_leveling_enabled(false); OPTCODE(MESH_BED_LEVELING, bedlevel.initialize()) reset_bed_level(); }
void applyMeshInset() { resetMeshInset(); redrawItem(); }
void setXMeshInset() { setPFloatOnClick(0, X_BED_SIZE, UNITFDIGITS, applyMeshInset); }
void setYMeshInset() { setPFloatOnClick(0, Y_BED_SIZE, UNITFDIGITS, applyMeshInset); }
void maxMeshArea() {
hmiData.mesh_min_x = 0;
hmiData.mesh_max_x = X_BED_SIZE;
hmiData.mesh_min_y = 0;
hmiData.mesh_max_y = Y_BED_SIZE;
resetMeshInset();
redrawMenu();
}
void centerMeshArea() {
float max = (MESH_MIN_X + MESH_MIN_Y) * 0.5;
if (max < X_BED_SIZE - MESH_MAX_X) { max = X_BED_SIZE - MESH_MAX_X; }
if (max < MESH_MIN_Y) { max = MESH_MIN_Y; }
if (max < Y_BED_SIZE - MESH_MAX_Y) { max = Y_BED_SIZE - MESH_MAX_Y; }
hmiData.mesh_min_x = max;
hmiData.mesh_max_x = X_BED_SIZE - max;
hmiData.mesh_min_y = max;
hmiData.mesh_max_y = Y_BED_SIZE - max;
resetMeshInset();
redrawMenu();
}
void drawMeshInsetMenu() {
checkkey = ID_Menu;
if (SET_MENU(meshInsetMenu, MSG_MESH_INSET, 7)) {
BACK_ITEM(drawMeshSetMenu);
EDIT_ITEM(ICON_Box, MSG_MESH_MIN_X, onDrawPFloatMenu, setXMeshInset, &hmiData.mesh_min_x);
EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_X, onDrawPFloatMenu, setXMeshInset, &hmiData.mesh_max_x);
EDIT_ITEM(ICON_Box, MSG_MESH_MIN_Y, onDrawPFloatMenu, setYMeshInset, &hmiData.mesh_min_y);
EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_Y, onDrawPFloatMenu, setYMeshInset, &hmiData.mesh_max_y);
MENU_ITEM(ICON_AxisC, MSG_MESH_AMAX, onDrawMenuItem, maxMeshArea);
MENU_ITEM(ICON_SetHome, MSG_MESH_CENTER, onDrawMenuItem, centerMeshArea);
}
updateMenu(meshInsetMenu);
LCD_MESSAGE_F("..Center Area sets mesh equidistant by greatest inset from edge.");
}
void drawEditMeshMenu() {
if (!leveling_is_valid()) { LCD_MESSAGE(MSG_UBL_MESH_INVALID); return; }
if (!leveling_is_valid()) {
LCD_MESSAGE(MSG_UBL_MESH_INVALID);
return dwinPopupConfirm(ICON_Leveling_1, GET_TEXT_F(MSG_NO_VALID_MESH), GET_TEXT_F(MSG_UBL_LOAD_MESH));
}
set_bed_leveling_enabled(false);
checkkey = ID_Menu;
if (SET_MENU(editMeshMenu, MSG_EDIT_MESH, 10)) {
if (SET_MENU(editMeshMenu, MSG_MESH_EDITOR, 7)) {
bedLevelTools.mesh_x = bedLevelTools.mesh_y = 0;
BACK_ITEM(drawLevelMenu);
EDIT_ITEM(ICON_SetHome, MSG_PROBE_WIZARD_MOVING, onDrawChkbMenu, setAutoMovToMesh, &autoMovToMesh);
EDIT_ITEM(ICON_MeshEditX, MSG_MESH_X, onDrawPInt8Menu, setEditMeshX, &bedLevelTools.mesh_x);
EDIT_ITEM(ICON_MeshEditY, MSG_MESH_Y, onDrawPInt8Menu, setEditMeshY, &bedLevelTools.mesh_y);
editZValueItem = EDIT_ITEM(ICON_MeshEditZ, MSG_MESH_EDIT_Z, onDrawPFloat2Menu, setEditZValue, &bedlevel.z_values[bedLevelTools.mesh_x][bedLevelTools.mesh_y]);
EDIT_ITEM(200 /*ICON_Box*/, MSG_MESH_MIN_X, onDrawPFloatMenu, setMeshInset, &hmiData.mesh_min_x);
EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_X, onDrawPFloatMenu, setMeshInset, &hmiData.mesh_max_x);
EDIT_ITEM(200 /*ICON_Box*/, MSG_MESH_MIN_Y, onDrawPFloatMenu, setMeshInset, &hmiData.mesh_min_y);
EDIT_ITEM(ICON_ProbeMargin, MSG_MESH_MAX_Y, onDrawPFloatMenu, setMeshInset, &hmiData.mesh_max_y);
//MENU_ITEM(254 /*ICON_AxisC*/, MSG_MESH_AMAX, onDrawMenuItem, maxMeshArea);
//MENU_ITEM(ICON_SetHome, MSG_MESH_CENTER, onDrawMenuItem, centerMeshArea);
editZValueItem = EDIT_ITEM(ICON_MeshEditZ, MSG_MESH_EDIT_Z, onDrawPFloat3Menu, setEditZValue, &bedlevel.z_values[bedLevelTools.mesh_x][bedLevelTools.mesh_y]);
TERN_(HAS_BED_PROBE, MENU_ITEM(ICON_Probe, MSG_PROBE_WIZARD_PROBING, onDrawMenuItem, bedLevelTools.ProbeXY);)
MENU_ITEM(ICON_SetZOffset, MSG_ZERO_MESH, onDrawMenuItem, zeroPoint);
}
updateMenu(editMeshMenu);
}
@ -4312,8 +4356,8 @@ void drawLevelMenu() {
MENU_ITEM(ICON_HomeOffset, MSG_SET_HOME_OFFSETS, onDrawSubMenu, drawHomeOffsetMenu);
#endif
#if HAS_MESH
MENU_ITEM(ICON_Mesh, MSG_MESH_SETTINGS, onDrawSubMenu, drawMeshSetMenu);
MENU_ITEM(ICON_MeshViewer, MSG_MESH_VIEW, onDrawSubMenu, dwinMeshViewer);
MENU_ITEM(ICON_Mesh, MSG_MESH_SETTINGS, onDrawSubMenu, drawMeshSetMenu);
#if ENABLED(PROUI_MESH_EDIT)
MENU_ITEM(ICON_MeshEdit, MSG_EDIT_MESH, onDrawSubMenu, drawEditMeshMenu);
MENU_ITEM(ICON_MeshReset, MSG_MESH_RESET, onDrawMenuItem, resetMesh);

View File

@ -321,6 +321,7 @@ void drawMaxAccelMenu();
#if HAS_MESH
void drawMeshSetMenu();
#if ENABLED(PROUI_MESH_EDIT)
void drawMeshInsetMenu();
void drawEditMeshMenu();
#endif
#endif

View File

@ -156,7 +156,11 @@ namespace ExtUI {
#if HAS_LEVELING
void onLevelingStart() { dwinLevelingStart(); }
void onLevelingDone() { dwinLevelingDone(); }
void onLevelingDone() {
#if ALL(HAS_MESH, HAS_BED_PROBE)
dwinLevelingDone();
#endif
}
#if ENABLED(PREHEAT_BEFORE_LEVELING)
celsius_t getLevelingBedTemp() { return hmiData.bedLevT; }
#endif

View File

@ -1098,6 +1098,7 @@ namespace LanguageWide_en {
LSTR MSG_MEDIA_NOT_INSERTED = _UxGT("No media inserted."); // ProUI
LSTR MSG_PLEASE_PREHEAT = _UxGT("Please preheat the hot end."); // ProUI
LSTR MSG_INFO_PRINT_COUNT_RESET = _UxGT("Reset Print Count"); // ProUI
LSTR MSG_ZERO_MESH = _UxGT("Zero Current Point"); // ProUI
LSTR MSG_INFO_PRINT_COUNT = _UxGT("Print Count");
LSTR MSG_INFO_PRINT_TIME = _UxGT("Print Time");
LSTR MSG_INFO_PRINT_LONGEST = _UxGT("Longest Job Time");