Skip to content

Commit

Permalink
Implement default_fan with -1 (disabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed May 21, 2024
1 parent 9cf1263 commit 48a3a5b
Showing 1 changed file with 25 additions and 14 deletions.
39 changes: 25 additions & 14 deletions src/libslic3r/GCode/CoolingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -931,9 +931,9 @@ std::string CoolingBuffer::apply_layer_cooldown(
fan_speeds[i] = default_fan_speed[i];
}
//fan_speeds[0] carry the current default value. ensure it's not negative.
if (initial_default_fan_speed <= 0) {
fan_speeds[0] = 0;
}
//if (initial_default_fan_speed <= 0) {
// fan_speeds[0] = 0;
//}
if (layer_time < slowdown_below_layer_time && fan_below_layer_time > 0) {
// Layer time very short. Enable the fan to a full throttle.
//fan_speed_new = std::max(max_fan_speed, fan_speed_new);
Expand All @@ -948,7 +948,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
for (size_t etype_idx = 0; etype_idx < etype_can_increase_fan.size(); etype_idx++) {
uint16_t idx = etype_can_increase_fan[etype_idx];
if (fan_speeds[idx] < max_fan_speed) // if max speed is lower, this will reduce speed, so don't do it.
fan_speeds[idx] = std::clamp(int(t * fan_speeds[idx] + (1. - t) * max_fan_speed + 0.5), 0, 255);
fan_speeds[idx] = std::clamp(int(t * (fan_speeds[idx] < 0 ? 0 : fan_speeds[idx]) + (1. - t) * max_fan_speed + 0.5), 0, 255);
}
}

Expand All @@ -961,7 +961,9 @@ std::string CoolingBuffer::apply_layer_cooldown(
float factor = float(int(layer_id + 1) - disable_fan_first_layers) / float(full_fan_speed_layer - disable_fan_first_layers);
for (size_t etype_idx = 0; etype_idx < etype_can_ramp_up_fan.size(); etype_idx++) {
uint16_t idx = etype_can_ramp_up_fan[etype_idx];
fan_speeds[idx] = std::clamp(int(float(fan_speeds[idx]) * factor + 0.01f), 0, 255);
if (fan_speeds[idx] > 0) {
fan_speeds[idx] = std::clamp(int(float(fan_speeds[idx] < 0 ? 0 : fan_speeds[idx]) * factor + 0.01f), 0, 255);
}
}
}
//only activate fan control if the fan speed is higher than min
Expand Down Expand Up @@ -1020,6 +1022,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
const char *pos = gcode.c_str();
int current_feedrate = 0;
int stored_fan_speed = m_fan_speed < 0 ? 0 : m_fan_speed;
int current_fan_speed = -1;
change_extruder_set_fan();
for (const CoolingLine *line : lines) {
const char *line_start = gcode.c_str() + line->line_start;
Expand Down Expand Up @@ -1139,19 +1142,27 @@ std::string CoolingBuffer::apply_layer_cooldown(
bool fan_set = false;
for (size_t i = extrude_tree.size() - 1; i < extrude_tree.size(); --i) {
if (fan_control[extrude_tree[i]]) {
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments,
fan_speeds[extrude_tree[i]],
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
std::string("set fan for ") + ExtrusionEntity::role_to_string(extrude_tree[i]));
if (current_fan_speed != fan_speeds[extrude_tree[i]]) {
current_fan_speed = fan_speeds[extrude_tree[i]];
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments,
fan_speeds[extrude_tree[i]],
EXTRUDER_CONFIG(extruder_fan_offset),
m_config.fan_percentage,
std::string("set fan for ") + ExtrusionEntity::role_to_string(extrude_tree[i]));
}
fan_set = true;
break;
}
}
if (!fan_set) {
// return to default
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed < 0 ? 0 : m_fan_speed,
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
"set default fan");
if (!fan_set && m_fan_speed >= 0 ) {
if (current_fan_speed != m_fan_speed && (default_fan_speed[0] >= 0 || current_fan_speed > 0)) {
current_fan_speed = m_fan_speed;
// return to default
new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_config.gcode_comments, m_fan_speed,
EXTRUDER_CONFIG(extruder_fan_offset), m_config.fan_percentage,
"set default fan");
}
fan_set = true;
}
fan_need_set = false;
}
Expand Down

0 comments on commit 48a3a5b

Please sign in to comment.