Browse Source

Fix M106 with SINGLENOZZLE

InsanityAutomation 6 years ago
parent
commit
4f2473053c
1 changed files with 26 additions and 18 deletions
  1. 26
    18
      Marlin/src/gcode/temperature/M106_M107.cpp

+ 26
- 18
Marlin/src/gcode/temperature/M106_M107.cpp View File

@@ -25,10 +25,11 @@
25 25
 #if FAN_COUNT > 0
26 26
 
27 27
 #include "../gcode.h"
28
-#include "../../Marlin.h" // for fan_speed — should move those to Planner
28
+#include "../../Marlin.h" // for fan_speed
29
+
30
+#include "../../module/motion.h"
29 31
 
30 32
 #if ENABLED(SINGLENOZZLE)
31
-  #include "../../module/motion.h"
32 33
   #include "../../module/tool_change.h"
33 34
 #endif
34 35
 
@@ -46,36 +47,42 @@
46 47
  *           3-255 = Set the speed for use with T2
47 48
  */
48 49
 void GcodeSuite::M106() {
49
-  const uint8_t p = parser.byteval('P');
50
-  const uint16_t s = parser.ushortval('S', 255);
50
+  const uint8_t p = parser.byteval('P', active_extruder);
51 51
 
52
-  #if ENABLED(SINGLENOZZLE)
53
-    if (p != active_extruder) {
54
-      if (p < EXTRUDERS) singlenozzle_fan_speed[p] = MIN(s, 255U);
55
-      return;
56
-    }
57
-  #endif
52
+  if (p < MIN(EXTRUDERS, FAN_COUNT)) {
53
+    uint16_t s = parser.ushortval('S', 255);
54
+    NOMORE(s, 255);
55
+
56
+    uint8_t np = p;
57
+
58
+    #if ENABLED(SINGLENOZZLE)
59
+      if (p != active_extruder) {
60
+        if (p < EXTRUDERS) singlenozzle_fan_speed[p] = s;
61
+        return;
62
+      }
63
+      np = 0; // Always use fan index 0 with SINGLENOZZLE
64
+    #endif
58 65
 
59
-  if (p < FAN_COUNT) {
60 66
     #if ENABLED(EXTRA_FAN_SPEED)
61 67
       const int16_t t = parser.intval('T');
62 68
       if (t > 0) {
63 69
         switch (t) {
64 70
           case 1:
65
-            fan_speed[p] = old_fan_speed[p];
71
+            fan_speed[np] = old_fan_speed[np];
66 72
             break;
67 73
           case 2:
68
-            old_fan_speed[p] = fan_speed[p];
69
-            fan_speed[p] = new_fan_speed[p];
74
+            old_fan_speed[np] = fan_speed[np];
75
+            fan_speed[np] = new_fan_speed[np];
70 76
             break;
71 77
           default:
72
-            new_fan_speed[p] = MIN(t, 255U);
78
+            new_fan_speed[np] = MIN(t, 255U);
73 79
             break;
74 80
         }
75 81
         return;
76 82
       }
77 83
     #endif // EXTRA_FAN_SPEED
78
-    fan_speed[p] = MIN(s, 255U);
84
+
85
+    fan_speed[np] = s;
79 86
   }
80 87
 }
81 88
 
@@ -83,7 +90,8 @@ void GcodeSuite::M106() {
83 90
  * M107: Fan Off
84 91
  */
85 92
 void GcodeSuite::M107() {
86
-  const uint16_t p = parser.ushortval('P');
93
+  const uint16_t p = parser.byteval('P', active_extruder);
94
+
87 95
   #if ENABLED(SINGLENOZZLE)
88 96
     if (p != active_extruder) {
89 97
       if (p < EXTRUDERS) singlenozzle_fan_speed[p] = 0;
@@ -91,7 +99,7 @@ void GcodeSuite::M107() {
91 99
     }
92 100
   #endif
93 101
 
94
-  if (p < FAN_COUNT) fan_speed[p] = 0;
102
+  if (p < MIN(EXTRUDERS, FAN_COUNT)) fan_speed[p] = 0;
95 103
 }
96 104
 
97 105
 #endif // FAN_COUNT > 0

Loading…
Cancel
Save