From aa9d472d9e4b8e30b0490220c06c393ae5d6d9b9 Mon Sep 17 00:00:00 2001 From: Igor Mammedov Date: Mon, 13 Apr 2026 21:56:46 +0200 Subject: [PATCH] CrealityPrint: add model detection from /info endpoint Parse the model field from the /info JSON response to enable model-specific features. Add supports_multi_color_print() which returns true for K2-platform printers (K2 Plus, K2 Pro, K2). Signed-off-by: Igor Mammedov --- src/slic3r/Utils/CrealityPrint.cpp | 30 +++++++++++++++++++++++++++++- src/slic3r/Utils/CrealityPrint.hpp | 3 +++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/slic3r/Utils/CrealityPrint.cpp b/src/slic3r/Utils/CrealityPrint.cpp index 35ab26743c..00399cf34f 100644 --- a/src/slic3r/Utils/CrealityPrint.cpp +++ b/src/slic3r/Utils/CrealityPrint.cpp @@ -88,7 +88,8 @@ bool CrealityPrint::test(wxString& msg) const // Here we do not have to add custom "Host" header - the url contains host filled by user and libCurl will set the header by itself. auto http = Http::get(std::move(url)); set_auth(http); - http.on_error([&](std::string body, std::string error, unsigned status) { + http.timeout_max(5) + .on_error([&](std::string body, std::string error, unsigned status) { BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status % body; res = false; @@ -96,6 +97,15 @@ bool CrealityPrint::test(wxString& msg) const }) .on_complete([&, this](std::string body, unsigned) { BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got version: %2%") % name % body; + try { + auto info = json::parse(body); + if (info.contains("model")) { + m_model = info["model"].get(); + BOOST_LOG_TRIVIAL(info) << boost::format("%1%: Detected model: %2%") % name % m_model; + } + } catch (const json::exception& e) { + BOOST_LOG_TRIVIAL(warning) << boost::format("%1%: Failed to parse /info response: %2%") % name % e.what(); + } }) #ifdef WIN32 .ssl_revoke_best_effort(m_ssl_revoke_best_effort) @@ -186,6 +196,24 @@ std::string CrealityPrint::safe_filename(const std::string &filename) const return safe_filename; } +void CrealityPrint::query_model() const +{ + if (!m_model.empty()) + return; + + wxString msg; + test(msg); +} + +bool CrealityPrint::supports_multi_color_print() const +{ + query_model(); + // K2-platform printers with CFS support + return m_model == "F008" // K2 Plus + || m_model == "F012" // K2 Pro + || m_model == "F021"; // K2 +} + bool CrealityPrint::start_print(wxString &msg, const std::string &filename) const { try { diff --git a/src/slic3r/Utils/CrealityPrint.hpp b/src/slic3r/Utils/CrealityPrint.hpp index b80fe27de5..08c1bb883d 100644 --- a/src/slic3r/Utils/CrealityPrint.hpp +++ b/src/slic3r/Utils/CrealityPrint.hpp @@ -29,6 +29,7 @@ public: virtual bool test(wxString& curl_msg) const override; PrintHostPostUploadActions get_post_upload_actions() const; bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override; + bool supports_multi_color_print() const; protected: virtual void set_auth(Http& http) const; @@ -39,10 +40,12 @@ private: std::string m_cafile; std::string m_web_ui; bool m_ssl_revoke_best_effort; + mutable std::string m_model; std::string make_url(const std::string& path) const; bool start_print(wxString& msg, const std::string& path) const; std::string safe_filename(const std::string& filename) const; + void query_model() const; }; } // namespace Slic3r