From 70ccd6a9578e5b957a2374b4ba8417f773c12fe8 Mon Sep 17 00:00:00 2001 From: Knutwurst <36196269+knutwurst@users.noreply.github.com> Date: Sat, 3 Jun 2023 19:29:59 +0200 Subject: [PATCH] Refactor Chiron A31 Adjust all Probe Points routine --- .../extui/knutwurst/anycubic_touchscreen.cpp | 141 +++++++++--------- 1 file changed, 69 insertions(+), 72 deletions(-) diff --git a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp index 58b59f18..91db8281 100755 --- a/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp +++ b/Marlin/src/lcd/extui/knutwurst/anycubic_touchscreen.cpp @@ -1480,9 +1480,8 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) { pos_z = getMeshPoint(pos); - SEND_PGM("A29V "); - LCD_SERIAL.print(pos_z * 100, 2); - SENDLINE_PGM(""); + SENDLINE_PGM("A29V "); + LCD_SERIAL.println(pos_z * 100); if (!isPrinting()) { setSoftEndstopState(true); @@ -1515,7 +1514,8 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) { SENDLINE_DBG_PGM("J24", "TFT Serial Debug: Forbid auto leveling... J24"); } else { SENDLINE_DBG_PGM("J26", "TFT Serial Debug: Start auto leveling... J26"); - injectCommands(F("G28\nG29")); + //injectCommands(F("G28\nG29")); + injectCommands(F("G28\nG29\nG90\nM300 S440 P200\nM300 S660 P250\nM300 S880 P300\nG1 Z30 F4000\nG1 X5 F4000\nG91\nM84\nM420 S1")); mediaPrintingState = AMPRINTSTATE_PROBING; } } else { @@ -1524,17 +1524,78 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) { break; case 31: // A31 z-offset - // The tokens can occur in different places on the new panel so we need to find it. + if (CodeSeen('S')) { // Set offset (adjusts all points by value) + float Zshift = CodeValue(); + setSoftEndstopState(false); + if (isPrinting()) { + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift); + #endif + if (isAxisPositionKnown(Z)) { + #if ENABLED(ANYCUBIC_TFT_DEBUG) + const float currZpos = getAxisPosition_mm(Z); + SERIAL_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); + #endif + // Use babystepping to adjust the head position + int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z); + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("Steps to move Z: ", steps); + #endif + babystepAxis_steps(steps, Z); + live_Zoffset += Zshift; + } + SENDLINE_PGM("A31V "); + LCD_SERIAL.println(live_Zoffset); + } + else { + GRID_LOOP(x, y) { + const xy_uint8_t pos { x, y }; + const float currval = getMeshPoint(pos); + setMeshPoint(pos, constrain(currval + Zshift, -10, 2)); + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) ); + #endif + } + const float currZOffset = getZOffset_mm(); + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift); + #endif + + setZOffset_mm(currZOffset + Zshift); + SENDLINE_PGM("A31V "); + LCD_SERIAL.println(getZOffset_mm()); + + if (isAxisPositionKnown(Z)) { + const float currZpos = getAxisPosition_mm(Z); + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); + #endif + setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z); + } + } + } + + if (CodeSeen('G')) { // Get current offset + SENDLINE_PGM("A31V "); + if (isPrinting()) + LCD_SERIAL.println(live_Zoffset); + else { + LCD_SERIAL.println(getZOffset_mm()); + selectedmeshpoint.x = selectedmeshpoint.y = 99; + } + } if (CodeSeen('C')) { // Restore and apply original offsets if (!isPrinting()) { injectCommands(F("M501\nM420 S1")); selectedmeshpoint.x = selectedmeshpoint.y = 99; - SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored.")); + #if ENABLED(ANYCUBIC_TFT_DEBUG) + SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored.")); + #endif } } - else if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state + if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state if (!isPrinting()) { setAxisPosition_mm(1.0,Z); // Lift nozzle before any further movements are made injectCommands(F("M500")); @@ -1544,71 +1605,7 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) { selectedmeshpoint.x = selectedmeshpoint.y = 99; } } - - else if (CodeSeen('G')) { // Get current offset - SENDLINE_PGM("A31V "); - // When printing use the live z Offset position - // we will use babystepping to move the print head - if (isPrinting()) - LCD_SERIAL.println(live_Zoffset); - else { - LCD_SERIAL.println(getZOffset_mm()); - selectedmeshpoint.x = selectedmeshpoint.y = 99; - } - } - - else { - if (CodeSeen('S')) { // Set offset (adjusts all points by value) - float Zshift = CodeValue(); - setSoftEndstopState(false); - if (isPrinting()) { - #if ENABLED(ANYCUBIC_TFT_DEBUG) - SERIAL_ECHOLNPGM("Change Zoffset from:", live_Zoffset, " to ", live_Zoffset + Zshift); - #endif - if (isAxisPositionKnown(Z)) { - #if ENABLED(ANYCUBIC_TFT_DEBUG) - const float currZpos = getAxisPosition_mm(Z); - SERIAL_ECHOLNPGM("Nudge Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); - #endif - // Use babystepping to adjust the head position - int16_t steps = mmToWholeSteps(constrain(Zshift,-0.05,0.05), Z); - #if ENABLED(ANYCUBIC_TFT_DEBUG) - SERIAL_ECHOLNPGM("Steps to move Z: ", steps); - #endif - babystepAxis_steps(steps, Z); - live_Zoffset += Zshift; - } - SENDLINE_PGM("A31V "); - LCD_SERIAL.println(live_Zoffset); - } - else { - GRID_LOOP(x, y) { - const xy_uint8_t pos { x, y }; - const float currval = getMeshPoint(pos); - setMeshPoint(pos, constrain(currval + Zshift, -10, 2)); - #if ENABLED(ANYCUBIC_TFT_DEBUG) - SERIAL_ECHOLNPGM("Change mesh point X", x," Y",y ," from ", currval, " to ", getMeshPoint(pos) ); - #endif - } - const float currZOffset = getZOffset_mm(); - #if ENABLED(ANYCUBIC_TFT_DEBUG) - SERIAL_ECHOLNPGM("Change probe offset from ", currZOffset, " to ", currZOffset + Zshift); - #endif - - setZOffset_mm(currZOffset + Zshift); - SENDLINE_PGM("A31V "); - LCD_SERIAL.println(getZOffset_mm()); - - if (isAxisPositionKnown(Z)) { - const float currZpos = getAxisPosition_mm(Z); - #if ENABLED(ANYCUBIC_TFT_DEBUG) - SERIAL_ECHOLNPGM("Move Z pos from ", currZpos, " to ", currZpos + constrain(Zshift, -0.05, 0.05)); - #endif - setAxisPosition_mm(currZpos+constrain(Zshift,-0.05,0.05),Z); - } - } - } - } + SENDLINE_PGM(""); break; case 32: // a32 clean leveling beep flag