Fix set fan bug

This commit is contained in:
SoftFever 2023-08-04 18:41:45 +08:00
parent d381a5ed11
commit ce59235bd7
2 changed files with 28 additions and 15 deletions

View file

@ -4159,23 +4159,25 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
// perimeter // perimeter
int overhang_threshold = overhang_fan_threshold == Overhang_threshold_none ? Overhang_threshold_none int overhang_threshold = overhang_fan_threshold == Overhang_threshold_none ? Overhang_threshold_none
: overhang_fan_threshold - 1; : overhang_fan_threshold - 1;
if ((overhang_fan_threshold == Overhang_threshold_none && is_perimeter(path.role()) && !m_is_overhang_fan_on) || if ((overhang_fan_threshold == Overhang_threshold_none && is_perimeter(path.role())) ||
(path.get_overhang_degree() > overhang_threshold || is_bridge(path.role()))) { (path.get_overhang_degree() > overhang_threshold || is_bridge(path.role()))) {
if (!m_is_overhang_fan_on) {
gcode += ";_OVERHANG_FAN_START\n"; gcode += ";_OVERHANG_FAN_START\n";
m_is_overhang_fan_on = true; m_is_overhang_fan_on = true;
} }
else { } else {
if (m_is_overhang_fan_on) { if (m_is_overhang_fan_on) {
m_is_overhang_fan_on = false; m_is_overhang_fan_on = false;
gcode += ";_OVERHANG_FAN_END\n"; gcode += ";_OVERHANG_FAN_END\n";
} }
} }
} }
if(supp_interface_fan_speed >= 0 && path.role() == erSupportMaterialInterface && !m_is_supp_interface_fan_on) { if (supp_interface_fan_speed >= 0 && path.role() == erSupportMaterialInterface) {
if (!m_is_supp_interface_fan_on) {
gcode += ";_SUPP_INTERFACE_FAN_START\n"; gcode += ";_SUPP_INTERFACE_FAN_START\n";
m_is_supp_interface_fan_on = true; m_is_supp_interface_fan_on = true;
} }
else { } else {
if (m_is_supp_interface_fan_on) { if (m_is_supp_interface_fan_on) {
gcode += ";_SUPP_INTERFACE_FAN_END\n"; gcode += ";_SUPP_INTERFACE_FAN_END\n";
m_is_supp_interface_fan_on = false; m_is_supp_interface_fan_on = false;

View file

@ -785,6 +785,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
} }
if (fan_speed_new != m_fan_speed) { if (fan_speed_new != m_fan_speed) {
m_fan_speed = fan_speed_new; m_fan_speed = fan_speed_new;
m_current_fan_speed = fan_speed_new;
if (immediately_apply) if (immediately_apply)
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed); new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed);
} }
@ -803,7 +804,8 @@ std::string CoolingBuffer::apply_layer_cooldown(
// Reduce set fan commands by deferring the GCodeWriter::set_fan calls. Inspired by SuperSlicer // Reduce set fan commands by deferring the GCodeWriter::set_fan calls. Inspired by SuperSlicer
// define fan_speed_change_requests and initialize it with all possible types fan speed change requests // define fan_speed_change_requests and initialize it with all possible types fan speed change requests
std::unordered_map<int, bool> fan_speed_change_requests = {{CoolingLine::TYPE_OVERHANG_FAN_START, false}, std::unordered_map<int, bool> fan_speed_change_requests = {{CoolingLine::TYPE_OVERHANG_FAN_START, false},
{CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START, false}}; {CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START, false},
{CoolingLine::TYPE_FORCE_RESUME_FAN, false}};
bool need_set_fan = false; bool need_set_fan = false;
for (const CoolingLine *line : lines) { for (const CoolingLine *line : lines) {
@ -826,8 +828,8 @@ std::string CoolingBuffer::apply_layer_cooldown(
} else if (line->type & CoolingLine::TYPE_OVERHANG_FAN_END) { } else if (line->type & CoolingLine::TYPE_OVERHANG_FAN_END) {
if (overhang_fan_control && fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]) { if (overhang_fan_control && fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]) {
fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START] = false; fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START] = false;
need_set_fan = true;
} }
need_set_fan = true;
} else if (line->type & CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START) { } else if (line->type & CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START) {
if (supp_interface_fan_control && !fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) { if (supp_interface_fan_control && !fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) {
fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START] = true; fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START] = true;
@ -836,11 +838,12 @@ std::string CoolingBuffer::apply_layer_cooldown(
} else if (line->type & CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_END && fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) { } else if (line->type & CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_END && fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) {
if (supp_interface_fan_control) { if (supp_interface_fan_control) {
fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START] = false; fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START] = false;
need_set_fan = true;
} }
need_set_fan = true;
} else if (line->type & CoolingLine::TYPE_FORCE_RESUME_FAN) { } else if (line->type & CoolingLine::TYPE_FORCE_RESUME_FAN) {
// check if any fan speed change request is active // check if any fan speed change request is active
if (m_fan_speed != -1 && !std::any_of(fan_speed_change_requests.begin(), fan_speed_change_requests.end(), [](const std::pair<int, bool>& p) { return p.second; })){ if (m_fan_speed != -1 && !std::any_of(fan_speed_change_requests.begin(), fan_speed_change_requests.end(), [](const std::pair<int, bool>& p) { return p.second; })){
fan_speed_change_requests[CoolingLine::TYPE_FORCE_RESUME_FAN] = true;
need_set_fan = true; need_set_fan = true;
} }
if (m_additional_fan_speed != -1 && m_config.auxiliary_fan.value) if (m_additional_fan_speed != -1 && m_config.auxiliary_fan.value)
@ -932,10 +935,18 @@ std::string CoolingBuffer::apply_layer_cooldown(
} }
if (need_set_fan) { if (need_set_fan) {
if (fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]) if (fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]){
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed); new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed);
else if (fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) m_current_fan_speed = overhang_fan_speed;
}
else if (fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]){
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, supp_interface_fan_speed); new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, supp_interface_fan_speed);
m_current_fan_speed = supp_interface_fan_speed;
}
else if(fan_speed_change_requests[CoolingLine::TYPE_FORCE_RESUME_FAN] && m_current_fan_speed != -1){
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_current_fan_speed);
fan_speed_change_requests[CoolingLine::TYPE_FORCE_RESUME_FAN] = false;
}
else else
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed); new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed);
need_set_fan = false; need_set_fan = false;