Add Creality K-series LAN discovery via DNS-SD mDNS

When a user adds a Creality K-series printer (host_type=crealityprint)
and clicks the existing "Browse" button in the Physical Printer dialog,
dispatch to a new CrealityDiscoveryDialog that finds K2 / K2 Plus /
K2 Pro printers on the LAN automatically. For other host types the
button keeps its existing BonjourDialog behaviour.

  CrealityHostDiscovery (src/slic3r/Utils/CrealityHostDiscovery.{hpp,cpp})

    Wraps the vendored cxmdns wrapper from the previous commit:

      static std::vector<CrealityHost> scan(bool probe_info = true);

    Calls cxnet::syncDiscoveryService({"Creality", "creality"}) to find
    K-series printers via DNS-SD, dedupes by IP, then optionally HTTP
    GETs http://<ip>/info on each match to fetch the model code
    (F008 = K2 Plus, F012 = K2 Pro, F021 = K2) and MAC. Returns enriched
    {ip, hostname, model_code, model_name, mac, cfs_capable} entries.

  CrealityDiscoveryDialog (src/slic3r/GUI/CrealityDiscoveryDialog.{hpp,cpp})

    Modal dialog with a wxListView showing Model / Hostname / IP per
    discovered host. Runs CrealityHostDiscovery::scan() synchronously
    with wxBusyCursor + wxWindowDisabler (5-10s total wait). User picks
    one, dialog returns the IP via selected_ip().

  PhysicalPrinterDialog (src/slic3r/GUI/PhysicalPrinterDialog.cpp)

    The "Browse" button's click handler now reads host_type from the
    edited config. If htCrealityPrint, opens CrealityDiscoveryDialog
    and writes "http://<ip>" into the print_host field. Otherwise the
    existing BonjourDialog path runs unchanged -- no behaviour change
    for OctoPrint / Moonraker / Klipper users.

No new UI surface: one existing button now does the right thing per
host_type, mirroring how Creality Print discovers its own printers.
This commit is contained in:
grant0013
2026-05-19 16:28:41 +00:00
parent d6cffbba26
commit 598df9ff0b
6 changed files with 372 additions and 1 deletions

View File

@@ -35,6 +35,7 @@
#include "RemovableDriveManager.hpp"
#include "BitmapCache.hpp"
#include "BonjourDialog.hpp"
#include "CrealityDiscoveryDialog.hpp"
#include "MsgDialog.hpp"
#include "OAuthDialog.hpp"
#include "SimplyPrint.hpp"
@@ -200,10 +201,28 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
return sizer;
};
auto printhost_browse = [=](wxWindow* parent)
auto printhost_browse = [=](wxWindow* parent)
{
auto sizer = create_sizer_with_btn(parent, &m_printhost_browse_btn, "printer_host_browser", _L("Browse") + " " + dots);
m_printhost_browse_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent& e) {
// Creality K-series printers announce themselves via DNS-SD under a
// per-device-unique service type _Creality-<MAC-hex>._udp, so the
// standard fixed-service-name Bonjour browser does not find them.
// Dispatch to the Creality-specific scanner instead.
const auto* host_type_opt = m_config->option<ConfigOptionEnum<PrintHostType>>("host_type");
const auto host_type = host_type_opt ? host_type_opt->value : htOctoPrint;
if (host_type == htCrealityPrint) {
CrealityDiscoveryDialog dialog(this);
if (dialog.ShowModal() == wxID_OK && !dialog.selected_ip().empty()) {
// set_value expects the value wrapped as wxString -- TextCtrl::set_value
// any_casts to wxString, so a raw std::string throws bad_any_cast.
wxString new_url = wxString::FromUTF8("http://" + dialog.selected_ip());
m_optgroup->set_value("print_host", new_url, true);
m_optgroup->get_field("print_host")->field_changed();
}
return;
}
BonjourDialog dialog(this, Preset::printer_technology(*m_config));
if (dialog.show_and_lookup()) {
m_optgroup->set_value("print_host", dialog.get_selected(), true);