ENH: remove the appended T cmd after change filament

Jira: none

Signed-off-by: qing.zhang <qing.zhang@bambulab.com>
Change-Id: Id5da64626b7343a71dcb38c06f5b5caf43ec40e2
(cherry picked from commit 7da565f0582f470274d279e52daf0dd889f0de7d)
This commit is contained in:
qing.zhang
2024-06-13 16:03:24 +08:00
committed by Noisyfox
parent 95a5914c26
commit bba00b2e7a
4 changed files with 68 additions and 5 deletions

View File

@@ -1447,7 +1447,9 @@ void GCode::do_export(Print* print, const char* path, GCodeProcessorResult* resu
return;
BOOST_LOG_TRIVIAL(info) << boost::format("Will export G-code to %1% soon")%path;
GCodeProcessor::s_IsBBLPrinter = print->is_BBL_printer();
m_writer.set_is_bbl_machine(print->is_BBL_printer());
print->set_started(psGCodeExport);
// check if any custom gcode contains keywords used by the gcode processor to
@@ -6573,9 +6575,10 @@ std::string GCode::set_extruder(unsigned int extruder_id, double print_z, bool b
m_writer.reset_e();
}
// We inform the writer about what is happening, but we may not use the resulting gcode.
//BBS: don't add T[next extruder] if there is no T cmd on filament change
//We inform the writer about what is happening, but we may not use the resulting gcode.
std::string toolchange_command = m_writer.toolchange(extruder_id);
if (! custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id))
if (!custom_gcode_changes_tool(toolchange_gcode_parsed, m_writer.toolchange_prefix(), extruder_id))
gcode += toolchange_command;
else {
// user provided his own toolchange gcode, no need to do anything

View File

@@ -1736,8 +1736,27 @@ void GCodeProcessor::process_gcode_line(const GCodeReader::GCodeLine& line, bool
break;
}
break;
default:
break;
case 5:
switch (cmd[1]) {
case '1':
switch (cmd[2]) {
case '0':
switch (cmd[3]) {
case '2':
switch (cmd[4]) {
case '0': {
process_M1020(line); // Select Tool
break;
}
default: break;
}
default: break;
}
default: break;
}
default: break;
}
default: break;
}
break;
case 't':
@@ -3962,6 +3981,42 @@ void GCodeProcessor::process_T(const GCodeReader::GCodeLine& line)
process_T(line.cmd());
}
void GCodeProcessor::process_M1020(const GCodeReader::GCodeLine &line)
{
if (line.raw().length() > 5) {
std::string filament_id = line.raw().substr(7);
if (filament_id.empty())
return;
int eid = 0;
eid = std::stoi(filament_id);
if (eid < 0 || eid > 254) {
// M1020-1 is a valid gcode line for RepRap Firmwares (used to deselects all tools)
if ((m_flavor != gcfRepRapFirmware && m_flavor != gcfRepRapSprinter) || eid != -1)
BOOST_LOG_TRIVIAL(error) << "Invalid M1020 command (" << line.raw() << ").";
} else {
unsigned char id = static_cast<unsigned char>(eid);
if (m_extruder_id != id) {
if (id >= m_result.extruders_count)
BOOST_LOG_TRIVIAL(error) << "Invalid M1020 command (" << line.raw() << ").";
else {
m_last_extruder_id = m_extruder_id;
process_filaments(CustomGCode::ToolChange);
m_extruder_id = id;
m_cp_color.current = m_extruder_colors[id];
// BBS: increase filament change times
m_result.lock();
m_result.print_statistics.total_filamentchanges++;
m_result.unlock();
}
// store tool change move
store_move_vertex(EMoveType::Tool_change);
}
}
}
}
void GCodeProcessor::process_T(const std::string_view command)
{
unsigned int new_extruder = 0;

View File

@@ -943,6 +943,7 @@ class Print;
// Processes T line (Select Tool)
void process_T(const GCodeReader::GCodeLine& line);
void process_T(const std::string_view command);
void process_M1020(const GCodeReader::GCodeLine &line);
// post process the file with the given filename to:
// 1) add remaining time lines M73 and update moves' gcode ids accordingly

View File

@@ -463,7 +463,11 @@ std::string GCodeWriter::toolchange(unsigned int extruder_id)
// if we are running a single-extruder setup, just set the extruder and return nothing
std::ostringstream gcode;
if (this->multiple_extruders || (this->config.filament_diameter.values.size() > 1 && !is_bbl_printers())) {
gcode << this->toolchange_prefix() << extruder_id;
// BBS
if (this->m_is_bbl_printers)
gcode << "M1020 S" << extruder_id;
else
gcode << this->toolchange_prefix() << extruder_id;
//BBS
if (GCodeWriter::full_gcode_comment)
gcode << " ; change extruder";