Fix live Z offset.

This commit is contained in:
Knutwurst
2023-06-06 16:46:09 +02:00
parent fbd1b7b9bf
commit 9376b95148
2 changed files with 77 additions and 80 deletions

View File

@@ -32,7 +32,7 @@
#include "../../../module/motion.h"
#include "../../../module/stepper.h"
//#define ANYCUBIC_TFT_DEBUG
#define ANYCUBIC_TFT_DEBUG
//#define KNUTWURST_DGUS2_TFT
//#define KNUTWURST_TFT_LEVELING
@@ -121,6 +121,7 @@
CaseLight = false;
currentFlowRate = 100;
flowRateBuffer = SM_FLOW_DISP_L;
live_Zoffset = 0.0;
#if BOTH(SDSUPPORT, HAS_SD_DETECT)
SET_INPUT_PULLUP(SD_DETECT_PIN);
@@ -1493,7 +1494,7 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNPGM("Moving to mesh point at x: ", pos.x, " y: ", pos.y, " z: ", pos_z);
#endif
setAxisPosition_mm(3.0,Z);
setAxisPosition_mm(5.0,Z);
setAxisPosition_mm(17 + (93 * pos.x), X);
setAxisPosition_mm(20 + (93 * pos.y), Y);
setAxisPosition_mm(0.0, Z);
@@ -1524,6 +1525,36 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
break;
case 31: // A31 z-offset
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."));
}
}
else if (CodeSeen('D')) { // Save Z Offset tables and restore leveling state
if (!isPrinting()) {
setAxisPosition_mm(5.0,Z); // Lift nozzle before any further movements are made
injectCommands(F("M500"));
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNF(F("Mesh changes saved."));
#endif
selectedmeshpoint.x = selectedmeshpoint.y = 99;
}
}
else 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;
}
}
else {
if (CodeSeen('S')) { // Set offset (adjusts all points by value)
float Zshift = CodeValue();
setSoftEndstopState(false);
@@ -1536,7 +1567,6 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
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);
@@ -1574,38 +1604,7 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
}
}
}
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;
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNF(F("Mesh changes abandoned, previous mesh restored."));
#endif
}
}
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"));
#if ENABLED(ANYCUBIC_TFT_DEBUG)
SERIAL_ECHOLNF(F("Mesh changes saved."));
#endif
selectedmeshpoint.x = selectedmeshpoint.y = 99;
}
}
SENDLINE_PGM("");
break;
case 32: // a32 clean leveling beep flag
@@ -1935,9 +1934,10 @@ void AnycubicTouchscreenClass::RenderCurrentFolder(uint16_t selectedNumber) {
void AnycubicTouchscreenClass::OnPrintTimerStarted() {
#if ENABLED(SDSUPPORT)
if (mediaPrintingState == AMPRINTSTATE_PRINTING)
if (mediaPrintingState == AMPRINTSTATE_PRINTING) {
SENDLINE_DBG_PGM("J04", "TFT Serial Debug: Starting SD Print... J04"); // J04 Starting Print
live_Zoffset = 0.0;
}
#endif
}

View File

@@ -199,9 +199,9 @@ void UserConfirmRequired(const char *);
void SDCardStateChange(bool);
void SDCardError();
void KillTFT();
static void OnPrintTimerStarted();
static void OnPrintTimerPaused();
static void OnPrintTimerStopped();
void OnPrintTimerStarted();
void OnPrintTimerPaused();
void OnPrintTimerStopped();
#if BOTH(ANYCUBIC_TFT_DEBUG, KNUTWURST_DGUS2_TFT)
void Command(const char * const command);
@@ -226,11 +226,8 @@ uint16_t HeaterCheckCount = 0;
int currentFlowRate = 0;
bool PrintdoneAndPowerOFF = true;
bool powerOFFflag = 0;
#if ENABLED(KNUTWURST_TFT_LEVELING)
xy_uint8_t selectedmeshpoint;
float live_Zoffset;
#endif
xy_uint8_t selectedmeshpoint;
float live_Zoffset;
static AnycubicMediaPrintState mediaPrintingState;
static AnycubicMediaPauseState mediaPauseState;