Skip to content

Commit 854f331

Browse files
plampixthinkyhead
andauthored
✨ EDITABLE_STEPS_PER_UNIT (MarlinFirmware#26618)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 1d46e67 commit 854f331

38 files changed

+711
-607
lines changed

Marlin/Configuration.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -1231,11 +1231,16 @@
12311231

12321232
/**
12331233
* Default Axis Steps Per Unit (linear=steps/mm, rotational=steps/°)
1234-
* Override with M92
1234+
* Override with M92 (when enabled below)
12351235
* X, Y, Z [, I [, J [, K...]]], E0 [, E1[, E2...]]
12361236
*/
12371237
#define DEFAULT_AXIS_STEPS_PER_UNIT { 80, 80, 400, 500 }
12381238

1239+
/**
1240+
* Enable support for M92. Disable to save at least ~530 bytes of flash.
1241+
*/
1242+
#define EDITABLE_STEPS_PER_UNIT
1243+
12391244
/**
12401245
* Default Max Feed Rate (linear=mm/s, rotational=°/s)
12411246
* Override with M203

Marlin/src/feature/encoder_i2c.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -422,22 +422,22 @@ void I2CPositionEncoder::calibrate_steps_mm(const uint8_t iter) {
422422
travelledDistance = mm_from_count(ABS(stopCount - startCount));
423423

424424
SERIAL_ECHOLNPGM("Attempted travel: ", travelDistance, "mm");
425-
SERIAL_ECHOLNPGM(" Actual travel: ", travelledDistance, "mm");
425+
SERIAL_ECHOLNPGM(" Actual travel: ", travelledDistance, "mm");
426426

427-
//Calculate new axis steps per unit
427+
// Calculate new axis steps per unit
428428
old_steps_mm = planner.settings.axis_steps_per_mm[encoderAxis];
429429
new_steps_mm = (old_steps_mm * travelDistance) / travelledDistance;
430430

431431
SERIAL_ECHOLNPGM("Old steps/mm: ", old_steps_mm);
432432
SERIAL_ECHOLNPGM("New steps/mm: ", new_steps_mm);
433433

434-
//Save new value
434+
// Save new value
435435
planner.settings.axis_steps_per_mm[encoderAxis] = new_steps_mm;
436436

437437
if (iter > 1) {
438438
total += new_steps_mm;
439439

440-
// swap start and end points so next loop runs from current position
440+
// Swap start and end points so next loop runs from current position
441441
const float tempCoord = startCoord[encoderAxis];
442442
startCoord[encoderAxis] = endCoord[encoderAxis];
443443
endCoord[encoderAxis] = tempCoord;

Marlin/src/gcode/config/M92.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
*
2121
*/
2222

23+
#include "../../inc/MarlinConfigPre.h"
24+
25+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
26+
2327
#include "../gcode.h"
2428
#include "../../module/planner.h"
2529

@@ -37,6 +41,7 @@
3741
* H<microsteps> - Specify micro-steps to use. Best guess if not supplied.
3842
* L<linear> - Desired layer height in current units. Nearest good heights are shown.
3943
*/
44+
4045
void GcodeSuite::M92() {
4146

4247
const int8_t target_extruder = get_target_extruder_from_command();
@@ -127,3 +132,5 @@ void GcodeSuite::M92_report(const bool forReplay/*=true*/, const int8_t e/*=-1*/
127132
UNUSED(e);
128133
#endif
129134
}
135+
136+
#endif // EDITABLE_STEPS_PER_UNIT

Marlin/src/gcode/gcode.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
669669
case 87: M87(); break; // M87: Cancel Hotend Idle Timeout
670670
#endif
671671

672-
case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes
672+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
673+
case 92: M92(); break; // M92: Set the steps-per-unit for one or more axes
674+
#endif
675+
673676
case 114: M114(); break; // M114: Report current position
674677

675678
#if ENABLED(CAPABILITIES_REPORT)

Marlin/src/gcode/gcode.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
* M84 - Disable steppers until next move, or use S<seconds> to specify an idle
129129
* duration after which steppers should turn off. S0 disables the timeout.
130130
* M85 - Set inactivity shutdown timer with parameter S<seconds>. To disable set zero (default)
131-
* M92 - Set planner.settings.axis_steps_per_mm for one or more axes.
131+
* M92 - Set planner.settings.axis_steps_per_mm for one or more axes. (Requires EDITABLE_STEPS_PER_UNIT)
132132
*
133133
* M100 - Watch Free Memory (for debugging) (Requires M100_FREE_MEMORY_WATCHER)
134134
*
@@ -719,8 +719,10 @@ class GcodeSuite {
719719
static void M87();
720720
#endif
721721

722-
static void M92();
723-
static void M92_report(const bool forReplay=true, const int8_t e=-1);
722+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
723+
static void M92();
724+
static void M92_report(const bool forReplay=true, const int8_t e=-1);
725+
#endif
724726

725727
#if ENABLED(M100_FREE_MEMORY_WATCHER)
726728
static void M100();

Marlin/src/inc/SanityCheck.h

+2
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,8 @@ static_assert(COUNT(arm) == LOGICAL_AXES, "AXIS_RELATIVE_MODES must contain " _L
458458
#if ENABLED(I2C_POSITION_ENCODERS)
459459
#if !ALL(BABYSTEPPING, BABYSTEP_XY)
460460
#error "I2C_POSITION_ENCODERS requires BABYSTEPPING and BABYSTEP_XY."
461+
#elif DISABLED(EDITABLE_STEPS_PER_UNIT)
462+
#error "EDITABLE_STEPS_PER_UNIT is required for I2C_POSITION_ENCODERS."
461463
#elif !WITHIN(I2CPE_ENCODER_CNT, 1, 5)
462464
#error "I2CPE_ENCODER_CNT must be between 1 and 5."
463465
#endif

Marlin/src/inc/Warnings.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -833,3 +833,10 @@
833833
#if ALL(FT_MOTION, I2S_STEPPER_STREAM)
834834
#warning "FT_MOTION has not been tested with I2S_STEPPER_STREAM."
835835
#endif
836+
837+
/**
838+
* User doesn't have or disabled G92?
839+
*/
840+
#if DISABLED(EDITABLE_STEPS_PER_UNIT)
841+
#warning "EDITABLE_STEPS_PER_UNIT is required to enable G92 runtime configuration of steps-per-unit."
842+
#endif

Marlin/src/lcd/e3v2/creality/dwin.cpp

+22-16
Original file line numberDiff line numberDiff line change
@@ -1619,23 +1619,27 @@ void hmiMaxAccelerationXYZE() {
16191619

16201620
#endif // CLASSIC_JERK
16211621

1622-
void hmiStepXYZE() {
1623-
EncoderState encoder_diffState = encoderReceiveAnalyze();
1624-
if (encoder_diffState == ENCODER_DIFF_NO) return;
1625-
if (applyEncoder(encoder_diffState, hmiValues.maxStepScaled)) {
1626-
checkkey = ID_Step;
1627-
encoderRate.enabled = false;
1622+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
1623+
1624+
void hmiStepXYZE() {
1625+
EncoderState encoder_diffState = encoderReceiveAnalyze();
1626+
if (encoder_diffState == ENCODER_DIFF_NO) return;
1627+
if (applyEncoder(encoder_diffState, hmiValues.maxStepScaled)) {
1628+
checkkey = ID_Step;
1629+
encoderRate.enabled = false;
1630+
if (WITHIN(hmiFlag.step_axis, X_AXIS, LAST_AXIS))
1631+
planner.settings.axis_steps_per_mm[hmiFlag.step_axis] = hmiValues.maxStepScaled / MINUNITMULT;
1632+
drawEditFloat3(select_step.now, hmiValues.maxStepScaled);
1633+
return;
1634+
}
1635+
// Step limit
16281636
if (WITHIN(hmiFlag.step_axis, X_AXIS, LAST_AXIS))
1629-
planner.settings.axis_steps_per_mm[hmiFlag.step_axis] = hmiValues.maxStepScaled / MINUNITMULT;
1630-
drawEditFloat3(select_step.now, hmiValues.maxStepScaled);
1631-
return;
1637+
LIMIT(hmiValues.maxStepScaled, min_steps_edit_values[hmiFlag.step_axis] * MINUNITMULT, max_steps_edit_values[hmiFlag.step_axis] * MINUNITMULT);
1638+
// Step value
1639+
drawEditFloat3(select_step.now, hmiValues.maxStepScaled, true);
16321640
}
1633-
// Step limit
1634-
if (WITHIN(hmiFlag.step_axis, X_AXIS, LAST_AXIS))
1635-
LIMIT(hmiValues.maxStepScaled, min_steps_edit_values[hmiFlag.step_axis] * MINUNITMULT, max_steps_edit_values[hmiFlag.step_axis] * MINUNITMULT);
1636-
// Step value
1637-
drawEditFloat3(select_step.now, hmiValues.maxStepScaled, true);
1638-
}
1641+
1642+
#endif // EDITABLE_STEPS_PER_UNIT
16391643

16401644
// Draw X, Y, Z and blink if in an un-homed or un-trusted state
16411645
void _update_axis_value(const AxisEnum axis, const uint16_t x, const uint16_t y, const bool blink, const bool force) {
@@ -4279,7 +4283,9 @@ void dwinHandleScreen() {
42794283
#if ENABLED(CLASSIC_JERK)
42804284
case ID_MaxJerkValue: hmiMaxJerkXYZE(); break;
42814285
#endif
4282-
case ID_StepValue: hmiStepXYZE(); break;
4286+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
4287+
case ID_StepValue: hmiStepXYZE(); break;
4288+
#endif
42834289
default: break;
42844290
}
42854291
}

Marlin/src/lcd/e3v2/creality/dwin.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ void hmiPrintSpeed();
204204
void hmiMaxFeedspeedXYZE();
205205
void hmiMaxAccelerationXYZE();
206206
void hmiMaxJerkXYZE();
207-
void hmiStepXYZE();
207+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
208+
void hmiStepXYZE();
209+
#endif
210+
208211
void hmiSetLanguageCache();
209212

210213
void updateVariable();

Marlin/src/lcd/e3v2/jyersui/dwin.cpp

+77-62
Original file line numberDiff line numberDiff line change
@@ -2364,6 +2364,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
23642364
else
23652365
drawMenu(ID_MaxAcceleration);
23662366
break;
2367+
23672368
#if ENABLED(CLASSIC_JERK)
23682369
case MOTION_JERK:
23692370
if (draw)
@@ -2372,12 +2373,16 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
23722373
drawMenu(ID_MaxJerk);
23732374
break;
23742375
#endif
2375-
case MOTION_STEPS:
2376-
if (draw)
2377-
drawMenuItem(row, ICON_Step, GET_TEXT_F(MSG_STEPS_PER_MM), nullptr, true);
2378-
else
2379-
drawMenu(ID_Steps);
2380-
break;
2376+
2377+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
2378+
case MOTION_STEPS:
2379+
if (draw)
2380+
drawMenuItem(row, ICON_Step, GET_TEXT_F(MSG_STEPS_PER_MM), nullptr, true);
2381+
else
2382+
drawMenu(ID_Steps);
2383+
break;
2384+
#endif
2385+
23812386
#if HAS_HOTEND
23822387
case MOTION_FLOW:
23832388
if (draw) {
@@ -2388,6 +2393,7 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
23882393
modifyValue(planner.flow_percentage[0], MIN_FLOW_RATE, MAX_FLOW_RATE, 1, []{ planner.refresh_e_factor(0); });
23892394
break;
23902395
#endif
2396+
23912397
#if ENABLED(LIN_ADVANCE)
23922398
case MOTION_LA:
23932399
if (draw) {
@@ -2613,64 +2619,69 @@ void JyersDWIN::menuItemHandler(const uint8_t menu, const uint8_t item, bool dra
26132619
}
26142620
break;
26152621
#endif
2616-
case ID_Steps:
26172622

2618-
#define STEPS_BACK 0
2619-
#define STEPS_X (STEPS_BACK + ENABLED(HAS_X_AXIS))
2620-
#define STEPS_Y (STEPS_X + ENABLED(HAS_Y_AXIS))
2621-
#define STEPS_Z (STEPS_Y + ENABLED(HAS_Z_AXIS))
2622-
#define STEPS_E (STEPS_Z + ENABLED(HAS_HOTEND))
2623-
#define STEPS_TOTAL STEPS_E
2623+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
26242624

2625-
switch (item) {
2626-
case STEPS_BACK:
2627-
if (draw)
2628-
drawMenuItem(row, ICON_Back, GET_TEXT_F(MSG_BACK));
2629-
else
2630-
drawMenu(ID_Motion, MOTION_STEPS);
2631-
break;
2632-
#if HAS_X_AXIS
2633-
case STEPS_X:
2634-
if (draw) {
2635-
drawMenuItem(row, ICON_StepX, GET_TEXT_F(MSG_A_STEPS));
2636-
drawFloat(planner.settings.axis_steps_per_mm[X_AXIS], row, false, STEPS_UNIT);
2637-
}
2638-
else
2639-
modifyValue(planner.settings.axis_steps_per_mm[X_AXIS], min_steps_edit_values.x, max_steps_edit_values.x, STEPS_UNIT);
2640-
break;
2641-
#endif
2642-
#if HAS_Y_AXIS
2643-
case STEPS_Y:
2644-
if (draw) {
2645-
drawMenuItem(row, ICON_StepY, GET_TEXT_F(MSG_B_STEPS));
2646-
drawFloat(planner.settings.axis_steps_per_mm[Y_AXIS], row, false, STEPS_UNIT);
2647-
}
2648-
else
2649-
modifyValue(planner.settings.axis_steps_per_mm[Y_AXIS], min_steps_edit_values.y, max_steps_edit_values.y, STEPS_UNIT);
2650-
break;
2651-
#endif
2652-
#if HAS_Z_AXIS
2653-
case STEPS_Z:
2654-
if (draw) {
2655-
drawMenuItem(row, ICON_StepZ, GET_TEXT_F(MSG_C_STEPS));
2656-
drawFloat(planner.settings.axis_steps_per_mm[Z_AXIS], row, false, STEPS_UNIT);
2657-
}
2658-
else
2659-
modifyValue(planner.settings.axis_steps_per_mm[Z_AXIS], min_steps_edit_values.z, max_steps_edit_values.z, STEPS_UNIT);
2660-
break;
2661-
#endif
2662-
#if HAS_HOTEND
2663-
case STEPS_E:
2664-
if (draw) {
2665-
drawMenuItem(row, ICON_StepE, GET_TEXT_F(MSG_E_STEPS));
2666-
drawFloat(planner.settings.axis_steps_per_mm[E_AXIS], row, false, STEPS_UNIT);
2667-
}
2625+
case ID_Steps:
2626+
2627+
#define STEPS_BACK 0
2628+
#define STEPS_X (STEPS_BACK + ENABLED(HAS_X_AXIS))
2629+
#define STEPS_Y (STEPS_X + ENABLED(HAS_Y_AXIS))
2630+
#define STEPS_Z (STEPS_Y + ENABLED(HAS_Z_AXIS))
2631+
#define STEPS_E (STEPS_Z + ENABLED(HAS_HOTEND))
2632+
#define STEPS_TOTAL STEPS_E
2633+
2634+
switch (item) {
2635+
case STEPS_BACK:
2636+
if (draw)
2637+
drawMenuItem(row, ICON_Back, GET_TEXT_F(MSG_BACK));
26682638
else
2669-
modifyValue(planner.settings.axis_steps_per_mm[E_AXIS], min_steps_edit_values.e, max_steps_edit_values.e, STEPS_UNIT);
2639+
drawMenu(ID_Motion, MOTION_STEPS);
26702640
break;
2671-
#endif
2672-
}
2673-
break;
2641+
#if HAS_X_AXIS
2642+
case STEPS_X:
2643+
if (draw) {
2644+
drawMenuItem(row, ICON_StepX, GET_TEXT_F(MSG_A_STEPS));
2645+
drawFloat(planner.settings.axis_steps_per_mm[X_AXIS], row, false, STEPS_UNIT);
2646+
}
2647+
else
2648+
modifyValue(planner.settings.axis_steps_per_mm[X_AXIS], min_steps_edit_values.x, max_steps_edit_values.x, STEPS_UNIT);
2649+
break;
2650+
#endif
2651+
#if HAS_Y_AXIS
2652+
case STEPS_Y:
2653+
if (draw) {
2654+
drawMenuItem(row, ICON_StepY, GET_TEXT_F(MSG_B_STEPS));
2655+
drawFloat(planner.settings.axis_steps_per_mm[Y_AXIS], row, false, STEPS_UNIT);
2656+
}
2657+
else
2658+
modifyValue(planner.settings.axis_steps_per_mm[Y_AXIS], min_steps_edit_values.y, max_steps_edit_values.y, STEPS_UNIT);
2659+
break;
2660+
#endif
2661+
#if HAS_Z_AXIS
2662+
case STEPS_Z:
2663+
if (draw) {
2664+
drawMenuItem(row, ICON_StepZ, GET_TEXT_F(MSG_C_STEPS));
2665+
drawFloat(planner.settings.axis_steps_per_mm[Z_AXIS], row, false, STEPS_UNIT);
2666+
}
2667+
else
2668+
modifyValue(planner.settings.axis_steps_per_mm[Z_AXIS], min_steps_edit_values.z, max_steps_edit_values.z, STEPS_UNIT);
2669+
break;
2670+
#endif
2671+
#if HAS_HOTEND
2672+
case STEPS_E:
2673+
if (draw) {
2674+
drawMenuItem(row, ICON_StepE, GET_TEXT_F(MSG_E_STEPS));
2675+
drawFloat(planner.settings.axis_steps_per_mm[E_AXIS], row, false, STEPS_UNIT);
2676+
}
2677+
else
2678+
modifyValue(planner.settings.axis_steps_per_mm[E_AXIS], min_steps_edit_values.e, max_steps_edit_values.e, STEPS_UNIT);
2679+
break;
2680+
#endif
2681+
}
2682+
break;
2683+
2684+
#endif // EDITABLE_STEPS_PER_UNIT
26742685

26752686
case ID_Visual:
26762687

@@ -4173,7 +4184,9 @@ FSTR_P JyersDWIN::getMenuTitle(const uint8_t menu) {
41734184
#if ENABLED(CLASSIC_JERK)
41744185
case ID_MaxJerk: return F("Max Jerk");
41754186
#endif
4176-
case ID_Steps: return GET_TEXT_F(MSG_STEPS_PER_MM);
4187+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
4188+
case ID_Steps: return GET_TEXT_F(MSG_STEPS_PER_MM);
4189+
#endif
41774190
case ID_Visual: return F("Visual Settings");
41784191
case ID_Advanced: return GET_TEXT_F(MSG_ADVANCED_SETTINGS);
41794192
#if HAS_BED_PROBE
@@ -4250,7 +4263,9 @@ uint8_t JyersDWIN::getMenuSize(const uint8_t menu) {
42504263
#if ENABLED(CLASSIC_JERK)
42514264
case ID_MaxJerk: return JERK_TOTAL;
42524265
#endif
4253-
case ID_Steps: return STEPS_TOTAL;
4266+
#if ENABLED(EDITABLE_STEPS_PER_UNIT)
4267+
case ID_Steps: return STEPS_TOTAL;
4268+
#endif
42544269
case ID_Visual: return VISUAL_TOTAL;
42554270
case ID_Advanced: return ADVANCED_TOTAL;
42564271
#if HAS_BED_PROBE

Marlin/src/lcd/e3v2/jyersui/dwin.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ enum menuID : uint8_t {
101101
ID_MaxSpeed,
102102
ID_MaxAcceleration,
103103
ID_MaxJerk,
104-
ID_Steps,
104+
OPTITEM(EDITABLE_STEPS_PER_UNIT, ID_Steps)
105105
ID_Visual,
106106
ID_ColorSettings,
107107
ID_Advanced,

0 commit comments

Comments
 (0)