ENH: add support for chamber_temp and exhaust_fan

Support controlling chamebr temperature and exhaust fan for air filtration

Signed-off-by: xun.zhang <xun.zhang@bambulab.com>
Change-Id: I31627ce4f8acce99e132b0436ab7dcd0bcebf81d
This commit is contained in:
xun.zhang 2023-08-01 10:14:22 +08:00 committed by Lane.Wei
parent be19c137fe
commit 9b20cad55e
11 changed files with 232 additions and 10 deletions

View file

@ -571,6 +571,15 @@ static std::vector<Vec2d> get_path_of_change_filament(const Print& print)
check_add_eol(start_filament_gcode_str);
}
// deal exhaust fan speed
{
const bool activate_air_filtration = gcodegen.config().activate_air_filtration.get_at(new_extruder_id);
if (activate_air_filtration&&gcodegen.config().support_air_filtration.getBool()) {
start_filament_gcode_str += GCodeWriter::set_exhaust_fan(gcodegen.config().during_print_exhaust_fan_speed.get_at(new_extruder_id),false);
((start_filament_gcode_str +=';')+=GCodeProcessor::reserved_tag(GCodeProcessor::ETags::During_Print_Exhaust_Fan)) += '\n';
}
}
// Insert the end filament, toolchange, and start filament gcode into the generated gcode.
DynamicConfig config;
config.set_key_value("filament_end_gcode", new ConfigOptionString(end_filament_gcode_str));
@ -1773,6 +1782,8 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
m_placeholder_parser.set("first_layer_print_size", new ConfigOptionFloats({ bbox.size().x(), bbox.size().y() }));
}
auto chamber_temp_vec = m_config.option<ConfigOptionInts>("chamber_temperatures")->values;
int max_chamber_temp = *std::max_element(chamber_temp_vec.begin(), chamber_temp_vec.end());
{
int curr_bed_type = m_config.curr_bed_type.getInt();
@ -1815,6 +1826,9 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
if (print.config().gcode_flavor != gcfKlipper) {
// Set bed temperature if the start G-code does not contain any bed temp control G-codes.
this->_print_first_layer_bed_temperature(file, print, machine_start_gcode, initial_extruder_id, true);
if (m_config.option<ConfigOptionBool>("chamber_temp_control")->getBool()) {
this->_print_chamber_temperature(file, print, machine_start_gcode,max_chamber_temp, true);
}
// Set extruder(s) temperature before and after start G-code.
this->_print_first_layer_extruder_temperatures(file, print, machine_start_gcode, initial_extruder_id, false);
}
@ -1827,6 +1841,7 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
m_writer.set_current_position_clear(false);
m_start_gcode_filament = GCodeProcessor::get_gcode_last_filament(machine_start_gcode);
// Process filament-specific gcode.
/* if (has_wipe_tower) {
// Wipe tower will control the extruder switching, it will call the filament_start_gcode.
@ -1837,6 +1852,13 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
}
*/
this->_print_first_layer_extruder_temperatures(file, print, machine_start_gcode, initial_extruder_id, true);
bool activate_air_filtration = *std::max_element(m_config.activate_air_filtration.values.begin(), m_config.activate_air_filtration.values.end()) && m_config.support_air_filtration.getBool();
if (activate_air_filtration && m_config.activate_air_filtration.get_at(initial_extruder_id)) {
file.write(m_writer.set_exhaust_fan(m_config.during_print_exhaust_fan_speed.get_at(initial_extruder_id), true));
}
print.throw_if_canceled();
// Set other general things.
@ -2103,6 +2125,16 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato
file.write(m_writer.update_progress(m_layer_count, m_layer_count, true)); // 100%
file.write(m_writer.postamble());
file.write(m_writer.set_chamber_temperature(0, false)); //close chamber_temperature
if (activate_air_filtration) {
int complete_print_exhaust_fan_speed = 0;
for (size_t i = 0; i < m_config.activate_air_filtration.size(); ++i)
if (m_config.activate_air_filtration.get_at(i))
complete_print_exhaust_fan_speed = std::max(complete_print_exhaust_fan_speed, m_config.complete_print_exhaust_fan_speed.get_at(i));
file.write(m_writer.set_exhaust_fan(complete_print_exhaust_fan_speed,true));
}
// adds tags for time estimators
file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Last_Line_M73_Placeholder).c_str());
file.write_format("; EXECUTABLE_BLOCK_END\n\n");
@ -2367,6 +2399,16 @@ int GCode::get_bed_temperature(const int extruder_id, const bool is_first_layer,
return bed_temp_opt->get_at(extruder_id);
}
void GCode::_print_chamber_temperature(GCodeOutputStream &file, Print &print, const std::string &gcode,int chamber_temperature, bool wait)
{
int temp_by_gcode = -1;
bool temp_set_by_gcode = custom_gcode_sets_temperature(gcode, 141, 191, false, temp_by_gcode);
std::string set_chamber_temp_gcode = m_writer.set_chamber_temperature(chamber_temperature, wait);
if (!temp_set_by_gcode)
file.write(set_chamber_temp_gcode);
}
// Write 1st layer bed temperatures into the G-code.
// Only do that if the start G-code does not already contain any M-code controlling an extruder temperature.
// M140 - Set Extruder Temperature