Skip to content

Commit

Permalink
compiler-friendly Tram()
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed May 28, 2022
1 parent d6cc102 commit 49f4449
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions Marlin/src/lcd/e3v2/proui/dwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -2357,55 +2342,66 @@ 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)
);
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();
Expand All @@ -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); }
Expand Down

0 comments on commit 49f4449

Please sign in to comment.