From 4f2473053c40ec02d1635c5dab1785e9e9073166 Mon Sep 17 00:00:00 2001 From: InsanityAutomation <38436470+InsanityAutomation@users.noreply.github.com> Date: Mon, 31 Dec 2018 21:10:18 -0500 Subject: [PATCH] Fix M106 with SINGLENOZZLE --- Marlin/src/gcode/temperature/M106_M107.cpp | 44 +++++++++++++--------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/Marlin/src/gcode/temperature/M106_M107.cpp b/Marlin/src/gcode/temperature/M106_M107.cpp index 12e2dc4f26..741901c32a 100644 --- a/Marlin/src/gcode/temperature/M106_M107.cpp +++ b/Marlin/src/gcode/temperature/M106_M107.cpp @@ -25,10 +25,11 @@ #if FAN_COUNT > 0 #include "../gcode.h" -#include "../../Marlin.h" // for fan_speed — should move those to Planner +#include "../../Marlin.h" // for fan_speed + +#include "../../module/motion.h" #if ENABLED(SINGLENOZZLE) - #include "../../module/motion.h" #include "../../module/tool_change.h" #endif @@ -46,36 +47,42 @@ * 3-255 = Set the speed for use with T2 */ void GcodeSuite::M106() { - const uint8_t p = parser.byteval('P'); - const uint16_t s = parser.ushortval('S', 255); + const uint8_t p = parser.byteval('P', active_extruder); - #if ENABLED(SINGLENOZZLE) - if (p != active_extruder) { - if (p < EXTRUDERS) singlenozzle_fan_speed[p] = MIN(s, 255U); - return; - } - #endif + if (p < MIN(EXTRUDERS, FAN_COUNT)) { + uint16_t s = parser.ushortval('S', 255); + NOMORE(s, 255); + + uint8_t np = p; + + #if ENABLED(SINGLENOZZLE) + if (p != active_extruder) { + if (p < EXTRUDERS) singlenozzle_fan_speed[p] = s; + return; + } + np = 0; // Always use fan index 0 with SINGLENOZZLE + #endif - if (p < FAN_COUNT) { #if ENABLED(EXTRA_FAN_SPEED) const int16_t t = parser.intval('T'); if (t > 0) { switch (t) { case 1: - fan_speed[p] = old_fan_speed[p]; + fan_speed[np] = old_fan_speed[np]; break; case 2: - old_fan_speed[p] = fan_speed[p]; - fan_speed[p] = new_fan_speed[p]; + old_fan_speed[np] = fan_speed[np]; + fan_speed[np] = new_fan_speed[np]; break; default: - new_fan_speed[p] = MIN(t, 255U); + new_fan_speed[np] = MIN(t, 255U); break; } return; } #endif // EXTRA_FAN_SPEED - fan_speed[p] = MIN(s, 255U); + + fan_speed[np] = s; } } @@ -83,7 +90,8 @@ void GcodeSuite::M106() { * M107: Fan Off */ void GcodeSuite::M107() { - const uint16_t p = parser.ushortval('P'); + const uint16_t p = parser.byteval('P', active_extruder); + #if ENABLED(SINGLENOZZLE) if (p != active_extruder) { if (p < EXTRUDERS) singlenozzle_fan_speed[p] = 0; @@ -91,7 +99,7 @@ void GcodeSuite::M107() { } #endif - if (p < FAN_COUNT) fan_speed[p] = 0; + if (p < MIN(EXTRUDERS, FAN_COUNT)) fan_speed[p] = 0; } #endif // FAN_COUNT > 0