Solenoid cleanups

Followups to #20473 ahead of #20675
This commit is contained in:
Scott Lahteine 2021-01-04 19:01:45 -06:00
parent 7033003c36
commit 3a99d001ff
2 changed files with 10 additions and 33 deletions

View File

@ -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;
}
}

View File

@ -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) {