From 3a99d001ff87e33533af324f28d50977eec1c1b7 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 4 Jan 2021 19:01:45 -0600 Subject: [PATCH] Solenoid cleanups Followups to #20473 ahead of #20675 --- Marlin/src/feature/solenoid.cpp | 37 ++++++++----------------------- Marlin/src/module/tool_change.cpp | 6 +---- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/Marlin/src/feature/solenoid.cpp b/Marlin/src/feature/solenoid.cpp index 659b642262..97a74c6d19 100644 --- a/Marlin/src/feature/solenoid.cpp +++ b/Marlin/src/feature/solenoid.cpp @@ -32,50 +32,31 @@ #if ENABLED(PARKING_EXTRUDER) #include "../module/tool_change.h" - #define SOLENOID_MAGNETIZED_STATE (TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT,!)PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE) -#else - #define SOLENOID_MAGNETIZED_STATE HIGH #endif -#define HAS_SOLENOID(N) (HAS_SOLENOID_##N && TERN(MANUAL_SOLENOID_CONTROL, true, EXTRUDERS > N)) +#define HAS_SOLENOID(N) (HAS_SOLENOID_##N && (ENABLED(MANUAL_SOLENOID_CONTROL) || N < EXTRUDERS)) // Used primarily with MANUAL_SOLENOID_CONTROL static void set_solenoid(const uint8_t num, const bool active) { - const uint8_t value = active ? SOLENOID_MAGNETIZED_STATE : !SOLENOID_MAGNETIZED_STATE; + const uint8_t value = active ? PE_MAGNET_ON_STATE : !PE_MAGNET_ON_STATE; switch (num) { - case 0: - OUT_WRITE(SOL0_PIN, value); - TERN_(PARKING_EXTRUDER, if (!active && active_extruder == 0) parking_extruder_set_parked()); // If active extruder's solenoid is disabled, carriage is considered parked - break; + case 0: OUT_WRITE(SOL0_PIN, value); break; #if HAS_SOLENOID(1) - case 1: - OUT_WRITE(SOL1_PIN, value); - TERN_(PARKING_EXTRUDER, if (!active && active_extruder == 1) parking_extruder_set_parked()); // If active extruder's solenoid is disabled, carriage is considered parked - break; + case 1: OUT_WRITE(SOL1_PIN, value); break; #endif #if HAS_SOLENOID(2) - case 2: - OUT_WRITE(SOL2_PIN, value); - break; + case 2: OUT_WRITE(SOL2_PIN, value); break; #endif #if HAS_SOLENOID(3) - case 3: - OUT_WRITE(SOL3_PIN, value); - break; + case 3: OUT_WRITE(SOL3_PIN, value); break; #endif #if HAS_SOLENOID(4) - case 4: - OUT_WRITE(SOL4_PIN, value); - break; + case 4: OUT_WRITE(SOL4_PIN, value); break; #endif #if HAS_SOLENOID(5) - case 5: - OUT_WRITE(SOL5_PIN, value); - break; + case 5: OUT_WRITE(SOL5_PIN, value); break; #endif - default: - SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); - break; + default: SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); break; } } diff --git a/Marlin/src/module/tool_change.cpp b/Marlin/src/module/tool_change.cpp index a310442126..7e78b5fec3 100644 --- a/Marlin/src/module/tool_change.cpp +++ b/Marlin/src/module/tool_change.cpp @@ -260,11 +260,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a void pe_solenoid_init() { LOOP_LE_N(n, 1) - #if ENABLED(PARKING_EXTRUDER_SOLENOIDS_INVERT) - pe_activate_solenoid(n); - #else - pe_deactivate_solenoid(n); - #endif + TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid, pe_deactivate_solenoid)(n); } void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state) {