Fan mover: Ignore non-part cooling fans (SoftFever/OrcaSlicer#7171) (#7193)

* Fan mover: Ignore non-part cooling fans (SoftFever/OrcaSlicer#7171)

* Update comment
This commit is contained in:
Noisyfox 2024-12-24 21:35:28 +08:00 committed by GitHub
parent 1cf90efe03
commit 35ecb8ab4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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) {