FIX:update load/unload command for n3s

(cherry picked from commit bambulab/BambuStudio@fc32042639)

---------

Co-authored-by: tao wang <tao.wang@bambulab.com>
This commit is contained in:
Noisyfox
2025-05-22 21:54:15 +08:00
parent b5c164fae6
commit 625a946e25
3 changed files with 113 additions and 54 deletions

View File

@@ -1868,45 +1868,71 @@ int MachineObject::command_set_chamber(int temp)
return this->publish_json(j.dump(), 1);
}
int MachineObject::command_ams_switch(int tray_index, int old_temp, int new_temp)
{
BOOST_LOG_TRIVIAL(trace) << "ams_switch to " << tray_index << " with temp: " << old_temp << ", " << new_temp;
if (old_temp < 0) old_temp = FILAMENT_DEF_TEMP;
if (new_temp < 0) new_temp = FILAMENT_DEF_TEMP;
//int MachineObject::command_ams_switch(int tray_index, int old_temp, int new_temp)
//{
// BOOST_LOG_TRIVIAL(trace) << "ams_switch to " << tray_index << " with temp: " << old_temp << ", " << new_temp;
// if (old_temp < 0) old_temp = FILAMENT_DEF_TEMP;
// if (new_temp < 0) new_temp = FILAMENT_DEF_TEMP;
//
// std::string gcode = "";
// int result = 0;
//
// //command
// if (is_support_command_ams_switch) {
// command_ams_change_filament(tray_index, old_temp, new_temp);
// }
// else {
// std::string gcode = "";
// if (tray_index == 255) {
// gcode = DeviceManager::load_gcode(printer_type, "ams_unload.gcode");
// }
// else {
// // include VIRTUAL_TRAY_ID
// gcode = DeviceManager::load_gcode(printer_type, "ams_load.gcode");
// boost::replace_all(gcode, "[next_extruder]", std::to_string(tray_index));
// boost::replace_all(gcode, "[new_filament_temp]", std::to_string(new_temp));
// }
//
// result = this->publish_gcode(gcode);
// }
//
// return result;
//}
std::string gcode = "";
int result = 0;
//command
if (is_support_command_ams_switch) {
command_ams_change_filament(tray_index, old_temp, new_temp);
}
else {
std::string gcode = "";
if (tray_index == 255) {
gcode = DeviceManager::load_gcode(printer_type, "ams_unload.gcode");
}
else {
// include VIRTUAL_TRAY_ID
gcode = DeviceManager::load_gcode(printer_type, "ams_load.gcode");
boost::replace_all(gcode, "[next_extruder]", std::to_string(tray_index));
boost::replace_all(gcode, "[new_filament_temp]", std::to_string(new_temp));
}
result = this->publish_gcode(gcode);
}
return result;
}
int MachineObject::command_ams_change_filament(int tray_id, int old_temp, int new_temp)
int MachineObject::command_ams_change_filament(bool load, std::string ams_id, std::string slot_id, int old_temp, int new_temp)
{
json j;
j["print"]["command"] = "ams_change_filament";
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
j["print"]["target"] = tray_id;
j["print"]["curr_temp"] = old_temp;
j["print"]["tar_temp"] = new_temp;
try {
auto tray_id = 0;
if (ams_id < "16") {
tray_id = atoi(ams_id.c_str()) * 4 + atoi(slot_id.c_str());
}
// TODO: Orca hack
if (ams_id == "254")
ams_id = "255";
j["print"]["command"] = "ams_change_filament";
j["print"]["sequence_id"] = std::to_string(MachineObject::m_sequence_id++);
j["print"]["curr_temp"] = old_temp;
j["print"]["tar_temp"] = new_temp;
j["print"]["ams_id"] = atoi(ams_id.c_str());
if (!load) {
j["print"]["target"] = 255;
j["print"]["slot_id"] = 255; // the new protocol to mark unload
} else {
if (tray_id == 0) {
j["print"]["target"] = atoi(ams_id.c_str());
} else {
j["print"]["target"] = tray_id;
}
j["print"]["slot_id"] = atoi(slot_id.c_str());
}
} catch (const std::exception &) {}
return this->publish_json(j.dump());
}
@@ -3308,6 +3334,7 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
if (jj.contains("flag3")) {
int flag3 = jj["flag3"].get<int>();
is_support_filament_setting_inprinting = get_flag_bits(flag3, 3);
is_enable_ams_np = get_flag_bits(flag3, 9);
}
}
if (!key_field_only) {

View File

@@ -929,8 +929,8 @@ public:
int command_set_nozzle(int temp);
int command_set_chamber(int temp);
// ams controls
int command_ams_switch(int tray_index, int old_temp = 210, int new_temp = 210);
int command_ams_change_filament(int tray_id, int old_temp = 210, int new_temp = 210);
//int command_ams_switch(int tray_index, int old_temp = 210, int new_temp = 210);
int command_ams_change_filament(bool load, std::string ams_id, std::string slot_id, int old_temp = 210, int new_temp = 210);
int command_ams_user_settings(int ams_id, bool start_read_opt, bool tray_read_opt, bool remain_flag = false);
int command_ams_switch_filament(bool switch_filament);
int command_ams_air_print_detect(bool air_print_detect);
@@ -1042,6 +1042,7 @@ public:
/*for more extruder*/
bool is_enable_np{ false };
bool is_enable_ams_np{ false };
ExtderData m_extder_data;

View File

@@ -3432,7 +3432,7 @@ void StatusPanel::on_axis_ctrl_e_down_10(wxCommandEvent &event)
void StatusPanel::on_start_unload(wxCommandEvent &event)
{
if (obj) obj->command_ams_switch(255);
if (obj) obj->command_ams_change_filament(false, "255", "255");
}
void StatusPanel::on_set_bed_temp()
@@ -3518,10 +3518,11 @@ void StatusPanel::on_ams_load_curr()
std::string curr_ams_id = m_ams_control->GetCurentAms();
std::string curr_can_id = m_ams_control->GetCurrentCan(curr_ams_id);
update_filament_step();
//virtual tray
if (curr_ams_id.compare(std::to_string(VIRTUAL_TRAY_ID)) == 0) {
if (curr_ams_id.compare(std::to_string(VIRTUAL_TRAY_ID)) == 0)
{
int old_temp = -1;
int new_temp = -1;
AmsTray* curr_tray = &obj->vt_tray;
@@ -3531,13 +3532,22 @@ void StatusPanel::on_ams_load_curr()
try {
if (!curr_tray->nozzle_temp_max.empty() && !curr_tray->nozzle_temp_min.empty())
old_temp = (atoi(curr_tray->nozzle_temp_min.c_str()) + atoi(curr_tray->nozzle_temp_max.c_str())) / 2;
if (!obj->vt_tray.nozzle_temp_max.empty() && !obj->vt_tray.nozzle_temp_min.empty())
new_temp = (atoi(obj->vt_tray.nozzle_temp_min.c_str()) + atoi(obj->vt_tray.nozzle_temp_max.c_str())) / 2;
if (!curr_tray->nozzle_temp_max.empty() && !curr_tray->nozzle_temp_min.empty())
new_temp = (atoi(curr_tray->nozzle_temp_min.c_str()) + atoi(curr_tray->nozzle_temp_max.c_str())) / 2;
}
catch (...) {
;
}
obj->command_ams_switch(VIRTUAL_TRAY_ID, old_temp, new_temp);
if (obj->is_enable_np || obj->is_enable_ams_np) {
try {
if (!curr_ams_id.empty() && !curr_can_id.empty()) {
obj->command_ams_change_filament(true, curr_ams_id, "0", old_temp, new_temp);
}
} catch (...) {}
} else {
obj->command_ams_change_filament(true, "254", "0", old_temp, new_temp);
}
}
std::map<std::string, Ams*>::iterator it = obj->amsList.find(curr_ams_id);
@@ -3552,24 +3562,32 @@ void StatusPanel::on_ams_load_curr()
}
AmsTray* curr_tray = obj->get_curr_tray();
AmsTray* targ_tray = obj->get_ams_tray(curr_ams_id, curr_can_id);
int old_temp = -1;
int new_temp = -1;
if (curr_tray && targ_tray) {
int old_temp = -1;
int new_temp = -1;
try {
if (!curr_tray->nozzle_temp_max.empty() && !curr_tray->nozzle_temp_min.empty())
old_temp = (atoi(curr_tray->nozzle_temp_min.c_str()) + atoi(curr_tray->nozzle_temp_max.c_str())) / 2;
if (!targ_tray->nozzle_temp_max.empty() && !targ_tray->nozzle_temp_min.empty())
new_temp = (atoi(targ_tray->nozzle_temp_min.c_str()) + atoi(targ_tray->nozzle_temp_max.c_str())) / 2;
}
catch (...) {
} catch (...) {
;
}
int tray_index = atoi(curr_ams_id.c_str()) * 4 + atoi(tray_it->second->id.c_str());
obj->command_ams_switch(tray_index, old_temp, new_temp);
}
else {
int tray_index = atoi(curr_ams_id.c_str()) * 4 + atoi(tray_it->second->id.c_str());
obj->command_ams_switch(tray_index, -1, -1);
int tray_index = atoi(curr_ams_id.c_str()) * 4 + atoi(tray_it->second->id.c_str());
if (obj->is_enable_np) {
try {
if (!curr_ams_id.empty() && !curr_can_id.empty()) {
obj->command_ams_change_filament(true, curr_ams_id, curr_can_id, old_temp, new_temp);
}
}
catch (...){}
} else {
obj->command_ams_change_filament(true, curr_ams_id, curr_can_id, old_temp, new_temp);
}
}
}
@@ -3586,7 +3604,20 @@ void StatusPanel::on_ams_load_vams(wxCommandEvent& event) {
void StatusPanel::on_ams_unload(SimpleEvent &event)
{
if (obj) { obj->command_ams_switch(255); }
if (obj) {
std::string curr_ams_id = m_ams_control->GetCurentAms();
std::string curr_can_id = m_ams_control->GetCurrentCan(curr_ams_id);
if (obj->is_enable_np) {
try {
for (auto ext : obj->m_extder_data.extders) {
if (ext.snow.ams_id == curr_ams_id && ext.snow.slot_id == curr_can_id) { obj->command_ams_change_filament(false, curr_ams_id, "255"); }
}
} catch (...) {}
} else {
obj->command_ams_change_filament(false, curr_ams_id, "255");
}
}
}
void StatusPanel::on_ams_filament_backup(SimpleEvent& event)