mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-10 18:56:13 +00:00
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 <niallain@gmail.com>
This commit is contained in:
@@ -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.
|
// 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));
|
auto http = Http::get(std::move(url));
|
||||||
set_auth(http);
|
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 %
|
BOOST_LOG_TRIVIAL(error) << boost::format("%1%: Error getting version: %2%, HTTP %3%, body: `%4%`") % name % error % status %
|
||||||
body;
|
body;
|
||||||
res = false;
|
res = false;
|
||||||
@@ -96,6 +97,15 @@ bool CrealityPrint::test(wxString& msg) const
|
|||||||
})
|
})
|
||||||
.on_complete([&, this](std::string body, unsigned) {
|
.on_complete([&, this](std::string body, unsigned) {
|
||||||
BOOST_LOG_TRIVIAL(debug) << boost::format("%1%: Got version: %2%") % name % body;
|
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<std::string>();
|
||||||
|
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
|
#ifdef WIN32
|
||||||
.ssl_revoke_best_effort(m_ssl_revoke_best_effort)
|
.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;
|
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
|
bool CrealityPrint::start_print(wxString &msg, const std::string &filename) const
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
virtual bool test(wxString& curl_msg) const override;
|
virtual bool test(wxString& curl_msg) const override;
|
||||||
PrintHostPostUploadActions get_post_upload_actions() const;
|
PrintHostPostUploadActions get_post_upload_actions() const;
|
||||||
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override;
|
bool upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, ErrorFn error_fn, InfoFn info_fn) const override;
|
||||||
|
bool supports_multi_color_print() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void set_auth(Http& http) const;
|
virtual void set_auth(Http& http) const;
|
||||||
@@ -39,10 +40,12 @@ private:
|
|||||||
std::string m_cafile;
|
std::string m_cafile;
|
||||||
std::string m_web_ui;
|
std::string m_web_ui;
|
||||||
bool m_ssl_revoke_best_effort;
|
bool m_ssl_revoke_best_effort;
|
||||||
|
mutable std::string m_model;
|
||||||
|
|
||||||
std::string make_url(const std::string& path) const;
|
std::string make_url(const std::string& path) const;
|
||||||
bool start_print(wxString& msg, const std::string& path) const;
|
bool start_print(wxString& msg, const std::string& path) const;
|
||||||
std::string safe_filename(const std::string& filename) const;
|
std::string safe_filename(const std::string& filename) const;
|
||||||
|
void query_model() const;
|
||||||
};
|
};
|
||||||
} // namespace Slic3r
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user