From c4db8e49a7429a696431c0d3419b545d13eead31 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sun, 1 Mar 2020 10:36:15 -0600 Subject: [PATCH] XYZ_CHAR macro --- Marlin/src/core/types.h | 1 + Marlin/src/core/utility.cpp | 24 +++++++++---------- Marlin/src/gcode/calibrate/M425.cpp | 6 ++--- Marlin/src/gcode/calibrate/M666.cpp | 4 ++-- Marlin/src/gcode/control/M605.cpp | 2 +- Marlin/src/gcode/feature/pause/G61.cpp | 4 ++-- .../src/gcode/feature/trinamic/M911-M914.cpp | 2 +- Marlin/src/gcode/gcode.cpp | 2 +- Marlin/src/gcode/geometry/M206_M428.cpp | 2 +- Marlin/src/gcode/host/M114.cpp | 4 ++-- Marlin/src/gcode/motion/M290.cpp | 4 ++-- Marlin/src/module/motion.cpp | 4 ++-- 12 files changed, 30 insertions(+), 29 deletions(-) diff --git a/Marlin/src/core/types.h b/Marlin/src/core/types.h index 17301bd8c1..c56ce41895 100644 --- a/Marlin/src/core/types.h +++ b/Marlin/src/core/types.h @@ -483,3 +483,4 @@ struct XYZEval { #undef FI const xyze_char_t axis_codes { 'X', 'Y', 'Z', 'E' }; +#define XYZ_CHAR(A) ('X' + char(A)) diff --git a/Marlin/src/core/utility.cpp b/Marlin/src/core/utility.cpp index 64783d070f..d2e3459d18 100644 --- a/Marlin/src/core/utility.cpp +++ b/Marlin/src/core/utility.cpp @@ -139,17 +139,17 @@ void safe_delay(millis_t ms) { #endif #if HAS_ABL_OR_UBL - SERIAL_ECHOLNPGM("Auto Bed Leveling: " - #if ENABLED(AUTO_BED_LEVELING_LINEAR) - "LINEAR" - #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) - "BILINEAR" - #elif ENABLED(AUTO_BED_LEVELING_3POINT) - "3POINT" - #elif ENABLED(AUTO_BED_LEVELING_UBL) - "UBL" - #endif - ); + SERIAL_ECHOPGM("Auto Bed Leveling: "); + #if ENABLED(AUTO_BED_LEVELING_LINEAR) + SERIAL_ECHOLNPGM("LINEAR"); + #elif ENABLED(AUTO_BED_LEVELING_BILINEAR) + SERIAL_ECHOLNPGM("BILINEAR"); + #elif ENABLED(AUTO_BED_LEVELING_3POINT) + SERIAL_ECHOLNPGM("3POINT"); + #elif ENABLED(AUTO_BED_LEVELING_UBL) + SERIAL_ECHOLNPGM("UBL"); + #endif + if (planner.leveling_active) { SERIAL_ECHOLNPGM(" (enabled)"); #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) @@ -160,7 +160,7 @@ void safe_delay(millis_t ms) { SERIAL_ECHOPGM("ABL Adjustment X"); LOOP_XYZ(a) { float v = planner.get_axis_position_mm(AxisEnum(a)) - current_position[a]; - SERIAL_CHAR(' ', 'X' + char(a)); + SERIAL_CHAR(' ', XYZ_CHAR(a)); if (v > 0) SERIAL_CHAR('+'); SERIAL_ECHO(v); } diff --git a/Marlin/src/gcode/calibrate/M425.cpp b/Marlin/src/gcode/calibrate/M425.cpp index a54c7cf746..41c80daf7c 100644 --- a/Marlin/src/gcode/calibrate/M425.cpp +++ b/Marlin/src/gcode/calibrate/M425.cpp @@ -47,7 +47,7 @@ void GcodeSuite::M425() { bool noArgs = true; LOOP_XYZ(a) { - if (parser.seen(axis_codes[a])) { + if (parser.seen(XYZ_CHAR(a))) { planner.synchronize(); backlash.distance_mm[a] = parser.has_value() ? parser.value_linear_units() : backlash.get_measurement(AxisEnum(a)); noArgs = false; @@ -75,7 +75,7 @@ void GcodeSuite::M425() { SERIAL_ECHOLNPAIR(" Correction Amount/Fade-out: F", backlash.get_correction(), " (F1.0 = full, F0.0 = none)"); SERIAL_ECHOPGM(" Backlash Distance (mm): "); LOOP_XYZ(a) { - SERIAL_CHAR(' ', axis_codes[a]); + SERIAL_CHAR(' ', XYZ_CHAR(a)); SERIAL_ECHO(backlash.distance_mm[a]); SERIAL_EOL(); } @@ -88,7 +88,7 @@ void GcodeSuite::M425() { SERIAL_ECHOPGM(" Average measured backlash (mm):"); if (backlash.has_any_measurement()) { LOOP_XYZ(a) if (backlash.has_measurement(AxisEnum(a))) { - SERIAL_CHAR(' ', axis_codes[a]); + SERIAL_CHAR(' ', XYZ_CHAR(a)); SERIAL_ECHO(backlash.get_measurement(AxisEnum(a))); } } diff --git a/Marlin/src/gcode/calibrate/M666.cpp b/Marlin/src/gcode/calibrate/M666.cpp index 094b32708b..721cbcfaa0 100644 --- a/Marlin/src/gcode/calibrate/M666.cpp +++ b/Marlin/src/gcode/calibrate/M666.cpp @@ -40,10 +40,10 @@ void GcodeSuite::M666() { if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM(">>> M666"); LOOP_XYZ(i) { - if (parser.seen(axis_codes[i])) { + if (parser.seen(XYZ_CHAR(i))) { 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[", axis_codes[i], "] = ", delta_endstop_adj[i]); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("delta_endstop_adj[", XYZ_CHAR(i), "] = ", delta_endstop_adj[i]); } } if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("<<< M666"); diff --git a/Marlin/src/gcode/control/M605.cpp b/Marlin/src/gcode/control/M605.cpp index 99bab4ddc9..ab5efbbb48 100644 --- a/Marlin/src/gcode/control/M605.cpp +++ b/Marlin/src/gcode/control/M605.cpp @@ -138,7 +138,7 @@ HOTEND_LOOP() { DEBUG_ECHOPAIR_P(SP_T_STR, int(e)); - LOOP_XYZ(a) DEBUG_ECHOPAIR(" hotend_offset[", int(e), "].", axis_codes[a] | 0x20, "=", hotend_offset[e][a]); + LOOP_XYZ(a) DEBUG_ECHOPAIR(" hotend_offset[", int(e), "].", XYZ_CHAR(a) | 0x20, "=", hotend_offset[e][a]); DEBUG_EOL(); } DEBUG_EOL(); diff --git a/Marlin/src/gcode/feature/pause/G61.cpp b/Marlin/src/gcode/feature/pause/G61.cpp index e6e5180192..2ec2f85fe5 100644 --- a/Marlin/src/gcode/feature/pause/G61.cpp +++ b/Marlin/src/gcode/feature/pause/G61.cpp @@ -56,10 +56,10 @@ void GcodeSuite::G61(void) { SERIAL_ECHOPAIR(STR_RESTORING_POS " S", int(slot)); LOOP_XYZ(i) { - destination[i] = parser.seen(axis_codes[i]) + destination[i] = parser.seen(XYZ_CHAR(i)) ? stored_position[slot][i] + parser.value_axis_units((AxisEnum)i) : current_position[i]; - SERIAL_CHAR(' ', axis_codes[i]); + SERIAL_CHAR(' ', XYZ_CHAR(i)); SERIAL_ECHO_F(destination[i]); } SERIAL_EOL(); diff --git a/Marlin/src/gcode/feature/trinamic/M911-M914.cpp b/Marlin/src/gcode/feature/trinamic/M911-M914.cpp index 505ac14d87..4629bccab0 100644 --- a/Marlin/src/gcode/feature/trinamic/M911-M914.cpp +++ b/Marlin/src/gcode/feature/trinamic/M911-M914.cpp @@ -348,7 +348,7 @@ bool report = true; const uint8_t index = parser.byteval('I'); - LOOP_XYZ(i) if (parser.seen(axis_codes[i])) { + LOOP_XYZ(i) if (parser.seen(XYZ_CHAR(i))) { const int16_t value = parser.value_int(); report = false; switch (i) { diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 0d2b656dd6..f6b8e6f59b 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -135,7 +135,7 @@ void GcodeSuite::get_destination_from_command() { // Get new XYZ position, whether absolute or relative LOOP_XYZ(i) { - if ( (seen[i] = parser.seenval(axis_codes[i])) ) { + if ( (seen[i] = parser.seenval(XYZ_CHAR(i))) ) { const float v = parser.value_axis_units((AxisEnum)i); if (skip_move) destination[i] = current_position[i]; diff --git a/Marlin/src/gcode/geometry/M206_M428.cpp b/Marlin/src/gcode/geometry/M206_M428.cpp index e4cac5174b..13e82a0c73 100644 --- a/Marlin/src/gcode/geometry/M206_M428.cpp +++ b/Marlin/src/gcode/geometry/M206_M428.cpp @@ -38,7 +38,7 @@ */ void GcodeSuite::M206() { LOOP_XYZ(i) - if (parser.seen(axis_codes[i])) + if (parser.seen(XYZ_CHAR(i))) set_home_offset((AxisEnum)i, parser.value_linear_units()); #if ENABLED(MORGAN_SCARA) diff --git a/Marlin/src/gcode/host/M114.cpp b/Marlin/src/gcode/host/M114.cpp index acdd925301..fc67f762d2 100644 --- a/Marlin/src/gcode/host/M114.cpp +++ b/Marlin/src/gcode/host/M114.cpp @@ -45,8 +45,8 @@ void report_xyz(const xyz_pos_t &pos, const uint8_t precision=3) { char str[12]; - for (uint8_t a = X_AXIS; a <= Z_AXIS; a++) { - SERIAL_CHAR(' ', axis_codes[a], ':'); + LOOP_XYZ(a) { + SERIAL_CHAR(' ', XYZ_CHAR(a), ':'); SERIAL_ECHO(dtostrf(pos[a], 1, precision, str)); } SERIAL_EOL(); diff --git a/Marlin/src/gcode/motion/M290.cpp b/Marlin/src/gcode/motion/M290.cpp index 4f6489d3b9..5fef948fa4 100644 --- a/Marlin/src/gcode/motion/M290.cpp +++ b/Marlin/src/gcode/motion/M290.cpp @@ -76,8 +76,8 @@ */ void GcodeSuite::M290() { #if ENABLED(BABYSTEP_XY) - for (uint8_t a = X_AXIS; a <= Z_AXIS; a++) - if (parser.seenval(axis_codes[a]) || (a == Z_AXIS && parser.seenval('S'))) { + LOOP_XYZ(a) + if (parser.seenval(XYZ_CHAR(a)) || (a == Z_AXIS && parser.seenval('S'))) { const float offs = constrain(parser.value_axis_units((AxisEnum)a), -2, 2); babystep.add_mm((AxisEnum)a, offs); #if ENABLED(BABYSTEP_ZPROBE_OFFSET) diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 9f6cbf1b38..8bad4473c5 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -587,7 +587,7 @@ void restore_feedrate_and_scaling() { #endif if (DEBUGGING(LEVELING)) - SERIAL_ECHOLNPAIR("Axis ", axis_codes[axis], " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]); + SERIAL_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " min:", soft_endstop.min[axis], " max:", soft_endstop.max[axis]); } /** @@ -1779,7 +1779,7 @@ void homeaxis(const AxisEnum axis) { #if HAS_WORKSPACE_OFFSET void update_workspace_offset(const AxisEnum axis) { workspace_offset[axis] = home_offset[axis] + position_shift[axis]; - if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Axis ", axis_codes[axis], " home_offset = ", home_offset[axis], " position_shift = ", position_shift[axis]); + if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPAIR("Axis ", XYZ_CHAR(axis), " home_offset = ", home_offset[axis], " position_shift = ", position_shift[axis]); } #endif