diff --git a/resources/config.json b/resources/config.json index 767235566..73890dcff 100644 --- a/resources/config.json +++ b/resources/config.json @@ -2,11 +2,17 @@ "printers": [ { "display_name": "Bambu Lab X1", + "func": { + "FUNC_LOCAL_TUNNEL": false + }, "model_id": "BL-P002", "printer_type": "3DPrinter-X1" }, { "display_name": "Bambu Lab X1 Carbon", + "func": { + "FUNC_LOCAL_TUNNEL": false + }, "model_id": "BL-P001", "printer_type": "3DPrinter-X1-Carbon" } diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index c728942dc..1ddadcb5e 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -1702,6 +1702,18 @@ bool MachineObject::is_function_supported(PrinterFunction func) case FUNC_CHAMBER_TEMP: func_name = "FUNC_CHAMBER_TEMP"; break; + case FUNC_CAMERA_VIDEO: + func_name = "FUNC_CAMERA_VIDEO"; + break; + case FUNC_MEDIA_FILE: + func_name = "FUNC_MEDIA_FILE"; + break; + case FUNC_REMOTE_TUNNEL: + func_name = "FUNC_REMOTE_TUNNEL"; + break; + case FUNC_LOCAL_TUNNEL: + func_name = "FUNC_LOCAL_TUNNEL"; + break; default: return true; } diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 077a25b87..59c9a13a9 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -65,6 +65,10 @@ enum PrinterFunction { FUNC_FLOW_CALIBRATION, FUNC_AUTO_LEVELING, FUNC_CHAMBER_TEMP, + FUNC_CAMERA_VIDEO, + FUNC_MEDIA_FILE, + FUNC_REMOTE_TUNNEL, + FUNC_LOCAL_TUNNEL, FUNC_MAX }; diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index a4cb719b7..c8c34b00f 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -174,6 +174,17 @@ MediaFilePanel::~MediaFilePanel() void MediaFilePanel::SetMachineObject(MachineObject* obj) { std::string machine = obj ? obj->dev_id : ""; + if (obj && obj->is_function_supported(PrinterFunction::FUNC_MEDIA_FILE)) { + m_lan_mode = obj->is_lan_mode_printer(); + m_lan_ip = obj->is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL) ? obj->dev_ip : ""; + m_lan_passwd = obj->access_code; + m_tutk_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL); + } else { + m_lan_mode = false; + m_lan_ip.clear(); + m_lan_passwd.clear(); + m_tutk_support = true; + } if (machine == m_machine) return; m_machine = machine; @@ -185,6 +196,8 @@ void MediaFilePanel::SetMachineObject(MachineObject* obj) } if (m_machine.empty()) { m_image_grid->SetStatus(m_bmp_failed.bmp(), _L("No printers.")); + } else if (m_lan_ip.empty() && (m_lan_mode && !m_tutk_support)) { + m_image_grid->SetStatus(m_bmp_failed.bmp(), _L("Not supported.")); } else { boost::shared_ptr fs(new PrinterFileSystem); m_image_grid->SetFileType(m_last_type); @@ -259,7 +272,17 @@ void MediaFilePanel::modeChanged(wxCommandEvent& e1) void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) { - NetworkAgent* agent = wxGetApp().getAgent(); + if (!m_lan_ip.empty()) { + std::string url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd; + boost::shared_ptr fs(wfs.lock()); + if (!fs || fs != m_image_grid->GetFileSystem()) return; + fs->SetUrl(url); + return; + } + if (m_lan_mode && !m_tutk_support) { // not support tutk + return; + } + NetworkAgent *agent = wxGetApp().getAgent(); if (agent) { agent->get_camera_url(m_machine, [this, wfs](std::string url) { diff --git a/src/slic3r/GUI/MediaFilePanel.h b/src/slic3r/GUI/MediaFilePanel.h index c6c1f0d9a..3b47ac8d9 100644 --- a/src/slic3r/GUI/MediaFilePanel.h +++ b/src/slic3r/GUI/MediaFilePanel.h @@ -65,7 +65,13 @@ private: ::Button *m_button_management = nullptr; std::string m_machine; - ImageGrid * m_image_grid = nullptr; + std::string m_lan_ip; + std::string m_lan_user; + std::string m_lan_passwd; + bool m_lan_mode = false; + bool m_tutk_support = false; + + ImageGrid * m_image_grid = nullptr; int m_last_mode = 0; int m_last_type = 0; diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index a1a9d0272..5126aa0e7 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -48,6 +48,9 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w }; parent->Bind(wxEVT_SHOW, onShowHide); parent->GetParent()->GetParent()->Bind(wxEVT_SHOW, onShowHide); + + m_lan_user = "bblp"; + m_lan_passwd = "bblp"; } MediaPlayCtrl::~MediaPlayCtrl() @@ -63,6 +66,17 @@ MediaPlayCtrl::~MediaPlayCtrl() void MediaPlayCtrl::SetMachineObject(MachineObject* obj) { std::string machine = obj ? obj->dev_id : ""; + if (obj && obj->is_function_supported(PrinterFunction::FUNC_CAMERA_VIDEO)) { + m_lan_mode = obj->is_lan_mode_printer(); + m_lan_ip = obj->is_function_supported(PrinterFunction::FUNC_LOCAL_TUNNEL) ? obj->dev_ip : ""; + m_lan_passwd = obj->access_code; + m_tutk_support = obj->is_function_supported(PrinterFunction::FUNC_REMOTE_TUNNEL); + } else { + m_lan_mode = false; + m_lan_ip.clear(); + m_lan_passwd.clear(); + m_tutk_support = true; + } if (machine == m_machine) { if (m_last_state == MEDIASTATE_IDLE && m_next_retry.IsValid() && wxDateTime::Now() >= m_next_retry) Play(); @@ -92,10 +106,36 @@ void MediaPlayCtrl::Play() if (m_last_state != MEDIASTATE_IDLE) { return; } + m_last_state = MEDIASTATE_INITIALIZING; m_button_play->SetIcon("media_stop"); SetStatus(_L("Initializing...")); + if (!m_lan_ip.empty()) { + m_url = "bambu:///local/" + m_lan_ip + ".?port=6000&user=" + m_lan_user + "&passwd=" + m_lan_passwd; + m_last_state = MEDIASTATE_LOADING; + SetStatus(_L("Loading...")); + if (wxGetApp().app_config->get("dump_video") == "true") { + std::string file_h264 = data_dir() + "/video.h264"; + std::string file_info = data_dir() + "/video.info"; + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl dump video to " << file_h264; + // closed by BambuSource + FILE *dump_h264_file = boost::nowide::fopen(file_h264.c_str(), "wb"); + FILE *dump_info_file = boost::nowide::fopen(file_info.c_str(), "wb"); + m_url = m_url + "&dump_h264=" + boost::lexical_cast(dump_h264_file); + m_url = m_url + "&dump_info=" + boost::lexical_cast(dump_info_file); + } + boost::unique_lock lock(m_mutex); + m_tasks.push_back(m_url); + m_cond.notify_all(); + return; + } + + if (m_lan_mode && !m_tutk_support) { // not support tutk + Stop(); + SetStatus(_L("Initialize failed (Not supported)!")); + return; + } NetworkAgent* agent = wxGetApp().getAgent(); if (agent) { diff --git a/src/slic3r/GUI/MediaPlayCtrl.h b/src/slic3r/GUI/MediaPlayCtrl.h index caef7dfce..f8f3945b3 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.h +++ b/src/slic3r/GUI/MediaPlayCtrl.h @@ -58,6 +58,11 @@ private: wxMediaCtrl2 * m_media_ctrl; wxMediaState m_last_state = MEDIASTATE_IDLE; std::string m_machine; + std::string m_lan_ip; + std::string m_lan_user; + std::string m_lan_passwd; + bool m_lan_mode = false; + bool m_tutk_support = false; wxString m_url; std::deque m_tasks;