Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional edit steps per unit #26618

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
rename to CONFIGURE_STEPS_PER_UNIT, add filtering, make everything re…
…lated to M92 conditional
Peter Palm committed Jan 3, 2024
commit de929c5e4d39a49b5b854f2ca85d7b33e4ba7fe8
4 changes: 2 additions & 2 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
@@ -1237,9 +1237,9 @@
#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 400, 500 }

/**
* Disable support for M92 to save ~530 bytes of flash (1400 more if using a display)
* Enable support for M92. Disable to save ~530 bytes of flash (1400 more if using a display)
*/
//#define NO_EDIT_STEPS_PER_UNIT
#define CONFIGURE_STEPS_PER_UNIT

/**
* Default Max Feed Rate (linear=mm/s, rotational=°/s)
160 changes: 81 additions & 79 deletions Marlin/src/gcode/config/M92.cpp
Original file line number Diff line number Diff line change
@@ -37,93 +37,95 @@
* H<microsteps> - Specify micro-steps to use. Best guess if not supplied.
* L<linear> - Desired layer height in current units. Nearest good heights are shown.
*/
void GcodeSuite::M92() {
#if ENABLED(CONFIGURE_STEPS_PER_UNIT)
void GcodeSuite::M92() {

const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
const int8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

// No arguments? Show M92 report.
if (!parser.seen(STR_AXES_LOGICAL TERN_(MAGIC_NUMBERS_GCODE, "HL")))
return M92_report(true, target_extruder);
// No arguments? Show M92 report.
if (!parser.seen(STR_AXES_LOGICAL TERN_(MAGIC_NUMBERS_GCODE, "HL")))
return M92_report(true, target_extruder);

LOOP_LOGICAL_AXES(i) {
if (parser.seenval(AXIS_CHAR(i))) {
if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);
else {
#if HAS_EXTRUDERS
const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
if (value < 20) {
float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
#if ALL(CLASSIC_JERK, HAS_CLASSIC_E_JERK)
planner.max_jerk.e *= factor;
#endif
planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
}
planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
#endif
LOOP_LOGICAL_AXES(i) {
if (parser.seenval(AXIS_CHAR(i))) {
if (TERN1(HAS_EXTRUDERS, i != E_AXIS))
planner.settings.axis_steps_per_mm[i] = parser.value_per_axis_units((AxisEnum)i);
else {
#if HAS_EXTRUDERS
const float value = parser.value_per_axis_units((AxisEnum)(E_AXIS_N(target_extruder)));
if (value < 20) {
float factor = planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] / value; // increase e constants if M92 E14 is given for netfab.
#if ALL(CLASSIC_JERK, HAS_CLASSIC_E_JERK)
planner.max_jerk.e *= factor;
#endif
planner.settings.max_feedrate_mm_s[E_AXIS_N(target_extruder)] *= factor;
planner.max_acceleration_steps_per_s2[E_AXIS_N(target_extruder)] *= factor;
}
planner.settings.axis_steps_per_mm[E_AXIS_N(target_extruder)] = value;
#endif
}
}
}
}
planner.refresh_positioning();
planner.refresh_positioning();

#if ENABLED(MAGIC_NUMBERS_GCODE)
#ifndef Z_MICROSTEPS
#define Z_MICROSTEPS 16
#endif
const float wanted = parser.linearval('L');
if (parser.seen('H') || wanted) {
const uint16_t argH = parser.ushortval('H'),
micro_steps = argH ?: Z_MICROSTEPS;
const float z_full_step_mm = micro_steps * planner.mm_per_step[Z_AXIS];
SERIAL_ECHO_START();
SERIAL_ECHOPGM("{ micro_steps:", micro_steps, ", z_full_step_mm:", z_full_step_mm);
if (wanted) {
const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm;
SERIAL_ECHOPGM(", best:[", best);
if (best != wanted) { SERIAL_ECHO(C(','), best + z_full_step_mm); }
SERIAL_CHAR(']');
#if ENABLED(MAGIC_NUMBERS_GCODE)
#ifndef Z_MICROSTEPS
#define Z_MICROSTEPS 16
#endif
const float wanted = parser.linearval('L');
if (parser.seen('H') || wanted) {
const uint16_t argH = parser.ushortval('H'),
micro_steps = argH ?: Z_MICROSTEPS;
const float z_full_step_mm = micro_steps * planner.mm_per_step[Z_AXIS];
SERIAL_ECHO_START();
SERIAL_ECHOPGM("{ micro_steps:", micro_steps, ", z_full_step_mm:", z_full_step_mm);
if (wanted) {
const float best = uint16_t(wanted / z_full_step_mm) * z_full_step_mm;
SERIAL_ECHOPGM(", best:[", best);
if (best != wanted) { SERIAL_ECHO(C(','), best + z_full_step_mm); }
SERIAL_CHAR(']');
}
SERIAL_ECHOLNPGM(" }");
}
SERIAL_ECHOLNPGM(" }");
}
#endif
}
#endif
}

void GcodeSuite::M92_report(const bool forReplay/*=true*/, const int8_t e/*=-1*/) {
report_heading_etc(forReplay, F(STR_STEPS_PER_UNIT));
#if NUM_AXES
SERIAL_ECHOPGM_P(LIST_N(DOUBLE(NUM_AXES),
PSTR(" M92 X"), LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]),
SP_Y_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]),
SP_Z_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]),
SP_I_STR, I_AXIS_UNIT(planner.settings.axis_steps_per_mm[I_AXIS]),
SP_J_STR, J_AXIS_UNIT(planner.settings.axis_steps_per_mm[J_AXIS]),
SP_K_STR, K_AXIS_UNIT(planner.settings.axis_steps_per_mm[K_AXIS]),
SP_U_STR, U_AXIS_UNIT(planner.settings.axis_steps_per_mm[U_AXIS]),
SP_V_STR, V_AXIS_UNIT(planner.settings.axis_steps_per_mm[V_AXIS]),
SP_W_STR, W_AXIS_UNIT(planner.settings.axis_steps_per_mm[W_AXIS])
));
#endif
void GcodeSuite::M92_report(const bool forReplay/*=true*/, const int8_t e/*=-1*/) {
report_heading_etc(forReplay, F(STR_STEPS_PER_UNIT));
#if NUM_AXES
SERIAL_ECHOPGM_P(LIST_N(DOUBLE(NUM_AXES),
PSTR(" M92 X"), LINEAR_UNIT(planner.settings.axis_steps_per_mm[X_AXIS]),
SP_Y_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Y_AXIS]),
SP_Z_STR, LINEAR_UNIT(planner.settings.axis_steps_per_mm[Z_AXIS]),
SP_I_STR, I_AXIS_UNIT(planner.settings.axis_steps_per_mm[I_AXIS]),
SP_J_STR, J_AXIS_UNIT(planner.settings.axis_steps_per_mm[J_AXIS]),
SP_K_STR, K_AXIS_UNIT(planner.settings.axis_steps_per_mm[K_AXIS]),
SP_U_STR, U_AXIS_UNIT(planner.settings.axis_steps_per_mm[U_AXIS]),
SP_V_STR, V_AXIS_UNIT(planner.settings.axis_steps_per_mm[V_AXIS]),
SP_W_STR, W_AXIS_UNIT(planner.settings.axis_steps_per_mm[W_AXIS])
));
#endif

#if HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS)
SERIAL_ECHOPGM_P(SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS]));
#endif
#if HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS)
SERIAL_ECHOPGM_P(SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS]));
#endif

#if NUM_AXES || (HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS))
SERIAL_EOL();
#endif
#if NUM_AXES || (HAS_EXTRUDERS && DISABLED(DISTINCT_E_FACTORS))
SERIAL_EOL();
#endif

#if ENABLED(DISTINCT_E_FACTORS)
for (uint8_t i = 0; i < E_STEPPERS; ++i) {
if (e >= 0 && i != e) continue;
report_echo_start(forReplay);
SERIAL_ECHOLNPGM_P(
PSTR(" M92 T"), i,
SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)])
);
}
#else
UNUSED(e);
#endif
}
#if ENABLED(DISTINCT_E_FACTORS)
for (uint8_t i = 0; i < E_STEPPERS; ++i) {
if (e >= 0 && i != e) continue;
report_echo_start(forReplay);
SERIAL_ECHOLNPGM_P(
PSTR(" M92 T"), i,
SP_E_STR, VOLUMETRIC_UNIT(planner.settings.axis_steps_per_mm[E_AXIS_N(i)])
);
}
#else
UNUSED(e);
#endif
}
#endif
2 changes: 1 addition & 1 deletion Marlin/src/gcode/gcode.cpp
Original file line number Diff line number Diff line change
@@ -667,7 +667,7 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 87: M87(); break; // M87: Cancel Hotend Idle Timeout
#endif

#if DISABLED(NO_EDIT_STEPS_PER_UNIT)
#if ENABLED(CONFIGURE_STEPS_PER_UNIT)
case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes
#endif

6 changes: 4 additions & 2 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
@@ -719,8 +719,10 @@ class GcodeSuite {
static void M87();
#endif

static void M92();
static void M92_report(const bool forReplay=true, const int8_t e=-1);
#if ENABLED(CONFIGURE_STEPS_PER_UNIT)
static void M92();
static void M92_report(const bool forReplay=true, const int8_t e=-1);
#endif

#if ENABLED(M100_FREE_MEMORY_WATCHER)
static void M100();
2 changes: 1 addition & 1 deletion Marlin/src/lcd/menu/menu_advanced.cpp
Original file line number Diff line number Diff line change
@@ -722,7 +722,7 @@ void menu_advanced_settings() {
#endif // !SLIM_LCD_MENUS

// M92 - Steps Per mm
#if DISABLED(NO_EDIT_STEPS_PER_UNIT)
#if ENABLED(CONFIGURE_STEPS_PER_UNIT)
if (!is_busy)
SUBMENU(MSG_STEPS_PER_MM, menu_advanced_steps_per_mm);
#endif
6 changes: 4 additions & 2 deletions Marlin/src/module/settings.cpp
Original file line number Diff line number Diff line change
@@ -3662,7 +3662,9 @@ void MarlinSettings::reset() {
#define CONFIG_ECHO_MSG_P(V...) do{ CONFIG_ECHO_START(); SERIAL_ECHOLNPGM_P(V); }while(0)
#define CONFIG_ECHO_HEADING(STR) gcode.report_heading(forReplay, F(STR))

void M92_report(const bool echo=true, const int8_t e=-1);
#if ENABLED(CONFIGURE_STEPS_PER_UNIT)
void M92_report(const bool echo=true, const int8_t e=-1);
#endif

/**
* M503 - Report current settings in RAM
@@ -3700,7 +3702,7 @@ void MarlinSettings::reset() {
//
// M92 Steps per Unit
//
#if DISABLED(NO_EDIT_STEPS_PER_UNIT)
#if ENABLED(CONFIGURE_STEPS_PER_UNIT)
gcode.M92_report(forReplay);
#endif

1 change: 1 addition & 0 deletions ini/features.ini
Original file line number Diff line number Diff line change
@@ -287,6 +287,7 @@ HAS_EXTRA_ENDSTOPS = build_src_filter=+<src/gcode/calibrate/
SKEW_CORRECTION_GCODE = build_src_filter=+<src/gcode/calibrate/M852.cpp>
DIRECT_PIN_CONTROL = build_src_filter=+<src/gcode/control/M42.cpp> +<src/gcode/control/M226.cpp>
PINS_DEBUGGING = build_src_filter=+<src/gcode/config/M43.cpp>
CONFIGURE_STEPS_PER_UNIT = build_src_filter=+<src/gcode/config/M92.cpp>
HAS_MULTI_EXTRUDER = build_src_filter=+<src/gcode/config/M217.cpp>
HAS_HOTEND_OFFSET = build_src_filter=+<src/gcode/config/M218.cpp>
EDITABLE_SERVO_ANGLES = build_src_filter=+<src/gcode/config/M281.cpp>
1 change: 0 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -97,7 +97,6 @@ default_src_filter = +<src/*> -<src/config> -<src/tests>
; Minimal Requirements
;
+<src/gcode/calibrate/G28.cpp>
+<src/gcode/config/M92.cpp>
+<src/gcode/config/M200-M205.cpp>
+<src/gcode/config/M220.cpp>
+<src/gcode/control/M17_M18_M84.cpp>