Browse Source

Support individual solenoid disable with M381 (#13008)

Mark Zachmann 6 years ago
parent
commit
19cf72e057

+ 48
- 38
Marlin/src/feature/solenoid.cpp View File

28
 
28
 
29
 #include "../module/motion.h" // for active_extruder
29
 #include "../module/motion.h" // for active_extruder
30
 
30
 
31
-void enable_solenoid(const uint8_t num) {
31
+#if ENABLED(MANUAL_SOLENOID_CONTROL)
32
+  #define HAS_SOLENOID(N) HAS_SOLENOID_##N
33
+#else
34
+  #define HAS_SOLENOID(N) (HAS_SOLENOID_##N && EXTRUDERS > N)
35
+#endif
36
+
37
+// Used primarily with MANUAL_SOLENOID_CONTROL
38
+static void set_solenoid(const uint8_t num, const bool active) {
39
+  const uint8_t value = active ? HIGH : LOW;
32
   switch (num) {
40
   switch (num) {
33
     case 0:
41
     case 0:
34
-      OUT_WRITE(SOL0_PIN, HIGH);
42
+      OUT_WRITE(SOL0_PIN, value);
35
       break;
43
       break;
36
-      #if HAS_SOLENOID_1 && EXTRUDERS > 1
37
-        case 1:
38
-          OUT_WRITE(SOL1_PIN, HIGH);
39
-          break;
40
-      #endif
41
-      #if HAS_SOLENOID_2 && EXTRUDERS > 2
42
-        case 2:
43
-          OUT_WRITE(SOL2_PIN, HIGH);
44
-          break;
45
-      #endif
46
-      #if HAS_SOLENOID_3 && EXTRUDERS > 3
47
-        case 3:
48
-          OUT_WRITE(SOL3_PIN, HIGH);
49
-          break;
50
-      #endif
51
-      #if HAS_SOLENOID_4 && EXTRUDERS > 4
52
-        case 4:
53
-          OUT_WRITE(SOL4_PIN, HIGH);
54
-          break;
55
-      #endif
56
-      #if HAS_SOLENOID_5 && EXTRUDERS > 5
57
-        case 5:
58
-          OUT_WRITE(SOL5_PIN, HIGH);
59
-          break;
60
-      #endif
44
+    #if HAS_SOLENOID(1)
45
+      case 1:
46
+        OUT_WRITE(SOL1_PIN, value);
47
+        break;
48
+    #endif
49
+    #if HAS_SOLENOID(2)
50
+      case 2:
51
+        OUT_WRITE(SOL2_PIN, value);
52
+        break;
53
+    #endif
54
+    #if HAS_SOLENOID(3)
55
+      case 3:
56
+        OUT_WRITE(SOL3_PIN, value);
57
+        break;
58
+    #endif
59
+    #if HAS_SOLENOID(4)
60
+      case 4:
61
+        OUT_WRITE(SOL4_PIN, value);
62
+        break;
63
+    #endif
64
+    #if HAS_SOLENOID(5)
65
+      case 5:
66
+        OUT_WRITE(SOL5_PIN, value);
67
+        break;
68
+    #endif
61
     default:
69
     default:
62
       SERIAL_ECHO_MSG(MSG_INVALID_SOLENOID);
70
       SERIAL_ECHO_MSG(MSG_INVALID_SOLENOID);
63
       break;
71
       break;
64
   }
72
   }
65
 }
73
 }
66
 
74
 
75
+void enable_solenoid(const uint8_t num) { set_solenoid(num, true); }
76
+void disable_solenoid(const uint8_t num) { set_solenoid(num, false); }
67
 void enable_solenoid_on_active_extruder() { enable_solenoid(active_extruder); }
77
 void enable_solenoid_on_active_extruder() { enable_solenoid(active_extruder); }
68
 
78
 
69
 void disable_all_solenoids() {
79
 void disable_all_solenoids() {
70
-  OUT_WRITE(SOL0_PIN, LOW);
71
-  #if HAS_SOLENOID_1 && EXTRUDERS > 1
72
-    OUT_WRITE(SOL1_PIN, LOW);
80
+  disable_solenoid(0);
81
+  #if HAS_SOLENOID(1)
82
+    disable_solenoid(1);
73
   #endif
83
   #endif
74
-  #if HAS_SOLENOID_2 && EXTRUDERS > 2
75
-    OUT_WRITE(SOL2_PIN, LOW);
84
+  #if HAS_SOLENOID(2)
85
+    disable_solenoid(2);
76
   #endif
86
   #endif
77
-  #if HAS_SOLENOID_3 && EXTRUDERS > 3
78
-    OUT_WRITE(SOL3_PIN, LOW);
87
+  #if HAS_SOLENOID(3)
88
+    disable_solenoid(3);
79
   #endif
89
   #endif
80
-  #if HAS_SOLENOID_4 && EXTRUDERS > 4
81
-    OUT_WRITE(SOL4_PIN, LOW);
90
+  #if HAS_SOLENOID(4)
91
+    disable_solenoid(4);
82
   #endif
92
   #endif
83
-  #if HAS_SOLENOID_5 && EXTRUDERS > 5
84
-    OUT_WRITE(SOL5_PIN, LOW);
93
+  #if HAS_SOLENOID(5)
94
+    disable_solenoid(5);
85
   #endif
95
   #endif
86
 }
96
 }
87
 
97
 

+ 1
- 0
Marlin/src/feature/solenoid.h View File

24
 void enable_solenoid_on_active_extruder();
24
 void enable_solenoid_on_active_extruder();
25
 void disable_all_solenoids();
25
 void disable_all_solenoids();
26
 void enable_solenoid(const uint8_t num);
26
 void enable_solenoid(const uint8_t num);
27
+void disable_solenoid(const uint8_t num);

+ 10
- 3
Marlin/src/gcode/control/M380_M381.cpp View File

35
  */
35
  */
36
 void GcodeSuite::M380() {
36
 void GcodeSuite::M380() {
37
   #if ENABLED(MANUAL_SOLENOID_CONTROL)
37
   #if ENABLED(MANUAL_SOLENOID_CONTROL)
38
-    enable_solenoid(parser.seenval('S') ? parser.value_int() : active_extruder);
38
+    enable_solenoid(parser.intval('S', active_extruder));
39
   #else
39
   #else
40
     enable_solenoid_on_active_extruder();
40
     enable_solenoid_on_active_extruder();
41
   #endif
41
   #endif
42
 }
42
 }
43
 
43
 
44
 /**
44
 /**
45
- * M381: Disable all solenoids
45
+ * M381: Disable all solenoids if EXT_SOLENOID
46
+ *       Disable selected/active solenoid if MANUAL_SOLENOID_CONTROL
46
  */
47
  */
47
-void GcodeSuite::M381() { disable_all_solenoids(); }
48
+void GcodeSuite::M381() { 
49
+  #if ENABLED(MANUAL_SOLENOID_CONTROL)
50
+    disable_solenoid(parser.intval('S', active_extruder));
51
+  #else
52
+    disable_all_solenoids();
53
+  #endif
54
+}
48
 
55
 
49
 #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL
56
 #endif // EXT_SOLENOID || MANUAL_SOLENOID_CONTROL

+ 1
- 1
Marlin/src/gcode/gcode.cpp View File

547
 
547
 
548
       #if ENABLED(EXT_SOLENOID) || ENABLED(MANUAL_SOLENOID_CONTROL)
548
       #if ENABLED(EXT_SOLENOID) || ENABLED(MANUAL_SOLENOID_CONTROL)
549
         case 380: M380(); break;                                  // M380: Activate solenoid on active (or specified) extruder
549
         case 380: M380(); break;                                  // M380: Activate solenoid on active (or specified) extruder
550
-        case 381: M381(); break;                                  // M381: Disable all solenoids
550
+        case 381: M381(); break;                                  // M381: Disable all solenoids or, if MANUAL_SOLENOID_CONTROL, active (or specified) solenoid
551
       #endif
551
       #endif
552
 
552
 
553
       case 400: M400(); break;                                    // M400: Finish all moves
553
       case 400: M400(); break;                                    // M400: Finish all moves

Loading…
Cancel
Save