When using fan_speedup, don't move fan from custom_gcode

also don't enter the start_gcode if start_gcode_manual (only custom start gcode)
Fix only for overhangs
Update to tooltips
supermerill/SuperSlicer#1742
This commit is contained in:
supermerill 2021-10-30 20:37:39 +02:00
parent a6802bc728
commit 3d07c03a37
3 changed files with 28 additions and 10 deletions

View File

@ -1398,6 +1398,13 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
// Write the custom start G-code
_writeln(file, start_gcode);
//flush FanMover buffer to avoid modifying the start gcode if it's manual.
if (this->config().start_gcode_manual && this->m_fan_mover.get() != nullptr) {
std::string to_write = this->m_fan_mover.get()->process_gcode("", true);
const char* gcode_to_write = to_write.c_str();
// writes string to file
fwrite(gcode_to_write, 1, ::strlen(gcode_to_write), file);
}
// Process filament-specific gcode.
/* if (has_wipe_tower) {
@ -1711,7 +1718,7 @@ std::string GCode::placeholder_parser_process(const std::string &name, const std
func_add_colour("thumbnails_color_int", config().thumbnails_color);
std::string gcode = m_placeholder_parser.process(templ, current_extruder_id, config_override, &m_placeholder_parser_context);
if (!gcode.empty() && m_config.gcode_comments) {
if (!gcode.empty() && (m_config.gcode_comments || m_config.fan_speedup_time.value != 0 || m_config.fan_kickstart.value != 0 )) {
gcode = "; custom gcode: " + name + "\n" + gcode;
check_add_eol(gcode);
gcode += "; custom gcode end: "+ name + "\n";

View File

@ -27,8 +27,9 @@ const std::string& FanMover::process_gcode(const std::string& gcode, bool flush)
m_buffer_time_size = 0;
for (auto& data : m_buffer) m_buffer_time_size += data.time;
m_parser.parse_buffer(gcode,
[this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { /*m_process_output += line.raw() + "\n";*/ this->_process_gcode_line(reader, line); });
if(!gcode.empty())
m_parser.parse_buffer(gcode,
[this](GCodeReader& reader, const GCodeReader::GCodeLine& line) { /*m_process_output += line.raw() + "\n";*/ this->_process_gcode_line(reader, line); });
if (flush) {
while (!m_buffer.empty()) {
@ -95,7 +96,6 @@ int16_t get_fan_speed(const std::string &line, GCodeFlavor flavor) {
}
void FanMover::_put_in_middle_G1(std::list<BufferData>::iterator item_to_split, float nb_sec_since_itemtosplit_start, BufferData &&line_to_write) {
//std::cout << "_put_in_middle_G1\n";
assert(item_to_split != m_buffer.end());
if (nb_sec_since_itemtosplit_start > item_to_split->time * 0.9) {
// doesn't really need to be split, print it after
@ -152,7 +152,6 @@ void FanMover::_put_in_middle_G1(std::list<BufferData>::iterator item_to_split,
}
void FanMover::_print_in_middle_G1(BufferData& line_to_split, float nb_sec, const std::string &line_to_write) {
//std::cout << "_print_in_middle_G1\n";
if (nb_sec < line_to_split.time * 0.1) {
// doesn't really need to be split, print it after
m_process_output += line_to_split.raw + "\n";
@ -215,6 +214,7 @@ void FanMover::_remove_slow_fan(int16_t min_speed, float past_sec) {
void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCodeLine& line)
{
// processes 'normal' gcode lines
bool need_flush = false;
std::string cmd(line.cmd());
double time = 0;
int16_t fan_speed = -1;
@ -245,7 +245,7 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
if (!m_is_custom_gcode) {
// if slow down => put in the queue. if not =>
if (m_back_buffer_fan_speed < fan_speed) {
if (nb_seconds_delay > 0 && (!only_overhangs || current_role != ExtrusionRole::erOverhangPerimeter)) {
if (nb_seconds_delay > 0 && (!only_overhangs || current_role == ExtrusionRole::erOverhangPerimeter)) {
//don't put this command in the queue
time = -1;
// this M106 need to go in the past
@ -339,6 +339,9 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
}
//update back buffer fan speed
m_back_buffer_fan_speed = fan_speed;
} else {
// have to flush the buffer to avoid erasing a fan command.
need_flush = true;
}
}
break;
@ -352,8 +355,12 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
std::string extrusion_string = line.raw().substr(6, line.raw().size() - 6);
current_role = ExtrusionEntity::string_to_role(extrusion_string);
}
if (line.raw().size() > 16 && line.raw().rfind("; custom gcode", 0) == 0) {
m_is_custom_gcode = line.raw().rfind("; custom gcode end", 0) != 0;
if (line.raw().size() > 16) {
if (line.raw().rfind("; custom gcode", 0) != std::string::npos)
if (line.raw().rfind("; custom gcode end", 0) != std::string::npos)
m_is_custom_gcode = false;
else
m_is_custom_gcode = true;
}
}
}
@ -412,7 +419,7 @@ void FanMover::_process_gcode_line(GCodeReader& reader, const GCodeReader::GCode
// puts the line back into the gcode
//if buffer too big, flush it.
if (time >= 0) {
while (!m_buffer.empty() && m_buffer_time_size - m_buffer.front().time > nb_seconds_delay - EPSILON) {
while (!m_buffer.empty() && (need_flush || m_buffer_time_size - m_buffer.front().time > nb_seconds_delay - EPSILON) ){
BufferData& frontdata = m_buffer.front();
if (frontdata.fan_speed < 0 || frontdata.fan_speed != m_front_buffer_fan_speed || frontdata.is_kickstart) {
if (frontdata.is_kickstart && frontdata.fan_speed < m_front_buffer_fan_speed) {

View File

@ -2564,7 +2564,10 @@ void PrintConfigDef::init_fff_params()
def->label = L("Fan startup delay");
def->category = OptionCategory::firmware;
def->tooltip = L("Move the fan start in the past by at least this delay (in seconds, you can use decimals)."
" It assumes infinite acceleration for this time estimation, and will only take into account G1 and G0 moves. Use 0 to deactivate.");
" It assumes infinite acceleration for this time estimation, and will only take into account G1 and G0 moves."
"\nIt won't move fan comands from custom gcodes (they act as a sort of 'barrier')."
"\nIt won't move fan comands into the start gcode if the 'only custom start gcode' is activated."
"\nUse 0 to deactivate.");
def->sidetext = L("s");
def->mode = comAdvanced;
def->set_default_value(new ConfigOptionFloat(0));
@ -2580,6 +2583,7 @@ void PrintConfigDef::init_fff_params()
def->label = L("Fan KickStart time");
def->category = OptionCategory::firmware;
def->tooltip = L("Add a M106 S255 (max speed for fan) for this amount of seconds before going down to the desired speed to kick-start the cooling fan."
"\nThis value is used for a 0->100% speedup, it will go down if the delta is lower."
"\nSet to 0 to deactivate.");
def->sidetext = L("s");
def->min = 0;