Skip to content

Commit 5a88a80

Browse files
committed
🚸 Extend M360 (a Repetier code)
1 parent 12fdde2 commit 5a88a80

File tree

1 file changed

+113
-62
lines changed

1 file changed

+113
-62
lines changed

Marlin/src/gcode/host/M360.cpp

Lines changed: 113 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323
#include "../../inc/MarlinConfig.h"
2424

25+
/**
26+
* M360 Report Printer Configuration - Repetier Firmware
27+
* See https://github.com/repetier/Repetier-Firmware/blob/master/src/ArduinoAVR/Repetier/Printer.cpp
28+
*/
2529
#if ENABLED(REPETIER_GCODE_M360)
2630

2731
#include "../gcode.h"
@@ -33,74 +37,112 @@
3337
#include "../../module/temperature.h"
3438
#endif
3539

36-
static void config_prefix(PGM_P const name, PGM_P const pref=nullptr, const int8_t ind=-1) {
40+
#include <cstddef>
41+
42+
struct ProgStr {
43+
PGM_P ptr;
44+
constexpr ProgStr(PGM_P p) : ptr(p) {}
45+
ProgStr(FSTR_P f) : ptr(FTOP(f)) {}
46+
ProgStr(std::nullptr_t) : ptr(nullptr) {}
47+
48+
constexpr operator PGM_P() const { return ptr; }
49+
constexpr explicit operator bool() const { return ptr != nullptr; }
50+
};
51+
52+
static void config_prefix(ProgStr name, ProgStr pref=nullptr, int8_t ind=-1) {
3753
SERIAL_ECHOPGM("Config:");
38-
if (pref) SERIAL_ECHOPGM_P(pref);
54+
if (pref) SERIAL_ECHOPGM_P(static_cast<PGM_P>(pref));
3955
if (ind >= 0) { SERIAL_ECHO(ind); SERIAL_CHAR(':'); }
40-
SERIAL_ECHOPGM_P(name, C(':'));
56+
SERIAL_ECHOPGM_P(static_cast<PGM_P>(name), C(':'));
4157
}
42-
static void config_line(PGM_P const name, const float val, PGM_P const pref=nullptr, const int8_t ind=-1) {
58+
59+
template<typename T>
60+
static void config_line(ProgStr name, const T val, ProgStr pref=nullptr, int8_t ind=-1) {
4361
config_prefix(name, pref, ind);
4462
SERIAL_ECHOLN(val);
4563
}
46-
static void config_line(FSTR_P const name, const float val, FSTR_P const pref=nullptr, const int8_t ind=-1) {
47-
config_line(FTOP(name), val, FTOP(pref), ind);
48-
}
49-
static void config_line_e(const int8_t e, PGM_P const name, const float val) {
64+
65+
template<typename T>
66+
static void config_line_e(int8_t e, ProgStr name, const T val) {
5067
config_line(name, val, PSTR("Extr."), e + 1);
5168
}
52-
static void config_line_e(const int8_t e, FSTR_P const name, const float val) {
53-
config_line_e(e, FTOP(name), val);
54-
}
55-
5669
/**
5770
* M360: Report Firmware configuration
5871
* in RepRapFirmware-compatible format
5972
*/
6073
void GcodeSuite::M360() {
61-
PGMSTR(X_STR, "X");
62-
PGMSTR(Y_STR, "Y");
63-
PGMSTR(Z_STR, "Z");
64-
#if ANY(CLASSIC_JERK, HAS_LINEAR_E_JERK)
65-
PGMSTR(JERK_STR, "Jerk");
66-
#endif
67-
6874
//
6975
// Basics and Enabled items
7076
//
7177
config_line(F("Baudrate"), BAUDRATE);
7278
config_line(F("InputBuffer"), MAX_CMD_SIZE);
7379
config_line(F("PrintlineCache"), BUFSIZE);
74-
config_line(F("MixingExtruder"), ENABLED(MIXING_EXTRUDER));
75-
config_line(F("SDCard"), ENABLED(HAS_MEDIA));
76-
config_line(F("Fan"), ENABLED(HAS_FAN));
77-
config_line(F("LCD"), ENABLED(HAS_DISPLAY));
80+
config_line(F("MixingExtruder"), bool(ENABLED(MIXING_EXTRUDER)));
81+
config_line(F("SDCard"), bool(ENABLED(HAS_MEDIA)));
82+
config_line(F("Fan"), bool(ENABLED(HAS_FAN)));
83+
config_line(F("LCD"), bool(ENABLED(HAS_DISPLAY)));
7884
config_line(F("SoftwarePowerSwitch"), 1);
79-
config_line(F("SupportLocalFilamentchange"), ENABLED(ADVANCED_PAUSE_FEATURE));
80-
config_line(F("CaseLights"), ENABLED(CASE_LIGHT_ENABLE));
81-
config_line(F("ZProbe"), ENABLED(HAS_BED_PROBE));
82-
config_line(F("Autolevel"), ENABLED(HAS_LEVELING));
83-
config_line(F("EEPROM"), ENABLED(EEPROM_SETTINGS));
85+
config_line(F("SupportLocalFilamentchange"), bool(ENABLED(ADVANCED_PAUSE_FEATURE)));
86+
config_line(F("CaseLights"), bool(ENABLED(CASE_LIGHT_ENABLE)));
87+
config_line(F("ZProbe"), bool(ENABLED(HAS_BED_PROBE)));
88+
config_line(F("Autolevel"), bool(ENABLED(HAS_LEVELING)));
89+
config_line(F("EEPROM"), bool(ENABLED(EEPROM_SETTINGS)));
90+
91+
//
92+
// Axis letters, in PROGMEM
93+
//
94+
#define _DEFINE_A_STR(Q) PGMSTR(Q##_STR, STR_##Q);
95+
MAIN_AXIS_MAP(_DEFINE_A_STR);
8496

8597
//
8698
// Homing Directions
8799
//
88100
PGMSTR(H_DIR_STR, "HomeDir");
89-
config_line(H_DIR_STR, X_HOME_DIR, X_STR);
90-
config_line(H_DIR_STR, Y_HOME_DIR, Y_STR);
91-
config_line(H_DIR_STR, Z_HOME_DIR, Z_STR);
101+
#if X_HOME_DIR
102+
config_line(H_DIR_STR, X_HOME_DIR, X_STR);
103+
#endif
104+
#if Y_HOME_DIR
105+
config_line(H_DIR_STR, Y_HOME_DIR, Y_STR);
106+
#endif
107+
#if Z_HOME_DIR
108+
config_line(H_DIR_STR, Z_HOME_DIR, Z_STR);
109+
#endif
110+
#if I_HOME_DIR
111+
config_line(H_DIR_STR, I_HOME_DIR, I_STR);
112+
#endif
113+
#if J_HOME_DIR
114+
config_line(H_DIR_STR, J_HOME_DIR, J_STR);
115+
#endif
116+
#if K_HOME_DIR
117+
config_line(H_DIR_STR, K_HOME_DIR, K_STR);
118+
#endif
119+
#if U_HOME_DIR
120+
config_line(H_DIR_STR, U_HOME_DIR, U_STR);
121+
#endif
122+
#if V_HOME_DIR
123+
config_line(H_DIR_STR, V_HOME_DIR, V_STR);
124+
#endif
125+
#if W_HOME_DIR
126+
config_line(H_DIR_STR, W_HOME_DIR, W_STR);
127+
#endif
128+
129+
#if ANY(CLASSIC_JERK, HAS_LINEAR_E_JERK)
130+
PGMSTR(JERK_STR, "Jerk");
131+
#endif
92132

93133
//
94134
// XYZ Axis Jerk
95135
//
96136
#if ENABLED(CLASSIC_JERK)
97-
if (planner.max_jerk.x == planner.max_jerk.y)
98-
config_line(F("XY"), planner.max_jerk.x, FPSTR(JERK_STR));
137+
#define _REPORT_JERK(Q) config_line(Q##_STR, planner.max_jerk.Q, JERK_STR);
138+
if (TERN0(HAS_Y_AXIS, planner.max_jerk.x == planner.max_jerk.y))
139+
config_line(F("XY"), planner.max_jerk.x, JERK_STR);
99140
else {
100-
config_line(X_STR, planner.max_jerk.x, JERK_STR);
101-
config_line(Y_STR, planner.max_jerk.y, JERK_STR);
141+
TERN_(HAS_X_AXIS, _REPORT_JERK(X));
142+
TERN_(HAS_Y_AXIS, _REPORT_JERK(Y));
102143
}
103-
config_line(Z_STR, planner.max_jerk.z, JERK_STR);
144+
TERN_(HAS_Z_AXIS, config_line(Z_STR, planner.max_jerk.z, JERK_STR));
145+
SECONDARY_AXIS_MAP(_REPORT_JERK);
104146
#endif
105147

106148
//
@@ -112,53 +154,62 @@ void GcodeSuite::M360() {
112154
PGMSTR(UNRET_STR, "RetractionUndo");
113155
PGMSTR(SPEED_STR, "Speed");
114156
// M10 Retract with swap (long) moves
115-
config_line(F("Length"), fwretract.settings.retract_length, FPSTR(RET_STR));
157+
config_line(F("Length"), fwretract.settings.retract_length, RET_STR);
158+
config_line(F("LongLength"), fwretract.settings.swap_retract_length, RET_STR);
116159
config_line(SPEED_STR, fwretract.settings.retract_feedrate_mm_s, RET_STR);
117-
config_line(F("ZLift"), fwretract.settings.retract_zraise, FPSTR(RET_STR));
118-
config_line(F("LongLength"), fwretract.settings.swap_retract_length, FPSTR(RET_STR));
160+
config_line(F("ZLift"), fwretract.settings.retract_zraise, RET_STR);
119161
// M11 Recover (undo) with swap (long) moves
162+
config_line(F("ExtraLength"), fwretract.settings.retract_recover_extra, UNRET_STR);
163+
config_line(F("ExtraLongLength"), fwretract.settings.swap_retract_recover_extra, UNRET_STR);
120164
config_line(SPEED_STR, fwretract.settings.retract_recover_feedrate_mm_s, UNRET_STR);
121-
config_line(F("ExtraLength"), fwretract.settings.retract_recover_extra, FPSTR(UNRET_STR));
122-
config_line(F("ExtraLongLength"), fwretract.settings.swap_retract_recover_extra, FPSTR(UNRET_STR));
123-
config_line(F("LongSpeed"), fwretract.settings.swap_retract_recover_feedrate_mm_s, FPSTR(UNRET_STR));
165+
config_line(F("LongSpeed"), fwretract.settings.swap_retract_recover_feedrate_mm_s, UNRET_STR);
124166
#endif
125167

126168
//
127169
// Workspace boundaries
128170
//
129-
const xyz_pos_t dmin = { X_MIN_POS, Y_MIN_POS, Z_MIN_POS },
130-
dmax = { X_MAX_POS, Y_MAX_POS, Z_MAX_POS };
171+
const xyz_pos_t dmin = NUM_AXIS_ARRAY(X_MIN_POS, Y_MIN_POS, Z_MIN_POS, I_MIN_POS, J_MIN_POS, K_MIN_POS, U_MIN_POS, V_MIN_POS, W_MIN_POS),
172+
dmax = NUM_AXIS_ARRAY(X_MAX_POS, Y_MAX_POS, Z_MAX_POS, I_MAX_POS, J_MAX_POS, K_MAX_POS, U_MAX_POS, V_MAX_POS, W_MAX_POS);
131173
xyz_pos_t cmin = dmin, cmax = dmax;
132174
apply_motion_limits(cmin);
133175
apply_motion_limits(cmax);
134176
const xyz_pos_t wmin = cmin.asLogical(), wmax = cmax.asLogical();
135177

136178
PGMSTR(MIN_STR, "Min");
179+
#define _REPORT_MIN(Q) config_line(MIN_STR, wmin.Q, Q##_STR);
180+
MAIN_AXIS_MAP(_REPORT_MIN);
181+
137182
PGMSTR(MAX_STR, "Max");
183+
#define _REPORT_MAX(Q) config_line(MAX_STR, wmax.Q, Q##_STR);
184+
MAIN_AXIS_MAP(_REPORT_MAX);
185+
138186
PGMSTR(SIZE_STR, "Size");
139-
config_line(MIN_STR, wmin.x, X_STR);
140-
config_line(MIN_STR, wmin.y, Y_STR);
141-
config_line(MIN_STR, wmin.z, Z_STR);
142-
config_line(MAX_STR, wmax.x, X_STR);
143-
config_line(MAX_STR, wmax.y, Y_STR);
144-
config_line(MAX_STR, wmax.z, Z_STR);
145-
config_line(SIZE_STR, wmax.x - wmin.x, X_STR);
146-
config_line(SIZE_STR, wmax.y - wmin.y, Y_STR);
147-
config_line(SIZE_STR, wmax.z - wmin.z, Z_STR);
187+
#define _REPORT_SIZE(Q) config_line(SIZE_STR, wmax.Q - wmin.Q, Q##_STR);
188+
MAIN_AXIS_MAP(_REPORT_SIZE);
189+
190+
//
191+
// Axis Steps per mm
192+
//
193+
PGMSTR(S_MM_STR, "Steps/mm");
194+
#define _REPORT_S_MM(Q) config_line(S_MM_STR, planner.settings.axis_steps_per_mm[_AXIS(Q)], Q##_STR);
195+
MAIN_AXIS_MAP(_REPORT_S_MM);
148196

149197
//
150198
// Print and Travel Acceleration
151199
//
152-
#define _ACCEL(A,B) _MIN(planner.settings.max_acceleration_mm_per_s2[A##_AXIS], planner.settings.B)
200+
#define _ACCEL(Q,B) _MIN(planner.settings.max_acceleration_mm_per_s2[Q##_AXIS], planner.settings.B)
201+
153202
PGMSTR(P_ACC_STR, "PrintAccel");
203+
#define _REPORT_P_ACC(Q) config_line(P_ACC_STR, _ACCEL(Q, acceleration), Q##_STR);
204+
MAIN_AXIS_MAP(_REPORT_P_ACC);
205+
154206
PGMSTR(T_ACC_STR, "TravelAccel");
155-
config_line(P_ACC_STR, _ACCEL(X, acceleration), X_STR);
156-
config_line(P_ACC_STR, _ACCEL(Y, acceleration), Y_STR);
157-
config_line(P_ACC_STR, _ACCEL(Z, acceleration), Z_STR);
158-
config_line(T_ACC_STR, _ACCEL(X, travel_acceleration), X_STR);
159-
config_line(T_ACC_STR, _ACCEL(Y, travel_acceleration), Y_STR);
160-
config_line(T_ACC_STR, _ACCEL(Z, travel_acceleration), Z_STR);
207+
#define _REPORT_T_ACC(Q) config_line(T_ACC_STR, _ACCEL(Q, travel_acceleration), Q##_STR);
208+
MAIN_AXIS_MAP(_REPORT_T_ACC);
161209

210+
//
211+
// Printer Type
212+
//
162213
config_prefix(PSTR("PrinterType"));
163214
SERIAL_ECHOLNPGM(
164215
TERN_(DELTA, "Delta")
@@ -189,12 +240,12 @@ void GcodeSuite::M360() {
189240
#elif ENABLED(CLASSIC_JERK)
190241
config_line_e(e, JERK_STR, planner.max_jerk.e);
191242
#endif
192-
config_line_e(e, F("MaxSpeed"), planner.settings.max_feedrate_mm_s[E_AXIS_N(e)]);
193243
config_line_e(e, F("Acceleration"), planner.settings.max_acceleration_mm_per_s2[E_AXIS_N(e)]);
244+
config_line_e(e, F("MaxSpeed"), planner.settings.max_feedrate_mm_s[E_AXIS_N(e)]);
194245
config_line_e(e, F("Diameter"), TERN(NO_VOLUMETRICS, DEFAULT_NOMINAL_FILAMENT_DIA, planner.filament_size[e]));
195246
config_line_e(e, F("MaxTemp"), thermalManager.hotend_maxtemp[e]);
196247
}
197248
#endif
198249
}
199250

200-
#endif
251+
#endif // REPETIER_GCODE_M360

0 commit comments

Comments
 (0)