From 35ecb8ab4a492476502919c05c06c8069f185fa8 Mon Sep 17 00:00:00 2001 From: Noisyfox Date: Tue, 24 Dec 2024 21:35:28 +0800 Subject: [PATCH] Fan mover: Ignore non-part cooling fans (SoftFever/OrcaSlicer#7171) (#7193) * Fan mover: Ignore non-part cooling fans (SoftFever/OrcaSlicer#7171) * Update comment --- src/libslic3r/GCode/FanMover.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/FanMover.cpp b/src/libslic3r/GCode/FanMover.cpp index 762d251b5..b21711b5a 100644 --- a/src/libslic3r/GCode/FanMover.cpp +++ b/src/libslic3r/GCode/FanMover.cpp @@ -50,7 +50,11 @@ float get_axis_value(const std::string& line, char axis) char match[3] = " X"; match[1] = axis; - size_t pos = line.find(match) + 2; + size_t pos = line.find(match); + if (pos == std::string::npos) { + return NAN; + } + pos += 2; //size_t end = std::min(line.find(' ', pos + 1), line.find(';', pos + 1)); // Try to parse the numeric value. const char* c = line.c_str(); @@ -83,6 +87,15 @@ int16_t get_fan_speed(const std::string &line, GCodeFlavor flavor) { if (flavor == (gcfMach3) || flavor == (gcfMachinekit)) { return (int16_t)get_axis_value(line, 'P'); } else { + // Bambu machines use both M106 P1(not P0!) and M106 for part cooling fan. + // Non-bambu machines usually use M106 (without P parameter) for part cooling fan. + // P2 is reserved for auxiliary fan regardless of bambu or not. + // To keep compatibility with Bambu machines, we accept M106 and M106 P1 as the only two valid form + // of gcode that control the part cooling fan. Any other command will be ignored! + const auto idx = get_axis_value(line, 'P'); + if (!isnan(idx) && idx != 1.0f) { + return -1; + } return (int16_t)get_axis_value(line, 'S'); } } else if (line.compare(0, 4, "M127") == 0 || line.compare(0, 4, "M107") == 0) {