From d1c9517903da3e7ab84e34ffb2c23d0772f2ce8c Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 24 Aug 2018 21:26:29 -0500 Subject: [PATCH] Followup to hotend_offset[Z] patch --- Marlin/src/gcode/config/M218.cpp | 23 +++++++++------------- Marlin/src/gcode/feature/pause/M125.cpp | 2 +- Marlin/src/gcode/feature/pause/M600.cpp | 2 +- Marlin/src/inc/Conditionals_LCD.h | 2 ++ Marlin/src/inc/Conditionals_post.h | 5 ++--- Marlin/src/module/configuration_store.cpp | 24 +++++++---------------- Marlin/src/module/delta.cpp | 2 +- Marlin/src/module/motion.cpp | 2 +- Marlin/src/module/motion.h | 2 +- 9 files changed, 25 insertions(+), 39 deletions(-) diff --git a/Marlin/src/gcode/config/M218.cpp b/Marlin/src/gcode/config/M218.cpp index 47910e0745..6b291b5488 100644 --- a/Marlin/src/gcode/config/M218.cpp +++ b/Marlin/src/gcode/config/M218.cpp @@ -22,7 +22,7 @@ #include "../../inc/MarlinConfig.h" -#if HOTENDS > 1 +#if HAS_HOTEND_OFFSET #include "../gcode.h" #include "../../module/motion.h" @@ -37,7 +37,7 @@ * T * X * Y - * Z - Available with DUAL_X_CARRIAGE, SWITCHING_NOZZLE and PARKING_EXTRUDER + * Z */ void GcodeSuite::M218() { if (get_target_extruder_from_command() || target_extruder == 0) return; @@ -51,13 +51,10 @@ void GcodeSuite::M218() { hotend_offset[Y_AXIS][target_extruder] = parser.value_linear_units(); report = false; } - - #if HAS_HOTEND_OFFSET_Z - if (parser.seenval('Z')) { - hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units(); - report = false; - } - #endif + if (parser.seenval('Z')) { + hotend_offset[Z_AXIS][target_extruder] = parser.value_linear_units(); + report = false; + } if (report) { SERIAL_ECHO_START(); @@ -67,10 +64,8 @@ void GcodeSuite::M218() { SERIAL_ECHO(hotend_offset[X_AXIS][e]); SERIAL_CHAR(','); SERIAL_ECHO(hotend_offset[Y_AXIS][e]); - #if HAS_HOTEND_OFFSET_Z - SERIAL_CHAR(','); - SERIAL_ECHO(hotend_offset[Z_AXIS][e]); - #endif + SERIAL_CHAR(','); + SERIAL_ECHO(hotend_offset[Z_AXIS][e]); } SERIAL_EOL(); } @@ -81,4 +76,4 @@ void GcodeSuite::M218() { #endif } -#endif // HOTENDS > 1 +#endif // HAS_HOTEND_OFFSET diff --git a/Marlin/src/gcode/feature/pause/M125.cpp b/Marlin/src/gcode/feature/pause/M125.cpp index fbba475f2a..7143392465 100644 --- a/Marlin/src/gcode/feature/pause/M125.cpp +++ b/Marlin/src/gcode/feature/pause/M125.cpp @@ -65,7 +65,7 @@ void GcodeSuite::M125() { // Lift Z axis if (parser.seenval('Z')) park_point.z = parser.linearval('Z'); - #if HOTENDS > 1 && DISABLED(DUAL_X_CARRIAGE) && DISABLED(DELTA) + #if HAS_HOTEND_OFFSET && DISABLED(DUAL_X_CARRIAGE) && DISABLED(DELTA) park_point.x += (active_extruder ? hotend_offset[X_AXIS][active_extruder] : 0); park_point.y += (active_extruder ? hotend_offset[Y_AXIS][active_extruder] : 0); #endif diff --git a/Marlin/src/gcode/feature/pause/M600.cpp b/Marlin/src/gcode/feature/pause/M600.cpp index be03c736c9..42ed74dbe1 100644 --- a/Marlin/src/gcode/feature/pause/M600.cpp +++ b/Marlin/src/gcode/feature/pause/M600.cpp @@ -87,7 +87,7 @@ void GcodeSuite::M600() { if (parser.seenval('X')) park_point.x = parser.linearval('X'); if (parser.seenval('Y')) park_point.y = parser.linearval('Y'); - #if HOTENDS > 1 && DISABLED(DUAL_X_CARRIAGE) && DISABLED(DELTA) + #if HAS_HOTEND_OFFSET && DISABLED(DUAL_X_CARRIAGE) && DISABLED(DELTA) park_point.x += (active_extruder ? hotend_offset[X_AXIS][active_extruder] : 0); park_point.y += (active_extruder ? hotend_offset[Y_AXIS][active_extruder] : 0); #endif diff --git a/Marlin/src/inc/Conditionals_LCD.h b/Marlin/src/inc/Conditionals_LCD.h index 608225ca4f..0869faa8e2 100644 --- a/Marlin/src/inc/Conditionals_LCD.h +++ b/Marlin/src/inc/Conditionals_LCD.h @@ -458,6 +458,8 @@ #define DO_SWITCH_EXTRUDER (ENABLED(SWITCHING_EXTRUDER) && (DISABLED(SWITCHING_NOZZLE) || SWITCHING_EXTRUDER_SERVO_NR != SWITCHING_NOZZLE_SERVO_NR)) +#define HAS_HOTEND_OFFSET (HOTENDS > 1) + /** * DISTINCT_E_FACTORS affects how some E factors are accessed */ diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 6cca5426df..f6345f3ecc 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -413,7 +413,6 @@ /** * Default hotend offsets, if not defined */ -#define HAS_HOTEND_OFFSET_Z (HOTENDS > 1 && (ENABLED(DUAL_X_CARRIAGE) || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER))) #if HOTENDS > 1 #ifndef HOTEND_OFFSET_X #define HOTEND_OFFSET_X { 0 } // X offsets for each extruder @@ -421,8 +420,8 @@ #ifndef HOTEND_OFFSET_Y #define HOTEND_OFFSET_Y { 0 } // Y offsets for each extruder #endif - #if HAS_HOTEND_OFFSET_Z && !defined(HOTEND_OFFSET_Z) - #define HOTEND_OFFSET_Z { 0 } + #ifndef HOTEND_OFFSET_Z + #define HOTEND_OFFSET_Z { 0 } // Z offsets for each extruder #endif #endif diff --git a/Marlin/src/module/configuration_store.cpp b/Marlin/src/module/configuration_store.cpp index 092934a66e..83cb3b4c46 100644 --- a/Marlin/src/module/configuration_store.cpp +++ b/Marlin/src/module/configuration_store.cpp @@ -126,7 +126,7 @@ typedef struct SettingsDataStruct { float home_offset[XYZ]; // M206 XYZ - #if HOTENDS > 1 + #if HAS_HOTEND_OFFSET float hotend_offset[XYZ][HOTENDS - 1]; // M218 XYZ #endif @@ -433,7 +433,7 @@ void MarlinSettings::postprocess() { #endif EEPROM_WRITE(home_offset); - #if HOTENDS > 1 + #if HAS_HOTEND_OFFSET // Skip hotend 0 which must be 0 for (uint8_t e = 1; e < HOTENDS; e++) LOOP_XYZ(i) EEPROM_WRITE(hotend_offset[i][e]); @@ -1038,7 +1038,7 @@ void MarlinSettings::postprocess() { // Hotend Offsets, if any // - #if HOTENDS > 1 + #if HAS_HOTEND_OFFSET // Skip hotend 0 which must be 0 for (uint8_t e = 1; e < HOTENDS; e++) LOOP_XYZ(i) EEPROM_READ(hotend_offset[i][e]); @@ -1749,16 +1749,8 @@ void MarlinSettings::reset(PORTARG_SOLO) { ZERO(home_offset); #endif - #if HOTENDS > 1 - constexpr float tmp4[XYZ][HOTENDS] = { - HOTEND_OFFSET_X, - HOTEND_OFFSET_Y - #ifdef HOTEND_OFFSET_Z - , HOTEND_OFFSET_Z - #else - , { 0 } - #endif - }; + #if HAS_HOTEND_OFFSET + constexpr float tmp4[XYZ][HOTENDS] = { HOTEND_OFFSET_X, HOTEND_OFFSET_Y, HOTEND_OFFSET_Z }; static_assert( tmp4[X_AXIS][0] == 0 && tmp4[Y_AXIS][0] == 0 && tmp4[Z_AXIS][0] == 0, "Offsets for the first hotend must be 0.0." @@ -2163,7 +2155,7 @@ void MarlinSettings::reset(PORTARG_SOLO) { SERIAL_ECHOLNPAIR_P(port, " Z", LINEAR_UNIT(home_offset[Z_AXIS])); #endif - #if HOTENDS > 1 + #if HAS_HOTEND_OFFSET if (!forReplay) { CONFIG_ECHO_START; SERIAL_ECHOLNPGM_P(port, "Hotend offsets:"); @@ -2173,9 +2165,7 @@ void MarlinSettings::reset(PORTARG_SOLO) { SERIAL_ECHOPAIR_P(port, " M218 T", (int)e); SERIAL_ECHOPAIR_P(port, " X", LINEAR_UNIT(hotend_offset[X_AXIS][e])); SERIAL_ECHOPAIR_P(port, " Y", LINEAR_UNIT(hotend_offset[Y_AXIS][e])); - #if HAS_HOTEND_OFFSET_Z - SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(hotend_offset[Z_AXIS][e])); - #endif + SERIAL_ECHOPAIR_P(port, " Z", LINEAR_UNIT(hotend_offset[Z_AXIS][e])); SERIAL_EOL_P(port); } #endif diff --git a/Marlin/src/module/delta.cpp b/Marlin/src/module/delta.cpp index 308eed106f..ba4c018f93 100644 --- a/Marlin/src/module/delta.cpp +++ b/Marlin/src/module/delta.cpp @@ -102,7 +102,7 @@ void recalc_delta_settings() { }while(0) void inverse_kinematics(const float raw[XYZ]) { - #if HOTENDS > 1 + #if HAS_HOTEND_OFFSET // Delta hotend offsets must be applied in Cartesian space with no "spoofing" const float pos[XYZ] = { raw[X_AXIS] - hotend_offset[X_AXIS][active_extruder], diff --git a/Marlin/src/module/motion.cpp b/Marlin/src/module/motion.cpp index 864d04609b..fbc2111172 100644 --- a/Marlin/src/module/motion.cpp +++ b/Marlin/src/module/motion.cpp @@ -92,7 +92,7 @@ float destination[XYZE] = { 0 }; uint8_t active_extruder; // = 0; // Extruder offsets -#if HOTENDS > 1 +#if HAS_HOTEND_OFFSET float hotend_offset[XYZ][HOTENDS]; // Initialized by settings.load() #endif diff --git a/Marlin/src/module/motion.h b/Marlin/src/module/motion.h index 6850250b6a..51e0478928 100644 --- a/Marlin/src/module/motion.h +++ b/Marlin/src/module/motion.h @@ -78,7 +78,7 @@ extern int16_t feedrate_percentage; extern uint8_t active_extruder; -#if HOTENDS > 1 +#if HAS_HOTEND_OFFSET extern float hotend_offset[XYZ][HOTENDS]; #endif