ENH:support setting chamber temperature

Change-Id: Icacd3f248a8f4dbff6c928e666f986c62801eebd
This commit is contained in:
tao wang 2023-07-06 10:53:28 +08:00 committed by Lane.Wei
parent 403c5e825d
commit 771bc38a02
5 changed files with 122 additions and 27 deletions

View file

@ -53,12 +53,12 @@
"printer_thumbnail_image": "printer_thumbnail_p1p"
},
{
"display_name": "Bambu Lab X1",
"func": {
"FUNC_VIRTUAL_TYAY": true,
"FUNC_EXTRUSION_CALI": false,
"FUNC_LOCAL_TUNNEL": false
"FUNC_LOCAL_TUNNEL": false,
"FUNC_CHAMBER_TEMP": false
},
"model_id": "BL-P002",
"compatible_machine": [ "BL-P001", "C11", "C12"],
@ -69,6 +69,7 @@
{
"display_name": "Bambu Lab X1 Carbon",
"func": {
"FUNC_CHAMBER_TEMP": false,
"FUNC_VIRTUAL_TYAY": true,
"FUNC_EXTRUSION_CALI": false,
"FUNC_LOCAL_TUNNEL": false

View file

@ -462,6 +462,7 @@ MachineObject::MachineObject(NetworkAgent* agent, std::string name, std::string
bed_temp = 0.0f;
bed_temp_target = 0.0f;
chamber_temp = 0.0f;
chamber_temp_target = 0;
frame_temp = 0.0f;
/* ams fileds */
@ -1720,6 +1721,12 @@ int MachineObject::command_set_nozzle(int temp)
return this->publish_gcode(gcode_str);
}
int MachineObject::command_set_chamber(int temp)
{
std::string gcode_str = (boost::format("M141 S%1%\n") % temp).str();
return this->publish_gcode(gcode_str);
}
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;
@ -2980,6 +2987,11 @@ int MachineObject::parse_json(std::string payload)
chamber_temp = jj["chamber_temper"].get<float>();
}
}
if (jj.contains("ctt")) {
if (jj["ctt"].is_number()) {
chamber_temp_target = jj["ctt"].get<int>();
}
}
/* signals */
if (jj.contains("link_th_state"))
link_th = jj["link_th_state"].get<std::string>();
@ -5121,6 +5133,22 @@ bool DeviceManager::get_bed_temperature_limit(std::string type_str, int &limit)
return result;
}
bool DeviceManager::get_nozzle_max_temperature(std::string type_str, int& limit)
{
bool result = false;
if (DeviceManager::function_table.contains("printers")) {
for (auto printer : DeviceManager::function_table["printers"]) {
if (printer.contains("model_id") && printer["model_id"].get<std::string>() == type_str) {
if (printer.contains("nozzle_max_temperature")) {
limit = printer["nozzle_max_temperature"].get<int>();
return true;
}
}
}
}
return result;
}
bool DeviceManager::load_functional_config(std::string config_file)
{
std::ifstream json_file(config_file.c_str());

View file

@ -530,6 +530,7 @@ public:
float bed_temp;
float bed_temp_target;
float chamber_temp;
int chamber_temp_target;
float frame_temp;
/* cooling */
@ -767,6 +768,7 @@ public:
int command_task_resume();
int command_set_bed(int temp);
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);
@ -931,6 +933,7 @@ public:
static std::vector<std::string> get_resolution_supported(std::string type_str);
static bool get_bed_temperature_limit(std::string type_str, int& limit);
static bool get_nozzle_max_temperature(std::string type_str, int& limit);
static bool load_functional_config(std::string config_file);
static bool load_filaments_blacklist_config(std::string config_file);
static void check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, bool& in_blacklist, std::string& ac, std::string& info);

View file

@ -30,6 +30,7 @@ static const wxFont SWITCH_FONT = Label::Body_10;
/* const values */
static const int bed_temp_range[2] = {20, 120};
static const int nozzle_temp_range[2] = {20, 300};
static const int nozzle_chamber_range[2] = {20, 60};
/* colors */
static const wxColour STATUS_PANEL_BG = wxColour(238, 238, 238);
@ -958,15 +959,17 @@ wxBoxSizer *StatusBasePanel::create_temp_control(wxWindow *parent)
sizer->Add(line, 0, wxEXPAND | wxLEFT | wxRIGHT, 12);
wxWindowID frame_id = wxWindow::NewControlId();
m_tempCtrl_frame = new TempInput(parent, frame_id, TEMP_BLANK_STR, TEMP_BLANK_STR, wxString("monitor_frame_temp"), wxString("monitor_frame_temp"), wxDefaultPosition,
m_tempCtrl_chamber = new TempInput(parent, frame_id, TEMP_BLANK_STR, TEMP_BLANK_STR, wxString("monitor_frame_temp"), wxString("monitor_frame_temp"), wxDefaultPosition,
wxDefaultSize, wxALIGN_CENTER);
m_tempCtrl_frame->SetReadOnly(true);
m_tempCtrl_frame->SetMinSize(TEMP_CTRL_MIN_SIZE);
m_tempCtrl_frame->SetBorderWidth(FromDIP(2));
m_tempCtrl_frame->SetTextColor(tempinput_text_colour);
m_tempCtrl_frame->SetBorderColor(tempinput_border_colour);
m_tempCtrl_chamber->SetReadOnly(true);
m_tempCtrl_chamber->SetMinTemp(nozzle_chamber_range[0]);
m_tempCtrl_chamber->SetMaxTemp(nozzle_chamber_range[1]);
m_tempCtrl_chamber->SetMinSize(TEMP_CTRL_MIN_SIZE);
m_tempCtrl_chamber->SetBorderWidth(FromDIP(2));
m_tempCtrl_chamber->SetTextColor(tempinput_text_colour);
m_tempCtrl_chamber->SetBorderColor(tempinput_border_colour);
sizer->Add(m_tempCtrl_frame, 0, wxEXPAND | wxALL, 1);
sizer->Add(m_tempCtrl_chamber, 0, wxEXPAND | wxALL, 1);
line = new StaticLine(parent);
line->SetLineColour(STATIC_BOX_LINE_COL);
sizer->Add(line, 0, wxEXPAND | wxLEFT | wxRIGHT, 12);
@ -1105,12 +1108,12 @@ void StatusBasePanel::reset_temp_misc_control()
m_tempCtrl_nozzle->GetTextCtrl()->SetValue(TEMP_BLANK_STR);
m_tempCtrl_bed->SetLabel(TEMP_BLANK_STR);
m_tempCtrl_bed->GetTextCtrl()->SetValue(TEMP_BLANK_STR);
m_tempCtrl_frame->SetLabel(TEMP_BLANK_STR);
m_tempCtrl_frame->GetTextCtrl()->SetValue(TEMP_BLANK_STR);
m_tempCtrl_chamber->SetLabel(TEMP_BLANK_STR);
m_tempCtrl_chamber->GetTextCtrl()->SetValue(TEMP_BLANK_STR);
m_button_unload->Show();
m_tempCtrl_nozzle->Enable(true);
m_tempCtrl_frame->Enable(true);
m_tempCtrl_chamber->Enable(true);
m_tempCtrl_bed->Enable(true);
// reset misc control
@ -1452,6 +1455,8 @@ StatusPanel::StatusPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, co
on_set_bed_temp();
} else if (id == m_tempCtrl_nozzle->GetType()) {
on_set_nozzle_temp();
} else if (id == m_tempCtrl_chamber->GetType()) {
on_set_chamber_temp();
}
});
@ -1469,10 +1474,12 @@ StatusPanel::StatusPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, co
m_tempCtrl_bed->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(StatusPanel::on_bed_temp_set_focus), NULL, this);
m_tempCtrl_nozzle->Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(StatusPanel::on_nozzle_temp_kill_focus), NULL, this);
m_tempCtrl_nozzle->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(StatusPanel::on_nozzle_temp_set_focus), NULL, this);
m_tempCtrl_chamber->Connect(wxEVT_KILL_FOCUS, wxFocusEventHandler(StatusPanel::on_cham_temp_kill_focus), NULL, this);
m_tempCtrl_chamber->Connect(wxEVT_SET_FOCUS, wxFocusEventHandler(StatusPanel::on_cham_temp_set_focus), NULL, this);
m_switch_lamp->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_lamp_switch), NULL, this);
m_switch_nozzle_fan->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_nozzle_fan_switch), NULL, this); // TODO
m_switch_printing_fan->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_nozzle_fan_switch), NULL, this);
m_switch_cham_fan->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_nozzle_fan_switch), NULL, this);
m_switch_cham_fan->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_nozzle_fan_switch), NULL, this);
m_bpButton_xy->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_axis_ctrl_xy), NULL, this); // TODO
m_bpButton_z_10->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_axis_ctrl_z_up_10), NULL, this);
m_bpButton_z_1->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_axis_ctrl_z_up_1), NULL, this);
@ -1732,12 +1739,15 @@ void StatusPanel::update(MachineObject *obj)
m_options_btn->Hide();
}
//support edit chamber temp
if (obj->is_function_supported(PrinterFunction::FUNC_CHAMBER_TEMP)) {
m_tempCtrl_frame->Enable();
m_tempCtrl_chamber->SetReadOnly(false);
m_tempCtrl_chamber->Enable();
} else {
m_tempCtrl_frame->SetLabel(TEMP_BLANK_STR);
m_tempCtrl_frame->GetTextCtrl()->SetValue(TEMP_BLANK_STR);
m_tempCtrl_frame->Disable();
m_tempCtrl_chamber->SetReadOnly(true);
m_tempCtrl_chamber->SetLabel(TEMP_BLANK_STR);
m_tempCtrl_chamber->GetTextCtrl()->SetValue(TEMP_BLANK_STR);
m_tempCtrl_chamber->Disable();
}
if (!obj->dev_connection_type.empty()) {
@ -1941,7 +1951,7 @@ void StatusPanel::show_printing_status(bool ctrl_area, bool temp_area)
if (!temp_area) {
m_tempCtrl_nozzle->Enable(false);
m_tempCtrl_bed->Enable(false);
m_tempCtrl_frame->Enable(false);
m_tempCtrl_chamber->Enable(false);
m_switch_speed->Enable(false);
m_switch_speed->SetValue(false);
m_switch_lamp->Enable(false);
@ -1951,7 +1961,7 @@ void StatusPanel::show_printing_status(bool ctrl_area, bool temp_area)
} else {
m_tempCtrl_nozzle->Enable();
m_tempCtrl_bed->Enable();
m_tempCtrl_frame->Enable();
m_tempCtrl_chamber->Enable();
m_switch_speed->Enable();
m_switch_speed->SetValue(true);
m_switch_lamp->Enable();
@ -1982,6 +1992,13 @@ void StatusPanel::update_temp_ctrl(MachineObject *obj)
}
m_tempCtrl_nozzle->SetCurrTemp((int) obj->nozzle_temp);
int nozzle_max_temp = 0;
if (DeviceManager::get_nozzle_max_temperature(obj->printer_type, nozzle_max_temp)) {
if (m_tempCtrl_nozzle) m_tempCtrl_nozzle->SetMaxTemp(nozzle_max_temp);
}
else {
if (m_tempCtrl_nozzle) m_tempCtrl_nozzle->SetMaxTemp(nozzle_temp_range[1]);
}
if (m_temp_nozzle_timeout > 0) {
m_temp_nozzle_timeout--;
@ -1995,8 +2012,21 @@ void StatusPanel::update_temp_ctrl(MachineObject *obj)
m_tempCtrl_nozzle->SetIconNormal();
}
m_tempCtrl_frame->SetCurrTemp(obj->chamber_temp);
m_tempCtrl_frame->SetTagTemp(obj->chamber_temp);
m_tempCtrl_chamber->SetCurrTemp(obj->chamber_temp);
// update temprature if not input temp target
if (m_temp_chamber_timeout > 0) {
m_temp_chamber_timeout--;
}
else {
if (!cham_temp_input) { m_tempCtrl_chamber->SetTagTemp(obj->chamber_temp_target); }
}
if ((obj->chamber_temp_target - obj->chamber_temp) >= TEMP_THRESHOLD_VAL) {
m_tempCtrl_chamber->SetIconActive();
}
else {
m_tempCtrl_chamber->SetIconNormal();
}
}
void StatusPanel::update_misc_ctrl(MachineObject *obj)
@ -2861,6 +2891,21 @@ void StatusPanel::on_set_nozzle_temp()
}
}
void StatusPanel::on_set_chamber_temp()
{
wxString str = m_tempCtrl_chamber->GetTextCtrl()->GetValue();
try {
long chamber_temp;
if (str.ToLong(&chamber_temp) && obj) {
set_hold_count(m_temp_chamber_timeout);
obj->command_set_chamber(chamber_temp);
}
}
catch (...) {
;
}
}
void StatusPanel::on_ams_load(SimpleEvent &event)
{
BOOST_LOG_TRIVIAL(info) << "on_ams_load";
@ -3273,6 +3318,18 @@ void StatusPanel::on_fan_changed(wxCommandEvent& event)
}
}
void StatusPanel::on_cham_temp_kill_focus(wxFocusEvent& event)
{
event.Skip();
cham_temp_input = false;
}
void StatusPanel::on_cham_temp_set_focus(wxFocusEvent& event)
{
event.Skip();
cham_temp_input = true;
}
void StatusPanel::on_bed_temp_kill_focus(wxFocusEvent &event)
{
event.Skip();
@ -3553,6 +3610,7 @@ void StatusPanel::set_default()
m_switch_lamp_timeout = 0;
m_temp_nozzle_timeout = 0;
m_temp_bed_timeout = 0;
m_temp_chamber_timeout = 0;
m_switch_nozzle_fan_timeout = 0;
m_switch_printing_fan_timeout = 0;
m_switch_cham_fan_timeout = 0;
@ -3563,7 +3621,7 @@ void StatusPanel::set_default()
m_bitmap_recording_img->Hide();
m_bitmap_vcamera_img->Hide();
m_setting_button->Show();
m_tempCtrl_frame->Show();
m_tempCtrl_chamber->Show();
m_options_btn->Show();
reset_temp_misc_control();
@ -3697,8 +3755,8 @@ void StatusPanel::msw_rescale()
m_line_nozzle->SetSize(wxSize(-1, FromDIP(1)));
m_tempCtrl_bed->SetMinSize(TEMP_CTRL_MIN_SIZE);
m_tempCtrl_bed->Rescale();
m_tempCtrl_frame->SetMinSize(TEMP_CTRL_MIN_SIZE);
m_tempCtrl_frame->Rescale();
m_tempCtrl_chamber->SetMinSize(TEMP_CTRL_MIN_SIZE);
m_tempCtrl_chamber->Rescale();
m_bitmap_speed.msw_rescale();
m_bitmap_speed_active.msw_rescale();

View file

@ -220,12 +220,13 @@ protected:
/* TempInput */
wxBoxSizer * m_misc_ctrl_sizer;
StaticBox* m_fan_panel;
TempInput * m_tempCtrl_nozzle;
int m_temp_nozzle_timeout {0};
StaticLine * m_line_nozzle;
TempInput* m_tempCtrl_nozzle;
int m_temp_nozzle_timeout{ 0 };
TempInput * m_tempCtrl_bed;
int m_temp_bed_timeout {0};
TempInput * m_tempCtrl_frame;
TempInput * m_tempCtrl_chamber;
int m_temp_chamber_timeout {0};
bool m_current_support_cham_fan{true};
FanSwitchButton *m_switch_nozzle_fan;
int m_switch_nozzle_fan_timeout{0};
@ -361,6 +362,7 @@ protected:
wxWebRequest web_request;
bool bed_temp_input = false;
bool nozzle_temp_input = false;
bool cham_temp_input = false;
int speed_lvl = 1; // 0 - 3
int speed_lvl_timeout {0};
boost::posix_time::ptime speed_dismiss_time;
@ -403,6 +405,7 @@ protected:
void on_nozzle_temp_kill_focus(wxFocusEvent &event);
void on_nozzle_temp_set_focus(wxFocusEvent &event);
void on_set_nozzle_temp();
void on_set_chamber_temp();
/* extruder apis */
void on_ams_load(SimpleEvent &event);
@ -420,6 +423,8 @@ protected:
void on_print_error_func(wxCommandEvent& event);
void on_fan_changed(wxCommandEvent& event);
void on_cham_temp_kill_focus(wxFocusEvent& event);
void on_cham_temp_set_focus(wxFocusEvent& event);
void on_switch_speed(wxCommandEvent& event);
void on_lamp_switch(wxCommandEvent &event);
void on_printing_fan_switch(wxCommandEvent &event);