Skip to content

Commit

Permalink
🩹 No PE_MAGNET_ON_STATE without PARKING_EXTRUDER
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 23, 2022
1 parent ef07c2c commit d3e3e6a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
18 changes: 6 additions & 12 deletions Marlin/src/feature/solenoid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,11 @@
#include "solenoid.h"

#include "../module/motion.h" // for active_extruder

// PARKING_EXTRUDER options alter the default behavior of solenoids, this ensures compliance of M380-381

#if ENABLED(PARKING_EXTRUDER)
#include "../module/tool_change.h"
#endif
#include "../module/tool_change.h"

// Used primarily with MANUAL_SOLENOID_CONTROL
static void set_solenoid(const uint8_t num, const bool active) {
const uint8_t value = active ? PE_MAGNET_ON_STATE : !PE_MAGNET_ON_STATE;
#define _SOL_CASE(N) case N: TERN_(HAS_SOLENOID_##N, OUT_WRITE(SOL##N##_PIN, value)); break;
static void set_solenoid(const uint8_t num, const uint8_t state) {
#define _SOL_CASE(N) case N: TERN_(HAS_SOLENOID_##N, OUT_WRITE(SOL##N##_PIN, state)); break;
switch (num) {
REPEAT(8, _SOL_CASE)
default: SERIAL_ECHO_MSG(STR_INVALID_SOLENOID); break;
Expand All @@ -49,9 +43,9 @@ static void set_solenoid(const uint8_t num, const bool active) {
#endif
}

void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
void enable_solenoid_on_active_extruder() { }
// PARKING_EXTRUDER options alter the default behavior of solenoids to ensure compliance of M380-381
void enable_solenoid(const uint8_t num) { set_solenoid(num, TERN1(PARKING_EXTRUDER, PE_MAGNET_ON_STATE)); }
void disable_solenoid(const uint8_t num) { set_solenoid(num, TERN0(PARKING_EXTRUDER, !PE_MAGNET_ON_STATE)); }

void disable_all_solenoids() {
#define _SOL_DISABLE(N) TERN_(HAS_SOLENOID_##N, disable_solenoid(N));
Expand Down
1 change: 0 additions & 1 deletion Marlin/src/feature/solenoid.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
*/
#pragma once

void enable_solenoid_on_active_extruder();
void disable_all_solenoids();
void enable_solenoid(const uint8_t num);
void disable_solenoid(const uint8_t num);
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/M380_M381.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void GcodeSuite::M380() {
#if ENABLED(MANUAL_SOLENOID_CONTROL)
enable_solenoid(parser.intval('S', active_extruder));
#else
enable_solenoid_on_active_extruder();
enable_solenoid(active_extruder);
#endif
}

Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/gcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@
* M350 - Set microstepping mode. (Requires digital microstepping pins.)
* M351 - Toggle MS1 MS2 pins directly. (Requires digital microstepping pins.)
* M355 - Set Case Light on/off and set brightness. (Requires CASE_LIGHT_PIN)
* M380 - Activate solenoid on active extruder. (Requires EXT_SOLENOID)
* M381 - Disable all solenoids. (Requires EXT_SOLENOID)
* M380 - Activate solenoid on active tool (Requires EXT_SOLENOID) or the tool specified by 'S' (Requires MANUAL_SOLENOID_CONTROL).
* M381 - Disable solenoids on all tools (Requires EXT_SOLENOID) or the tool specified by 'S' (Requires MANUAL_SOLENOID_CONTROL).
* M400 - Finish all moves.
* M401 - Deploy and activate Z probe. (Requires a probe)
* M402 - Deactivate and stow Z probe. (Requires a probe)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/module/tool_change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,7 @@ void tool_change(const uint8_t new_tool, bool no_move/*=false*/) {

#if ENABLED(EXT_SOLENOID) && DISABLED(PARKING_EXTRUDER)
disable_all_solenoids();
enable_solenoid_on_active_extruder();
enable_solenoid(active_extruder);
#endif

#if HAS_PRUSA_MMU1
Expand Down

0 comments on commit d3e3e6a

Please sign in to comment.