From bd625361245bd32e4f4bd0ad9a69420d3c32c6b4 Mon Sep 17 00:00:00 2001 From: kisslorand Date: Sun, 20 Aug 2023 23:00:18 +0300 Subject: [PATCH] Corner Leveling Marlin Fix --- TFT/src/User/API/LevelingControl.c | 2 +- TFT/src/User/API/parseACK.c | 21 +++-- TFT/src/User/Menu/LevelCorner.c | 123 ++++++++--------------------- 3 files changed, 46 insertions(+), 100 deletions(-) diff --git a/TFT/src/User/API/LevelingControl.c b/TFT/src/User/API/LevelingControl.c index 21cd6ce8ff..c1d434a616 100644 --- a/TFT/src/User/API/LevelingControl.c +++ b/TFT/src/User/API/LevelingControl.c @@ -13,7 +13,7 @@ float probedZ = 0.0f; // last Z offset measured by probe int16_t setCoordValue(AXIS axis, ALIGN_POSITION align) { return ((align == LEFT || align == BOTTOM) ? infoSettings.machine_size_min[axis] + infoSettings.level_edge - : infoSettings.machine_size_max[axis] - infoSettings.level_edge) - infoParameters.HomeOffset[axis]; + : infoSettings.machine_size_max[axis] - infoSettings.level_edge); } void levelingGetPointCoords(LEVELING_POINT_COORDS coords) diff --git a/TFT/src/User/API/parseACK.c b/TFT/src/User/API/parseACK.c index d43a332caf..a38dc9ca6a 100644 --- a/TFT/src/User/API/parseACK.c +++ b/TFT/src/User/API/parseACK.c @@ -740,7 +740,7 @@ void parseACK(void) //---------------------------------------- // parse and store build volume size - else if (ack_seen("work:")) + else if (ack_seen("full:")) { if (ack_continue_seen("min:")) { @@ -871,16 +871,23 @@ void parseACK(void) mblUpdateStatus(true); } // parse G30, feedback to get the 4 corners Z value returned by Marlin for LevelCorner menu - else if (ack_seen("Bed X: ")) + else if (ack_seen("Bed X:")) { float x = ack_value(); - float y = 0; - if (ack_continue_seen("Y: ")) - y = ack_value(); + if (ack_continue_seen("Y:")) + { + float y = ack_value(); - if (ack_continue_seen("Z: ")) - levelingSetProbedPoint(x, y, ack_value()); // save probed Z value + if (ack_continue_seen("Z:")) + levelingSetProbedPoint(x, y, ack_value()); // save probed Z value + } + } + // parse G30 coordinate unreachable message + else if (ack_seen("Z Probe Past Bed")) + { + levelingSetProbedPoint(-1, -1, 0); // cancel waiting for coordinates + BUZZER_PLAY(SOUND_ERROR); } #if DELTA_PROBE_TYPE != 0 // parse and store Delta calibration settings diff --git a/TFT/src/User/Menu/LevelCorner.c b/TFT/src/User/Menu/LevelCorner.c index 6a9188268a..c7ba2b8653 100644 --- a/TFT/src/User/Menu/LevelCorner.c +++ b/TFT/src/User/Menu/LevelCorner.c @@ -1,14 +1,14 @@ #include "LevelCorner.h" #include "includes.h" -const uint8_t valIconIndex[LEVELING_POINT_COUNT] = {4, 5, 1, 0, 3}; +const uint8_t valIconIndex[LEVELING_POINT_COUNT] = {KEY_ICON_4, KEY_ICON_5, KEY_ICON_1, KEY_ICON_0, KEY_ICON_3}; // buffer current Z value measured in Level Corner = {position 1, position 2, position 3, position 4, probe accuracy(M48)} float levelCornerPosition[LEVELING_POINT_COUNT] = {0}; int16_t origLevelEdge = -1; -uint8_t getLevelEdgeMin(void) +static uint8_t getLevelEdgeMin(void) { // min edge limit for the probe with probe offset set in parseACK.c int16_t maxXedge = getParameter(P_PROBE_OFFSET, AXIS_INDEX_X) + getParameter(P_HOME_OFFSET, AXIS_INDEX_X); @@ -20,72 +20,23 @@ uint8_t getLevelEdgeMin(void) return MAX(maxXedge, maxYedge) + 1; } -uint8_t getLevelEdgeDefault(void) +static uint8_t getLevelEdgeDefault(void) { return MAX(origLevelEdge, getLevelEdgeMin()); } -void setLevelEdgeMin(void) +static void setLevelEdgeMin(void) { infoSettings.level_edge = getLevelEdgeMin(); } // draw values under icons -void refreshValue(MENUITEMS * levelItems, uint8_t index) +static void refreshValue(MENUITEMS * levelItems, uint8_t index) { - sprintf((char *)levelItems->items[valIconIndex[index]].label.address, "%.4f", levelCornerPosition[index]); + sprintf((char *)levelItems->items[valIconIndex[index]].label.address, "%.3f", levelCornerPosition[index]); menuDrawIconText(&levelItems->items[valIconIndex[index]], valIconIndex[index]); } -void checkRefreshValue(MENUITEMS * levelItems) -{ - LEVELING_POINT levelingPoint = levelingGetProbedPoint(); - - if (levelingPoint != LEVEL_NO_POINT) - { - levelCornerPosition[levelingPoint] = levelingGetProbedZ(); - refreshValue(levelItems, levelingPoint); - - levelingResetProbedPoint(); // reset to check for new updates - } -} - -// show M48 on icon -void drawProbeAccuracyIcon(MENUITEMS * levelItems) -{ - uint8_t index = 4; - GUI_POINT loc; - LIVE_INFO lvIcon; - char * str = "M48"; - - loc.x = 5; - loc.y = ICON_HEIGHT - 5; - - lvIcon.iconIndex = levelItems->items[valIconIndex[index]].icon; - lvIcon.enabled[0] = true; - lvIcon.enabled[1] = true; - lvIcon.enabled[2] = false; - - lvIcon.lines[0].h_align = LEFT; - lvIcon.lines[0].v_align = BOTTOM; - lvIcon.lines[0].fn_color = LC_VAL_COLOR; - lvIcon.lines[0].text_mode = GUI_TEXTMODE_TRANS; - lvIcon.lines[0].pos = loc; - lvIcon.lines[0].font = FONT_SIZE_NORMAL; - - lvIcon.lines[1].h_align = LEFT; - lvIcon.lines[1].v_align = BOTTOM; - lvIcon.lines[1].fn_color = LC_VAL_COLOR_2; - lvIcon.lines[1].text_mode = GUI_TEXTMODE_TRANS; - lvIcon.lines[1].pos = (GUI_POINT){loc.x - 2, loc.y - 2}; - lvIcon.lines[1].font = FONT_SIZE_NORMAL; - - lvIcon.lines[0].text = (uint8_t *)str; - lvIcon.lines[1].text = (uint8_t *)str; - - showLiveInfo(valIconIndex[index], &lvIcon, false); -} - void menuLevelCorner(void) { MENUITEMS levelCornerItems = { @@ -93,19 +44,19 @@ void menuLevelCorner(void) LABEL_LEVEL_CORNER, // icon label { - {ICON_POINT_4, LABEL_DYNAMIC}, - {ICON_POINT_3, LABEL_DYNAMIC}, + {ICON_POINT_4, LABEL_NULL}, + {ICON_POINT_3, LABEL_NULL}, {ICON_LEVEL_EDGE_DISTANCE, LABEL_DISTANCE}, - {ICON_BLTOUCH, LABEL_DYNAMIC}, - {ICON_POINT_1, LABEL_DYNAMIC}, - {ICON_POINT_2, LABEL_DYNAMIC}, + {ICON_BLTOUCH, LABEL_NULL}, + {ICON_POINT_1, LABEL_NULL}, + {ICON_POINT_2, LABEL_NULL}, {ICON_RESUME, LABEL_START}, {ICON_BACK, LABEL_BACK}, } }; KEY_VALUES key_num = KEY_IDLE; - char iconText[LEVELING_POINT_COUNT][15]; + char iconText[LEVELING_POINT_COUNT][5] = {"---", "---", "---", "---", "M48"}; if (origLevelEdge < 0) // initialize leveling edge value to be used for leveling corner if not yet initialized (-1) { @@ -113,15 +64,12 @@ void menuLevelCorner(void) infoSettings.level_edge = getLevelEdgeDefault(); // set leveling edge value for leveling corner } - for (uint8_t i = 0; i < LEVELING_POINT_COUNT; i++) + for (uint8_t i = LEVEL_BOTTOM_LEFT; i < LEVELING_POINT_COUNT; i++) { levelCornerItems.items[valIconIndex[i]].label.address = (uint8_t *)iconText[i]; - - refreshValue(&levelCornerItems, i); } menuDrawPage(&levelCornerItems); - drawProbeAccuracyIcon(&levelCornerItems); while (MENU_IS(menuLevelCorner)) { @@ -129,11 +77,25 @@ void menuLevelCorner(void) switch (key_num) { case KEY_ICON_0: - levelingProbePoint(LEVEL_TOP_LEFT); - break; - case KEY_ICON_1: - levelingProbePoint(LEVEL_TOP_RIGHT); + case KEY_ICON_4: + case KEY_ICON_5: + case KEY_ICON_6: + for (int lvlPoint = LEVEL_BOTTOM_LEFT; lvlPoint <= LEVEL_TOP_LEFT; lvlPoint++) + { + if (key_num < KEY_ICON_6 && key_num != valIconIndex[lvlPoint]) + continue; + + levelingProbePoint(lvlPoint); + + // wait until point probing is executed + TASK_LOOP_WHILE(levelingGetProbedPoint() == LEVEL_NO_POINT); + + levelCornerPosition[lvlPoint] = levelingGetProbedZ(); + refreshValue(&levelCornerItems, lvlPoint); + levelingResetProbedPoint(); // reset to check for new updates + } + break; case KEY_ICON_2: @@ -151,27 +113,6 @@ void menuLevelCorner(void) case KEY_ICON_3: mustStoreCmd("M48\n"); - - drawProbeAccuracyIcon(&levelCornerItems); - break; - - case KEY_ICON_4: - levelingProbePoint(LEVEL_BOTTOM_LEFT); - break; - - case KEY_ICON_5: - levelingProbePoint(LEVEL_BOTTOM_RIGHT); - break; - - case KEY_ICON_6: - for (int i = LEVEL_BOTTOM_LEFT; i <= LEVEL_TOP_LEFT; i++) - { - levelingProbePoint(i); - - // following loop needed to guarantee the value for each point beeing probed is updated at least one time on the menu - TASK_LOOP_WHILE(isNotEmptyCmdQueue(), checkRefreshValue(&levelCornerItems)) - } - break; case KEY_ICON_7: @@ -185,7 +126,5 @@ void menuLevelCorner(void) } loopProcess(); - - checkRefreshValue(&levelCornerItems); } }