Clarify solenoid active / magnet-on state

This commit is contained in:
Scott Lahteine 2021-01-04 23:09:35 -06:00 committed by Scott Lahteine
parent ed7698efaa
commit cc1b8c2d0b
2 changed files with 17 additions and 20 deletions

View file

@ -259,11 +259,10 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
#elif ENABLED(PARKING_EXTRUDER) #elif ENABLED(PARKING_EXTRUDER)
void pe_solenoid_init() { void pe_solenoid_init() {
LOOP_LE_N(n, 1) LOOP_LE_N(n, 1) pe_solenoid_set_pin_state(n, !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE);
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) { void pe_solenoid_set_pin_state(const uint8_t extruder_num, const uint8_t state) {
switch (extruder_num) { switch (extruder_num) {
case 1: OUT_WRITE(SOL1_PIN, state); break; case 1: OUT_WRITE(SOL1_PIN, state); break;
default: OUT_WRITE(SOL0_PIN, state); break; default: OUT_WRITE(SOL0_PIN, state); break;
@ -282,11 +281,11 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
if (!extruder_parked) return false; // nothing to do if (!extruder_parked) return false; // nothing to do
if (homed_towards_final_tool) { if (homed_towards_final_tool) {
pe_deactivate_solenoid(1 - final_tool); pe_solenoid_magnet_off(1 - final_tool);
DEBUG_ECHOLNPAIR("Disengage magnet", (int)(1 - final_tool)); DEBUG_ECHOLNPAIR("Disengage magnet", (int)(1 - final_tool));
pe_activate_solenoid(final_tool); pe_solenoid_magnet_on(final_tool);
DEBUG_ECHOLNPAIR("Engage magnet", (int)final_tool); DEBUG_ECHOLNPAIR("Engage magnet", (int)final_tool);
extruder_parked = false; parking_extruder_set_parked(false);
return false; return false;
} }
@ -335,7 +334,7 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
planner.synchronize(); planner.synchronize();
DEBUG_ECHOLNPGM("(2) Disengage magnet"); DEBUG_ECHOLNPGM("(2) Disengage magnet");
pe_deactivate_solenoid(active_extruder); pe_solenoid_magnet_off(active_extruder);
// STEP 3 // STEP 3
@ -353,8 +352,8 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
DEBUG_ECHOLNPGM("(4) Engage magnetic field"); DEBUG_ECHOLNPGM("(4) Engage magnetic field");
// Just save power for inverted magnets // Just save power for inverted magnets
TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid(active_extruder)); TERN_(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_solenoid_magnet_on(active_extruder));
pe_activate_solenoid(new_tool); pe_solenoid_magnet_on(new_tool);
// STEP 5 // STEP 5
@ -382,10 +381,10 @@ inline void fast_line_to_current(const AxisEnum fr_axis) { _line_to_current(fr_a
extruder_parked = false; extruder_parked = false;
} }
else if (do_solenoid_activation) { // && nomove == true else if (do_solenoid_activation) { // && nomove == true
// Deactivate old extruder solenoid // Deactivate current extruder solenoid
TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_activate_solenoid, pe_deactivate_solenoid)(active_extruder); pe_solenoid_set_pin_state(active_extruder, !PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE);
// Only engage magnetic field for new extruder // Engage new extruder magnetic field
TERN(PARKING_EXTRUDER_SOLENOIDS_INVERT, pe_deactivate_solenoid, pe_activate_solenoid)(new_tool); pe_solenoid_set_pin_state(new_tool, PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE);
} }
do_solenoid_activation = true; // Activate solenoid for subsequent tool_change() do_solenoid_activation = true; // Activate solenoid for subsequent tool_change()
@ -1149,9 +1148,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {
// Just move back down // Just move back down
DEBUG_ECHOLNPGM("Move back Z only"); DEBUG_ECHOLNPGM("Move back Z only");
#if ENABLED(TOOLCHANGE_PARK) if (TERN1(TOOLCHANGE_PARK, toolchange_settings.enable_park))
if (toolchange_settings.enable_park)
#endif
do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]); do_blocking_move_to_z(destination.z, planner.settings.max_feedrate_mm_s[Z_AXIS]);
#else #else

View file

@ -86,10 +86,10 @@
#define PE_MAGNET_ON_STATE PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE #define PE_MAGNET_ON_STATE PARKING_EXTRUDER_SOLENOIDS_PINS_ACTIVE
#endif #endif
void pe_set_solenoid(const uint8_t extruder_num, const uint8_t state); void pe_solenoid_set_pin_state(const uint8_t extruder_num, const uint8_t state);
inline void pe_activate_solenoid(const uint8_t extruder_num) { pe_set_solenoid(extruder_num, PE_MAGNET_ON_STATE); } inline void pe_solenoid_magnet_on(const uint8_t extruder_num) { pe_solenoid_set_pin_state(extruder_num, PE_MAGNET_ON_STATE); }
inline void pe_deactivate_solenoid(const uint8_t extruder_num) { pe_set_solenoid(extruder_num, !PE_MAGNET_ON_STATE); } inline void pe_solenoid_magnet_off(const uint8_t extruder_num) { pe_solenoid_set_pin_state(extruder_num, !PE_MAGNET_ON_STATE); }
void pe_solenoid_init(); void pe_solenoid_init();