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
 #if FAN_COUNT > 0
25
 #if FAN_COUNT > 0
26
 
26
 
27
 #include "../gcode.h"
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
 #if ENABLED(SINGLENOZZLE)
32
 #if ENABLED(SINGLENOZZLE)
31
-  #include "../../module/motion.h"
32
   #include "../../module/tool_change.h"
33
   #include "../../module/tool_change.h"
33
 #endif
34
 #endif
34
 
35
 
46
  *           3-255 = Set the speed for use with T2
47
  *           3-255 = Set the speed for use with T2
47
  */
48
  */
48
 void GcodeSuite::M106() {
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
     #if ENABLED(EXTRA_FAN_SPEED)
66
     #if ENABLED(EXTRA_FAN_SPEED)
61
       const int16_t t = parser.intval('T');
67
       const int16_t t = parser.intval('T');
62
       if (t > 0) {
68
       if (t > 0) {
63
         switch (t) {
69
         switch (t) {
64
           case 1:
70
           case 1:
65
-            fan_speed[p] = old_fan_speed[p];
71
+            fan_speed[np] = old_fan_speed[np];
66
             break;
72
             break;
67
           case 2:
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
             break;
76
             break;
71
           default:
77
           default:
72
-            new_fan_speed[p] = MIN(t, 255U);
78
+            new_fan_speed[np] = MIN(t, 255U);
73
             break;
79
             break;
74
         }
80
         }
75
         return;
81
         return;
76
       }
82
       }
77
     #endif // EXTRA_FAN_SPEED
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
  * M107: Fan Off
90
  * M107: Fan Off
84
  */
91
  */
85
 void GcodeSuite::M107() {
92
 void GcodeSuite::M107() {
86
-  const uint16_t p = parser.ushortval('P');
93
+  const uint16_t p = parser.byteval('P', active_extruder);
94
+
87
   #if ENABLED(SINGLENOZZLE)
95
   #if ENABLED(SINGLENOZZLE)
88
     if (p != active_extruder) {
96
     if (p != active_extruder) {
89
       if (p < EXTRUDERS) singlenozzle_fan_speed[p] = 0;
97
       if (p < EXTRUDERS) singlenozzle_fan_speed[p] = 0;
91
     }
99
     }
92
   #endif
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
 #endif // FAN_COUNT > 0
105
 #endif // FAN_COUNT > 0

Loading…
Cancel
Save