From 49f4449569a148cd0c91201c44a37b8e442f691b Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 28 May 2022 15:10:34 -0500 Subject: [PATCH] compiler-friendly Tram() --- Marlin/src/lcd/e3v2/proui/dwin.cpp | 80 +++++++++++++++--------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/Marlin/src/lcd/e3v2/proui/dwin.cpp b/Marlin/src/lcd/e3v2/proui/dwin.cpp index 8af4b49d4815f..88296b95e8f4a 100644 --- a/Marlin/src/lcd/e3v2/proui/dwin.cpp +++ b/Marlin/src/lcd/e3v2/proui/dwin.cpp @@ -195,21 +195,6 @@ #if HAS_MESH #define BABY_Z_VAR TERN(HAS_BED_PROBE, probe.offset.z, HMI_data.ManualZOffset) - - // These may be overridden in Configuration.h if a smaller area is desired - // AUTO_BED_LEVELING_BILINEAR does not define MESH_INSET - #ifndef MESH_MIN_X - #define MESH_MIN_X (_MAX(X_MIN_BED + PROBING_MARGIN, X_MIN_POS)) - #endif - #ifndef MESH_MIN_Y - #define MESH_MIN_Y (_MAX(Y_MIN_BED + PROBING_MARGIN, Y_MIN_POS)) - #endif - #ifndef MESH_MAX_X - #define MESH_MAX_X (_MIN(X_MAX_BED - (PROBING_MARGIN), X_MAX_POS)) - #endif - #ifndef MESH_MAX_Y - #define MESH_MAX_Y (_MIN(Y_MAX_BED - (PROBING_MARGIN), Y_MAX_POS)) - #endif #else float z_offset = 0; #define BABY_Z_VAR z_offset @@ -2357,48 +2342,45 @@ void ApplyFlow() { planner.refresh_e_factor(0); } void SetFlow() { SetPIntOnClick(MIN_PRINT_FLOW, MAX_PRINT_FLOW, ApplyFlow); } // Bed Tramming -TERN(HAS_BED_PROBE, float, void) Tram(uint8_t point) { - char cmd[100] = ""; - #if HAS_BED_PROBE - static bool inLev = false; - float xpos = 0, ypos = 0, zval = 0, margin = 0; - char str_1[6] = "", str_2[6] = "", str_3[6] = ""; - if (inLev) return NAN; - margin = HMI_data.FullManualTramming ? 30 : PROBING_MARGIN; - #else - int16_t xpos = 0, ypos = 0; - int16_t margin = 30; - #endif +void TramXY(const uint8_t point, const float &margin, float &x, float &y) { switch (point) { case 0: LCD_MESSAGE(MSG_LEVBED_FL); - xpos = ypos = margin; + x = y = margin; break; case 1: LCD_MESSAGE(MSG_LEVBED_FR); - xpos = X_BED_SIZE - margin; ypos = margin; + x = X_BED_SIZE - margin; y = margin; break; case 2: LCD_MESSAGE(MSG_LEVBED_BR); - xpos = X_BED_SIZE - margin; ypos = Y_BED_SIZE - margin; + x = X_BED_SIZE - margin; y = Y_BED_SIZE - margin; break; case 3: LCD_MESSAGE(MSG_LEVBED_BL); - xpos = margin; ypos = Y_BED_SIZE - margin; + x = margin; y = Y_BED_SIZE - margin; break; case 4: LCD_MESSAGE(MSG_LEVBED_C); - xpos = X_BED_SIZE / 2; ypos = Y_BED_SIZE / 2; + x = X_CENTER; y = Y_CENTER; break; } +} - planner.synchronize(); +#if HAS_BED_PROBE - #if HAS_BED_PROBE + float Tram(const uint8_t point) { + char cmd[100] = ""; + static bool inLev = false; + float xpos = 0, ypos = 0, zval = 0, margin = 0; + char str_1[6] = "", str_2[6] = "", str_3[6] = ""; + if (inLev) return NAN; + margin = HMI_data.FullManualTramming ? 30 : PROBING_MARGIN; + + TramXY(point, margin, xpos, ypos); if (HMI_data.FullManualTramming) { - planner.synchronize(); sprintf_P(cmd, PSTR("M420S0\nG28O\nG90\nG0Z5F300\nG0X%sY%sF5000\nG0Z0F300"), dtostrf(xpos, 1, 1, str_1), dtostrf(ypos, 1, 1, str_2) @@ -2406,6 +2388,20 @@ TERN(HAS_BED_PROBE, float, void) Tram(uint8_t point) { queue.inject(cmd); } else { + // AUTO_BED_LEVELING_BILINEAR does not define MESH_INSET + #ifndef MESH_MIN_X + #define MESH_MIN_X (_MAX(X_MIN_BED + PROBING_MARGIN, X_MIN_POS)) + #endif + #ifndef MESH_MIN_Y + #define MESH_MIN_Y (_MAX(Y_MIN_BED + PROBING_MARGIN, Y_MIN_POS)) + #endif + #ifndef MESH_MAX_X + #define MESH_MAX_X (_MIN(X_MAX_BED - (PROBING_MARGIN), X_MAX_POS)) + #endif + #ifndef MESH_MAX_Y + #define MESH_MAX_Y (_MIN(Y_MAX_BED - (PROBING_MARGIN), Y_MAX_POS)) + #endif + LIMIT(xpos, MESH_MIN_X, MESH_MAX_X); LIMIT(ypos, MESH_MIN_Y, MESH_MAX_Y); probe.stow(); @@ -2425,14 +2421,20 @@ TERN(HAS_BED_PROBE, float, void) Tram(uint8_t point) { inLev = false; } return zval; + } + +#else - #else // !HAS_BED_PROBE + void Tram(const uint8_t point) { + float xpos = 0, ypos = 0, margin = 30; + TramXY(point, margin, xpos, ypos); - sprintf_P(cmd, PSTR("M420S0\nG28O\nG90\nG0Z5F300\nG0X%iY%iF5000\nG0Z0F300"), xpos, ypos); + char cmd[100] = "", str_1[6] = "", str_2[6] = ""; + sprintf_P(cmd, PSTR("M420S0\nG28O\nG90\nG0Z5F300\nG0X%sY%sF5000\nG0Z0F300"), dtostrf(xpos, 1, 1, str_1), dtostrf(ypos, 1, 1, str_2)); queue.inject(cmd); + } - #endif -} +#endif void TramFL() { Tram(0); } void TramFR() { Tram(1); }