Skip to content

Commit

Permalink
fan speed now can be properly disabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Aug 4, 2024
1 parent fef68ef commit ef7cf96
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 68 deletions.
36 changes: 24 additions & 12 deletions src/libslic3r/GCode/CoolingBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,10 @@ std::string CoolingBuffer::apply_layer_cooldown(
int fan_speeds[ uint8_t(GCodeExtrusionRole::Count)];
int default_fan_speed[ uint8_t(GCodeExtrusionRole::Count)];
#define EXTRUDER_CONFIG(OPT) m_config.OPT.get_at(m_current_extruder)
#define FAN_CONFIG(OPT) m_config.OPT.is_enabled(m_current_extruder) ? m_config.OPT.get_at(m_current_extruder) : -1
const int min_fan_speed = m_config.fan_printer_min_speed;
assert(min_fan_speed >= 0);
int initial_default_fan_speed = EXTRUDER_CONFIG(default_fan_speed);
int initial_default_fan_speed = FAN_CONFIG(default_fan_speed);
//if default_fan_speed activated, be sure it's at least the mins
if (initial_default_fan_speed > 0 && initial_default_fan_speed < min_fan_speed)
initial_default_fan_speed = min_fan_speed;
Expand All @@ -967,19 +968,29 @@ std::string CoolingBuffer::apply_layer_cooldown(
if (default_fan_speed[i] == 1) default_fan_speed[i] = 0;
}
//set the fan controls
default_fan_speed[ uint8_t(GCodeExtrusionRole::BridgeInfill)] = EXTRUDER_CONFIG(bridge_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::InternalBridgeInfill)] = EXTRUDER_CONFIG(internal_bridge_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::TopSolidInfill)] = EXTRUDER_CONFIG(top_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::BridgeInfill)] = FAN_CONFIG(bridge_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::InternalBridgeInfill)] = FAN_CONFIG(internal_bridge_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::TopSolidInfill)] = FAN_CONFIG(top_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::Ironing)] = default_fan_speed[ uint8_t(GCodeExtrusionRole::TopSolidInfill)];
default_fan_speed[ uint8_t(GCodeExtrusionRole::SupportMaterialInterface)] = EXTRUDER_CONFIG(support_material_interface_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::SupportMaterial)] = EXTRUDER_CONFIG(support_material_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::ExternalPerimeter)] = EXTRUDER_CONFIG(external_perimeter_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::SupportMaterialInterface)] = FAN_CONFIG(support_material_interface_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::SupportMaterial)] = FAN_CONFIG(support_material_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::ExternalPerimeter)] = FAN_CONFIG(external_perimeter_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::ThinWall)] = default_fan_speed[ uint8_t(GCodeExtrusionRole::ExternalPerimeter)];
default_fan_speed[ uint8_t(GCodeExtrusionRole::Perimeter)] = EXTRUDER_CONFIG(perimeter_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::SolidInfill)] = EXTRUDER_CONFIG(solid_infill_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::InternalInfill)] = EXTRUDER_CONFIG(infill_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::OverhangPerimeter)] = EXTRUDER_CONFIG(overhangs_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::GapFill)] = EXTRUDER_CONFIG(gap_fill_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::Perimeter)] = FAN_CONFIG(perimeter_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::SolidInfill)] = FAN_CONFIG(solid_infill_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::InternalInfill)] = FAN_CONFIG(infill_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::OverhangPerimeter)] = FAN_CONFIG(overhangs_fan_speed);
default_fan_speed[ uint8_t(GCodeExtrusionRole::GapFill)] = FAN_CONFIG(gap_fill_fan_speed);
// if disabled, and default is not default
if (default_fan_speed[uint8_t(GCodeExtrusionRole::TopSolidInfill)] < 0) {
default_fan_speed[ uint8_t(GCodeExtrusionRole::TopSolidInfill)] = default_fan_speed[ uint8_t(GCodeExtrusionRole::SolidInfill)];
}
if (default_fan_speed[uint8_t(GCodeExtrusionRole::SupportMaterialInterface)] < 0) {
default_fan_speed[ uint8_t(GCodeExtrusionRole::SupportMaterialInterface)] = default_fan_speed[ uint8_t(GCodeExtrusionRole::SupportMaterial)];
}
if (default_fan_speed[uint8_t(GCodeExtrusionRole::InternalBridgeInfill)] < 0) {
default_fan_speed[ uint8_t(GCodeExtrusionRole::InternalBridgeInfill)] = default_fan_speed[ uint8_t(GCodeExtrusionRole::BridgeInfill)];
}
// if default is enabled, it takes over the settings that are disabled.
if (initial_default_fan_speed >= 0) {
for (int i = 0; i < uint8_t(GCodeExtrusionRole::Count); i++) {
Expand Down Expand Up @@ -1285,6 +1296,7 @@ std::string CoolingBuffer::apply_layer_cooldown(
pos = line_end;
}
#undef EXTRUDER_CONFIG
#undef FAN_CONFIG
const char *gcode_end = gcode.c_str() + gcode.size();
if (pos < gcode_end)
new_gcode.append(pos, gcode_end - pos);
Expand Down
123 changes: 79 additions & 44 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,15 @@ void PrintConfigDef::init_fff_params()
def->label = L("Bridges fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during bridges and overhangs. It won't slow down the fan if it's currently running at a higher speed."
"\nSet to -1 to disable this override (Bridges will use default fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, default fan speed will be used."
"\nCan be disabled by disable_fan_first_layers and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comAdvancedE | comPrusa;
def->is_vector_extruder = true;
def->can_be_disabled = true;
def->set_default_value(new ConfigOptionInts{ 100 });

def = this->add("bridge_type", coEnum);
Expand Down Expand Up @@ -1354,12 +1356,13 @@ void PrintConfigDef::init_fff_params()
def->tooltip = L(
"Default speed for the fan, to set the speed for features where there is no fan control. Useful for PLA and other low-temp filament."
"\nSet 0 to disable the fan by default. Useful for ABS and other high-temp filaments."
"\nSet -1 to disable. if disabled, the beahavior isn't defined yet. The goal is to avoid adding fan speed commands.");
"\nIf disabled, no fan speed command will be emmited when possible (if a feature set a speed, it won't be reverted).");
def->mode = comSimpleAE | comSuSi;
def->min = -1;
def->min = 0;
def->max = 100;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts({-1}));
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));
def->aliases = { "min_fan_speed" }; // only if "fan_always_on"

def = this->add("default_print_profile", coString);
Expand Down Expand Up @@ -1646,17 +1649,18 @@ void PrintConfigDef::init_fff_params()
def = this->add("external_perimeter_fan_speed", coInts);
def->label = L("External perimeter fan speed");
def->tooltip = L("When set to a non-zero value this fan speed is used only for external perimeters (visible ones) and thin walls."
"\nSet to 1 to disable the fan."
"\nSet to -1 to use the normal fan speed on external perimeters."
"External perimeters can benefit from higher fan speed to improve surface finish, "
"\nSet to 0 to stop the fan."
"\nIf disabled, the default fan speed will be used."
"\nExternal perimeters can benefit from higher fan speed to improve surface finish, "
"while internal perimeters, infill, etc. benefit from lower fan speed to improve layer adhesion."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts { -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("external_perimeter_overlap", coPercent);
def->label = L("external perimeter overlap");
Expand Down Expand Up @@ -2891,15 +2895,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Gap fill fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all gap fill Perimeter moves"
"\nSet to 1 to disable fan."
"\nSet to -1 to disable this override (Gap Fill will use default fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, default fan speed will be used."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("gap_fill_flow_match_perimeter", coPercent);
def->label = L("Cap with perimeter flow");
Expand Down Expand Up @@ -3324,15 +3329,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Internal Infill fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all Internal Infill moves"
"\nSet to 1 to disable fan."
"\nSet to -1 to disable this override (Internal Infill will use default fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, default fan speed will be used."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("infill_first", coBool);
def->label = L("Infill before perimeters");
Expand Down Expand Up @@ -3421,14 +3427,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Infill bridges fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all infill bridges. It won't slow down the fan if it's currently running at a higher speed."
"\nSet to -1 to disable this override (Internal bridges will use Bridges fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, Bridge fan speed will be used."
"\nCan be disabled by disable_fan_first_layers and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));
def->aliases = { "bridge_internal_fan_speed" };

def = this->add("internal_bridge_speed", coFloatOrPercent);
Expand Down Expand Up @@ -4131,11 +4139,12 @@ void PrintConfigDef::init_fff_params()
"\nSet to -1 to disable this override (Overhang Perimeter use default fan speed)."
"\nCan be disabled by disable_fan_first_layers and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("overhangs_max_slope", coFloatOrPercent);
def->label = L("Overhangs max slope");
Expand Down Expand Up @@ -4391,15 +4400,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Internal Perimeter fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all Perimeter moves"
"\nSet to 1 to disable fan."
"\nSet to -1 to disable this override (Internal Perimeter use default fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, default fan speed will be used."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("perimeter_loop", coBool);
def->label = L("Perimeters loop");
Expand Down Expand Up @@ -5380,15 +5390,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Solid Infill fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all Solid Infill moves"
"\nSet to 1 to disable fan."
"\nSet to -1 to disable this override (Solid Infill will use default fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, default fan speed will be used."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer and increased by low layer time.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("solid_infill_speed", coFloatOrPercent);
def->label = L("Solid");
Expand Down Expand Up @@ -5757,15 +5768,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Support Material fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all support moves"
"\nSet to 0 to disable fan."
"\nSet to -1 to disable this override (Support will use default fan speed)."
"\nSet to 0 to stop the fan."
"\nIf disabled, default fan speed will be used."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comExpert | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("support_material_interface_angle", coFloat);
def->label = L("Pattern angle");
Expand All @@ -5792,15 +5804,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Support interface fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all support interfaces, to be able to weaken their bonding with a high fan speed."
"\nSet to 0 to disable the fan."
"\nSet to -1 to disable this override (Support Interface will use Support)."
"\nSet to 0 to stop the fan."
"\nIf disabled, Support Material fan speed will be used."
"\nCan only be overriden by disable_fan_first_layers.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));


def = this->add("support_material_interface_contact_loops", coBool);
Expand Down Expand Up @@ -6338,15 +6351,16 @@ void PrintConfigDef::init_fff_params()
def->label = L("Top Solid fan speed");
def->category = OptionCategory::cooling;
def->tooltip = L("This fan speed is enforced during all top fills (including ironing)."
"\nSet to 1 to disable the fan."
"\nSet to -1 to disable this override (Top Solid Infill will use Solid Infill)."
"\nSet to 0 to stop the fan."
"\nIf disabled, Solid Infill fan speed will be used."
"\nCan be disabled by disable_fan_first_layers, slowed down by full_fan_speed_layer.");
def->sidetext = L("%");
def->min = -1;
def->min = 0;
def->max = 100;
def->mode = comAdvancedE | comSuSi;
def->is_vector_extruder = true;
def->set_default_value(new ConfigOptionInts{ -1 });
def->can_be_disabled = true;
def->set_default_value((ConfigOptionInts*)(new ConfigOptionInts({ 100 }))->set_can_be_disabled()->set_enabled(false));

def = this->add("top_infill_extrusion_width", coFloatOrPercent);
def->label = L("Top solid infill");
Expand Down Expand Up @@ -8380,6 +8394,19 @@ void PrintConfigDef::handle_legacy(t_config_option_key &opt_key, std::string &va
value = "disabled";
}

//fan speed: activate disable.
if (opt_key.find("_fan_speed") != std::string::npos) {
if ("max_fan_speed" != opt_key && "filament_toolchange_part_fan_speed" != opt_key) {
if (value == "-1") {
value = "!100";
} else if (value == "1") {
// for now, still consider "1" as a "0", to be able to import old config where the 1 means 0 (and 0
// was disable).
value = "0";
}
}
}

if (!print_config_def.has(opt_key)) {
//check the aliases
for(const auto& entry : print_config_def.options) {
Expand Down Expand Up @@ -9257,15 +9284,23 @@ std::map<std::string, std::string> PrintConfigDef::to_prusa(t_config_option_key&
value = Slic3r::find_full_path(value, value).generic_string();
}
if ("default_fan_speed" == opt_key) {
if (!value.empty() && value.front() == '!') {
value = "1";
}
if (value == "0") {
opt_key = "min_fan_speed";
value = all_conf.option("fan_printer_min_speed")->get_float();
value = std::to_string(all_conf.option("fan_printer_min_speed")->get_float());
new_entries["fan_always_on"] = "0";
} else {
opt_key = "min_fan_speed";
new_entries["fan_always_on"] = "1";
}
}
if ("bridge_fan_speed" == opt_key) {
if (!value.empty() && value.front() == '!') {
value = std::to_string(all_conf.option("fan_printer_min_speed")->get_float());
}
}

// compute max & min height from % to flat value
if ("min_layer_height" == opt_key || "max_layer_height" == opt_key) {
Expand Down
Loading

0 comments on commit ef7cf96

Please sign in to comment.