Skip to content

Commit

Permalink
Add M207/8/9 reporting (MarlinFirmware#21335)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead authored Mar 12, 2021
1 parent 604c5de commit 7f1fa0d
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 54 deletions.
76 changes: 76 additions & 0 deletions Marlin/src/feature/fwretract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ FWRetract fwretract; // Single instance - this calls the constructor
#include "../module/planner.h"
#include "../module/stepper.h"

#include "../gcode/parser.h"

#if ENABLED(RETRACT_SYNC_MIXING)
#include "mixing.h"
#endif
Expand Down Expand Up @@ -198,4 +200,78 @@ void FWRetract::retract(const bool retracting
//*/
}

//extern const char SP_Z_STR[];

/**
* M207: Set firmware retraction values
*
* S[+units] retract_length
* W[+units] swap_retract_length (multi-extruder)
* F[units/min] retract_feedrate_mm_s
* Z[units] retract_zraise
*/
void FWRetract::M207() {
if (!parser.seen("FSWZ")) return M207_report();
if (parser.seen('S')) settings.retract_length = parser.value_axis_units(E_AXIS);
if (parser.seen('F')) settings.retract_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
if (parser.seen('Z')) settings.retract_zraise = parser.value_linear_units();
if (parser.seen('W')) settings.swap_retract_length = parser.value_axis_units(E_AXIS);
}

void FWRetract::M207_report(const bool forReplay/*=false*/) {
if (!forReplay) { SERIAL_ECHO_MSG("; Retract: S<length> F<units/m> Z<lift>"); SERIAL_ECHO_START(); }
SERIAL_ECHOLNPAIR_P(
PSTR(" M207 S"), LINEAR_UNIT(settings.retract_length)
, PSTR(" W"), LINEAR_UNIT(settings.swap_retract_length)
, PSTR(" F"), LINEAR_UNIT(MMS_TO_MMM(settings.retract_feedrate_mm_s))
, SP_Z_STR, LINEAR_UNIT(settings.retract_zraise)
);
}

/**
* M208: Set firmware un-retraction values
*
* S[+units] retract_recover_extra (in addition to M207 S*)
* W[+units] swap_retract_recover_extra (multi-extruder)
* F[units/min] retract_recover_feedrate_mm_s
* R[units/min] swap_retract_recover_feedrate_mm_s
*/
void FWRetract::M208() {
if (!parser.seen("FSRW")) return M208_report();
if (parser.seen('S')) settings.retract_recover_extra = parser.value_axis_units(E_AXIS);
if (parser.seen('F')) settings.retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
if (parser.seen('R')) settings.swap_retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
if (parser.seen('W')) settings.swap_retract_recover_extra = parser.value_axis_units(E_AXIS);
}

void FWRetract::M208_report(const bool forReplay/*=false*/) {
if (!forReplay) { SERIAL_ECHO_MSG("; Recover: S<length> F<units/m>"); SERIAL_ECHO_START(); }
SERIAL_ECHOLNPAIR(
" M208 S", LINEAR_UNIT(settings.retract_recover_extra)
, " W", LINEAR_UNIT(settings.swap_retract_recover_extra)
, " F", LINEAR_UNIT(MMS_TO_MMM(settings.retract_recover_feedrate_mm_s))
);
}

#if ENABLED(FWRETRACT_AUTORETRACT)

/**
* M209: Enable automatic retract (M209 S1)
* For slicers that don't support G10/11, reversed extrude-only
* moves will be classified as retraction.
*/
void FWRetract::M209() {
if (!parser.seen('S')) return M209_report();
if (MIN_AUTORETRACT <= MAX_AUTORETRACT)
enable_autoretract(parser.value_bool());
}

void FWRetract::M209_report(const bool forReplay/*=false*/) {
if (!forReplay) { SERIAL_ECHO_MSG("; Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover"); SERIAL_ECHO_START(); }
SERIAL_ECHOLNPAIR(" M209 S", autoretract_enabled);
}

#endif // FWRETRACT_AUTORETRACT


#endif // FWRETRACT
9 changes: 9 additions & 0 deletions Marlin/src/feature/fwretract.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class FWRetract {
, bool swapping = false
#endif
);

static void M207();
static void M207_report(const bool forReplay=false);
static void M208();
static void M208_report(const bool forReplay=false);
#if ENABLED(FWRETRACT_AUTORETRACT)
static void M209();
static void M209_report(const bool forReplay=false);
#endif
};

extern FWRetract fwretract;
Expand Down
36 changes: 7 additions & 29 deletions Marlin/src/gcode/feature/fwretract/M207-M209.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,46 +29,24 @@

/**
* M207: Set firmware retraction values
*
* S[+units] retract_length
* W[+units] swap_retract_length (multi-extruder)
* F[units/min] retract_feedrate_mm_s
* Z[units] retract_zraise
*/
void GcodeSuite::M207() {
if (parser.seen('S')) fwretract.settings.retract_length = parser.value_axis_units(E_AXIS);
if (parser.seen('F')) fwretract.settings.retract_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
if (parser.seen('Z')) fwretract.settings.retract_zraise = parser.value_linear_units();
if (parser.seen('W')) fwretract.settings.swap_retract_length = parser.value_axis_units(E_AXIS);
}
void GcodeSuite::M207() { fwretract.M207(); }

/**
* M208: Set firmware un-retraction values
*
* S[+units] retract_recover_extra (in addition to M207 S*)
* W[+units] swap_retract_recover_extra (multi-extruder)
* F[units/min] retract_recover_feedrate_mm_s
* R[units/min] swap_retract_recover_feedrate_mm_s
*/
void GcodeSuite::M208() {
if (parser.seen('S')) fwretract.settings.retract_recover_extra = parser.value_axis_units(E_AXIS);
if (parser.seen('F')) fwretract.settings.retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
if (parser.seen('R')) fwretract.settings.swap_retract_recover_feedrate_mm_s = MMM_TO_MMS(parser.value_axis_units(E_AXIS));
if (parser.seen('W')) fwretract.settings.swap_retract_recover_extra = parser.value_axis_units(E_AXIS);
}
void GcodeSuite::M208() { fwretract.M208(); }

#if ENABLED(FWRETRACT_AUTORETRACT)

/**
* M209: Enable automatic retract (M209 S1)
* For slicers that don't support G10/11, reversed extrude-only
* moves will be classified as retraction.
*
* For slicers that don't support G10/11, reversed
* extruder-only moves can be classified as retraction.
*/
void GcodeSuite::M209() {
if (MIN_AUTORETRACT <= MAX_AUTORETRACT && parser.seen('S'))
fwretract.enable_autoretract(parser.value_bool());
}
void GcodeSuite::M209() { fwretract.M209(); }

#endif // FWRETRACT_AUTORETRACT
#endif

#endif // FWRETRACT
4 changes: 2 additions & 2 deletions Marlin/src/gcode/geometry/M206_M428.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "../../libs/buzzer.h"
#include "../../MarlinCore.h"

void m206_report() {
void M206_report() {
SERIAL_ECHOLNPAIR_P(PSTR("M206 X"), home_offset.x, SP_Y_STR, home_offset.y, SP_Z_STR, home_offset.z);
}

Expand All @@ -52,7 +52,7 @@ void GcodeSuite::M206() {
#endif

if (!parser.seen("XYZ"))
m206_report();
M206_report();
else
report_current_position();
}
Expand Down
27 changes: 4 additions & 23 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3466,29 +3466,10 @@ void MarlinSettings::reset() {
#endif

#if ENABLED(FWRETRACT)

CONFIG_ECHO_HEADING("Retract: S<length> F<units/m> Z<lift>");
CONFIG_ECHO_START();
SERIAL_ECHOLNPAIR_P(
PSTR(" M207 S"), LINEAR_UNIT(fwretract.settings.retract_length)
, PSTR(" W"), LINEAR_UNIT(fwretract.settings.swap_retract_length)
, PSTR(" F"), LINEAR_UNIT(MMS_TO_MMM(fwretract.settings.retract_feedrate_mm_s))
, SP_Z_STR, LINEAR_UNIT(fwretract.settings.retract_zraise)
);

CONFIG_ECHO_HEADING("Recover: S<length> F<units/m>");
CONFIG_ECHO_MSG(
" M208 S", LINEAR_UNIT(fwretract.settings.retract_recover_extra)
, " W", LINEAR_UNIT(fwretract.settings.swap_retract_recover_extra)
, " F", LINEAR_UNIT(MMS_TO_MMM(fwretract.settings.retract_recover_feedrate_mm_s))
);

#if ENABLED(FWRETRACT_AUTORETRACT)
CONFIG_ECHO_HEADING("Auto-Retract: S=0 to disable, 1 to interpret E-only moves as retract/recover");
CONFIG_ECHO_MSG(" M209 S", fwretract.autoretract_enabled);
#endif

#endif // FWRETRACT
fwretract.M207_report(forReplay);
fwretract.M208_report(forReplay);
TERN_(FWRETRACT_AUTORETRACT, fwretract.M209_report(forReplay));
#endif

/**
* Probe Offset
Expand Down

0 comments on commit 7f1fa0d

Please sign in to comment.