Skip to content

Commit

Permalink
🚸 M666: Fix value filter, add report (#22337)
Browse files Browse the repository at this point in the history
In reference to #22325
  • Loading branch information
thinkyhead authored Jul 11, 2021
1 parent ec84770 commit 01ae1ce
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 59 deletions.
74 changes: 51 additions & 23 deletions Marlin/src/gcode/calibrate/M666.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,72 @@
#include "../gcode.h"

#if ENABLED(DELTA)

#include "../../module/delta.h"
#include "../../module/motion.h"
#else
#include "../../module/endstops.h"
#endif

#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../core/debug_out.h"
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../core/debug_out.h"

void M666_report(const bool forReplay=true) {
if (!forReplay) { SERIAL_ECHOLNPGM("; Endstop adjustment:"); SERIAL_ECHO_START(); }
#if ENABLED(DELTA)
SERIAL_ECHOLNPAIR_P(
PSTR(" M666 X"), LINEAR_UNIT(delta_endstop_adj.a)
, SP_Y_STR, LINEAR_UNIT(delta_endstop_adj.b)
, SP_Z_STR, LINEAR_UNIT(delta_endstop_adj.c)
);
#else
SERIAL_ECHOPGM(" M666");
#if ENABLED(X_DUAL_ENDSTOPS)
SERIAL_ECHOLNPAIR_P(SP_X_STR, LINEAR_UNIT(endstops.x2_endstop_adj));
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
SERIAL_ECHOLNPAIR_P(SP_Y_STR, LINEAR_UNIT(endstops.y2_endstop_adj));
#endif
#if ENABLED(Z_MULTI_ENDSTOPS)
#if NUM_Z_STEPPER_DRIVERS >= 3
SERIAL_ECHOPAIR(" S2 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
if (!forReplay) SERIAL_ECHO_START();
SERIAL_ECHOPAIR(" M666 S3 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
#if NUM_Z_STEPPER_DRIVERS >= 4
if (!forReplay) SERIAL_ECHO_START();
SERIAL_ECHOPAIR(" M666 S4 Z", LINEAR_UNIT(endstops.z4_endstop_adj));
#endif
#else
SERIAL_ECHOLNPAIR_P(SP_Z_STR, LINEAR_UNIT(endstops.z2_endstop_adj));
#endif
#endif
#endif
}

#if ENABLED(DELTA)

/**
* M666: Set delta endstop adjustment
*/
void GcodeSuite::M666() {
DEBUG_SECTION(log_M666, "M666", DEBUGGING(LEVELING));
bool is_err = false, is_set = false;
LOOP_LINEAR_AXES(i) {
if (parser.seen(AXIS_CHAR(i))) {
is_set = true;
const float v = parser.value_linear_units();
if (v * Z_HOME_DIR <= 0) delta_endstop_adj[i] = v;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", AS_CHAR(AXIS_CHAR(i)), "] = ", delta_endstop_adj[i]);
if (v > 0)
is_err = true;
else {
delta_endstop_adj[i] = v;
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", AS_CHAR(AXIS_CHAR(i)), "] = ", v);
}
}
}
if (is_err) SERIAL_ECHOLNPAIR("?M666 offsets must be <= 0");
if (!is_set) M666_report();
}

#elif HAS_EXTRA_ENDSTOPS

#include "../../module/endstops.h"
#else

/**
* M666: Set Dual Endstops offsets for X, Y, and/or Z.
Expand Down Expand Up @@ -81,21 +123,7 @@
#endif
}
#endif
if (!parser.seen("XYZ")) {
auto echo_adj = [](PGM_P const label, const_float_t value) { SERIAL_ECHOPAIR_P(label, value); };
SERIAL_ECHOPGM("Dual Endstop Adjustment (mm): ");
#if ENABLED(X_DUAL_ENDSTOPS)
echo_adj(PSTR(" X2:"), endstops.x2_endstop_adj);
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
echo_adj(PSTR(" Y2:"), endstops.y2_endstop_adj);
#endif
#if ENABLED(Z_MULTI_ENDSTOPS)
#define _ECHO_ZADJ(N) echo_adj(PSTR(" Z" STRINGIFY(N) ":"), endstops.z##N##_endstop_adj);
REPEAT_S(2, INCREMENT(NUM_Z_STEPPER_DRIVERS), _ECHO_ZADJ)
#endif
SERIAL_EOL();
}
if (!parser.seen("XYZ")) M666_report();
}

#endif // HAS_EXTRA_ENDSTOPS
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/feature/controllerfan/M710.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "../../gcode.h"
#include "../../../feature/controllerfan.h"

void M710_report(const bool forReplay) {
void M710_report(const bool forReplay=true) {
if (!forReplay) { SERIAL_ECHOLNPGM("; Controller Fan"); SERIAL_ECHO_START(); }
SERIAL_ECHOLNPAIR(" M710"
" S", int(controllerFan.settings.active_speed),
Expand Down Expand Up @@ -75,7 +75,7 @@ void GcodeSuite::M710() {
if (seenD) controllerFan.settings.duration = parser.value_ushort();

if (!(seenR || seenS || seenI || seenA || seenD))
M710_report(false);
M710_report();
}

#endif // CONTROLLER_FAN_EDITABLE
43 changes: 9 additions & 34 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@

#include "../feature/controllerfan.h"
#if ENABLED(CONTROLLER_FAN_EDITABLE)
void M710_report(const bool forReplay);
void M710_report(const bool forReplay=true);
#endif

#if ENABLED(CASE_LIGHT_ENABLE)
Expand Down Expand Up @@ -168,6 +168,10 @@
void M554_report();
#endif

#if EITHER(DELTA, HAS_EXTRA_ENDSTOPS)
void M666_report(const bool forReplay=true);
#endif

#define _EN_ITEM(N) , E##N

typedef struct { uint16_t LINEAR_AXIS_LIST(X, Y, Z, I, J, K), X2, Y2, Z2, Z3, Z4 REPEAT(E_STEPPERS, _EN_ITEM); } tmc_stepper_current_t;
Expand Down Expand Up @@ -3302,14 +3306,6 @@ void MarlinSettings::reset() {

#elif ENABLED(DELTA)

CONFIG_ECHO_HEADING("Endstop adjustment:");
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR_P(
PSTR(" M666 X"), LINEAR_UNIT(delta_endstop_adj.a)
, SP_Y_STR, LINEAR_UNIT(delta_endstop_adj.b)
, SP_Z_STR, LINEAR_UNIT(delta_endstop_adj.c)
);

CONFIG_ECHO_HEADING("Delta settings: L<diagonal rod> R<radius> H<height> S<segments per sec> XYZ<tower angle trim> ABC<rod trim>");
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR_P(
Expand All @@ -3325,32 +3321,11 @@ void MarlinSettings::reset() {
, PSTR(" C"), LINEAR_UNIT(delta_diagonal_rod_trim.c)
);

#elif HAS_EXTRA_ENDSTOPS

CONFIG_ECHO_HEADING("Endstop adjustment:");
CONFIG_ECHO_START();
SERIAL_ECHOPGM(" M666");
#if ENABLED(X_DUAL_ENDSTOPS)
SERIAL_ECHOLNPAIR_P(SP_X_STR, LINEAR_UNIT(endstops.x2_endstop_adj));
#endif
#if ENABLED(Y_DUAL_ENDSTOPS)
SERIAL_ECHOLNPAIR_P(SP_Y_STR, LINEAR_UNIT(endstops.y2_endstop_adj));
#endif
#if ENABLED(Z_MULTI_ENDSTOPS)
#if NUM_Z_STEPPER_DRIVERS >= 3
SERIAL_ECHOPAIR(" S2 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
CONFIG_ECHO_START();
SERIAL_ECHOPAIR(" M666 S3 Z", LINEAR_UNIT(endstops.z3_endstop_adj));
#if NUM_Z_STEPPER_DRIVERS >= 4
CONFIG_ECHO_START();
SERIAL_ECHOPAIR(" M666 S4 Z", LINEAR_UNIT(endstops.z4_endstop_adj));
#endif
#else
SERIAL_ECHOLNPAIR_P(SP_Z_STR, LINEAR_UNIT(endstops.z2_endstop_adj));
#endif
#endif
#endif

#endif // [XYZ]_DUAL_ENDSTOPS
#if EITHER(DELTA, HAS_EXTRA_ENDSTOPS)
M666_report(forReplay);
#endif

#if PREHEAT_COUNT

Expand Down

1 comment on commit 01ae1ce

@ellensp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit assumes delta is homing to max. Although this is true for 99% of deltas. it is not 100% true

Please sign in to comment.