mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-30 00:45:26 -05:00
Fix AMS sync for Happy Hare printers with an unpopulated lane_data skeleton (#14798)
Happy Hare can write a lane_data entry for every gate with only the lane number set. Orca took that as the answer and showed every slot empty without asking Happy Hare's mmu object. When every lane is empty, sync now tries Happy Hare and then Creality CFS, and keeps the empty lane layout if neither reports filament. Lane data with filament in it keeps its priority.
This commit is contained in:
1 parent
e56fd1ed44
commit
58fc8a7c1f
4 files changed
+189
-24
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
enum class MoonrakerFilamentSource { None, Lanes, HappyHare, CrealityCfs, EmptyLanes };
|
||||
|
||||
// Select the first usable filament source, preserving empty lane topology.
|
||||
// Each reader fills trays and the highest slot index; failed readers own no result.
|
||||
template<class Trays, class LaneReader, class HappyHareReader, class CfsReader>
|
||||
MoonrakerFilamentSource select_moonraker_filament_data(
|
||||
Trays& trays, int& max_lane_index, LaneReader read_lanes, HappyHareReader read_happy_hare, CfsReader read_cfs)
|
||||
{
|
||||
trays.clear();
|
||||
max_lane_index = 0;
|
||||
int empty_lane_data_max_index = -1;
|
||||
if (read_lanes(trays, max_lane_index)) {
|
||||
if (std::any_of(trays.begin(), trays.end(), [](const auto& tray) { return tray.has_filament; }))
|
||||
return MoonrakerFilamentSource::Lanes;
|
||||
empty_lane_data_max_index = max_lane_index;
|
||||
}
|
||||
|
||||
trays.clear();
|
||||
max_lane_index = 0;
|
||||
if (read_happy_hare(trays, max_lane_index)) {
|
||||
max_lane_index = std::max(max_lane_index, empty_lane_data_max_index);
|
||||
return MoonrakerFilamentSource::HappyHare;
|
||||
}
|
||||
|
||||
trays.clear();
|
||||
max_lane_index = 0;
|
||||
if (read_cfs(trays, max_lane_index))
|
||||
return MoonrakerFilamentSource::CrealityCfs;
|
||||
|
||||
trays.clear();
|
||||
max_lane_index = empty_lane_data_max_index;
|
||||
if (empty_lane_data_max_index >= 0)
|
||||
return MoonrakerFilamentSource::EmptyLanes;
|
||||
max_lane_index = 0;
|
||||
return MoonrakerFilamentSource::None;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "MoonrakerPrinterAgent.hpp"
|
||||
#include "MoonrakerFilamentSources.hpp"
|
||||
#include "AsioUtils.hpp"
|
||||
#include "CrealityCfs.hpp"
|
||||
#include "Http.hpp"
|
||||
@@ -747,38 +748,35 @@ bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id, FilamentSync
|
||||
{
|
||||
std::vector<AmsTrayData> trays;
|
||||
int max_lane_index = 0;
|
||||
const auto source = select_moonraker_filament_data(trays, max_lane_index,
|
||||
[this](auto& out, int& index) { return fetch_moonraker_filament_data(out, index); },
|
||||
[this](auto& out, int& index) { return fetch_hh_filament_info(out, index); },
|
||||
[this](auto& out, int& index) { return fetch_creality_cfs_data(out, index); });
|
||||
|
||||
// Try Moonraker filament data (more generic, supports any filament changer
|
||||
// software that reports lane data to Moonraker like AFC and recent Happy
|
||||
// Hare as of Feb 15, 2026)
|
||||
if (fetch_moonraker_filament_data(trays, max_lane_index)) {
|
||||
switch (source) {
|
||||
case MoonrakerFilamentSource::Lanes:
|
||||
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::fetch_filament_info: Detected Moonraker filament system with "
|
||||
<< (max_lane_index + 1) << " lanes";
|
||||
int ams_count = (max_lane_index + 4) / 4;
|
||||
build_ams_payload(ams_count, max_lane_index, trays);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Attempt Happy Hare first (more widely adopted, supports more filament changers)
|
||||
if (fetch_hh_filament_info(trays, max_lane_index)) {
|
||||
break;
|
||||
case MoonrakerFilamentSource::HappyHare:
|
||||
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::fetch_filament_info: Detected Happy Hare MMU with "
|
||||
<< (max_lane_index + 1) << " gates";
|
||||
int ams_count = (max_lane_index + 4) / 4;
|
||||
build_ams_payload(ams_count, max_lane_index, trays);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Creality Hi exposes CFS slots as a Moonraker box printer object.
|
||||
if (fetch_creality_cfs_data(trays, max_lane_index)) {
|
||||
<< trays.size() << " loaded gates and " << (max_lane_index + 1) << " slots";
|
||||
break;
|
||||
case MoonrakerFilamentSource::CrealityCfs:
|
||||
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::fetch_filament_info: Detected Creality CFS with "
|
||||
<< (max_lane_index + 1) << " slots";
|
||||
build_ams_payload((max_lane_index + 4) / 4, max_lane_index, trays);
|
||||
return true;
|
||||
break;
|
||||
case MoonrakerFilamentSource::EmptyLanes:
|
||||
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::fetch_filament_info: Preserving empty lane_data topology with "
|
||||
<< (max_lane_index + 1) << " lanes";
|
||||
break;
|
||||
case MoonrakerFilamentSource::None:
|
||||
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::fetch_filament_info: No MMU system detected";
|
||||
return false;
|
||||
}
|
||||
|
||||
// No MMU detected - this is normal for printers without MMU, not an error.
|
||||
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent::fetch_filament_info: No MMU system detected";
|
||||
return false;
|
||||
build_ams_payload((max_lane_index + 4) / 4, max_lane_index, trays);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string MoonrakerPrinterAgent::trim_and_upper(const std::string& input)
|
||||
|
||||
@@ -11,6 +11,7 @@ add_executable(${_TEST_NAME}_tests
|
||||
test_dev_mapping.cpp
|
||||
test_device_access.cpp
|
||||
test_moonraker_printer_agent.cpp
|
||||
test_moonraker_filament_sources.cpp
|
||||
test_snapmaker_filament_match.cpp
|
||||
test_network_discovery.cpp
|
||||
test_filament_bitmap_utils.cpp
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <catch2/generators/catch_generators.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "slic3r/Utils/MoonrakerFilamentSources.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
namespace {
|
||||
struct Tray
|
||||
{
|
||||
bool has_filament;
|
||||
int slot_index;
|
||||
std::string material;
|
||||
};
|
||||
|
||||
struct Reader
|
||||
{
|
||||
bool success = false;
|
||||
std::vector<Tray> result;
|
||||
int max_index = 0;
|
||||
int calls = 0;
|
||||
bool operator()(std::vector<Tray>& trays, int& max_lane_index)
|
||||
{
|
||||
++calls;
|
||||
trays = result;
|
||||
max_lane_index = max_index;
|
||||
return success;
|
||||
}
|
||||
};
|
||||
|
||||
struct Sources
|
||||
{
|
||||
Reader lanes, hh, cfs;
|
||||
std::vector<Tray> trays;
|
||||
int max_index = 0;
|
||||
MoonrakerFilamentSource read()
|
||||
{
|
||||
return select_moonraker_filament_data(
|
||||
trays, max_index, [&](auto& out, int& index) { return lanes(out, index); },
|
||||
[&](auto& out, int& index) { return hh(out, index); }, [&](auto& out, int& index) { return cfs(out, index); });
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Populated lane data keeps priority over Happy Hare and CFS", "[MoonrakerFilamentSources]")
|
||||
{
|
||||
Sources sources;
|
||||
sources.lanes = {true, {{false, 0, ""}, {true, 4, "PLA"}}, 7};
|
||||
sources.hh = {true, {{true, 2, "PETG"}}, 2};
|
||||
sources.cfs = {true, {{true, 1, "ABS"}}, 1};
|
||||
REQUIRE(sources.read() == MoonrakerFilamentSource::Lanes);
|
||||
REQUIRE(sources.trays.size() == 2);
|
||||
CHECK(sources.trays[1].material == "PLA");
|
||||
CHECK(sources.max_index == 7);
|
||||
CHECK(sources.hh.calls == 0);
|
||||
CHECK(sources.cfs.calls == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("Empty lane data lets Happy Hare supply loaded gates and keeps the widest topology", "[MoonrakerFilamentSources][Regression]")
|
||||
{
|
||||
Sources sources;
|
||||
const int loaded_gate = GENERATE(2, 9);
|
||||
sources.lanes = {true, {{false, 0, ""}, {false, 7, ""}}, 7};
|
||||
sources.hh = {true, {{true, loaded_gate, "PETG"}}, loaded_gate};
|
||||
REQUIRE(sources.read() == MoonrakerFilamentSource::HappyHare);
|
||||
REQUIRE(sources.trays.size() == 1);
|
||||
CHECK(sources.trays.front().has_filament);
|
||||
CHECK(sources.trays.front().slot_index == loaded_gate);
|
||||
CHECK(sources.trays.front().material == "PETG");
|
||||
CHECK(sources.max_index == (loaded_gate > 7 ? loaded_gate : 7));
|
||||
CHECK(sources.cfs.calls == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("An empty lane topology survives an unavailable Happy Hare and CFS", "[MoonrakerFilamentSources][Regression]")
|
||||
{
|
||||
Sources sources;
|
||||
sources.lanes = {true, {{false, 0, ""}, {false, 7, ""}}, 7};
|
||||
sources.hh = {false, {{true, 19, "discard partial HH"}}, 19};
|
||||
sources.cfs = {false, {{true, 23, "discard partial CFS"}}, 23};
|
||||
REQUIRE(sources.read() == MoonrakerFilamentSource::EmptyLanes);
|
||||
CHECK(sources.trays.empty());
|
||||
CHECK(sources.max_index == 7);
|
||||
CHECK(sources.hh.calls == 1);
|
||||
CHECK(sources.cfs.calls == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("CFS stays reachable after empty lanes and failed Happy Hare", "[MoonrakerFilamentSources][Regression]")
|
||||
{
|
||||
Sources sources;
|
||||
sources.lanes = {true, {{false, 7, ""}}, 7};
|
||||
sources.hh = {false, {{true, 12, "discard partial HH"}}, 12};
|
||||
sources.cfs = {true, {{true, 1, "ABS"}}, 3};
|
||||
REQUIRE(sources.read() == MoonrakerFilamentSource::CrealityCfs);
|
||||
REQUIRE(sources.trays.size() == 1);
|
||||
CHECK(sources.trays.front().material == "ABS");
|
||||
CHECK(sources.max_index == 3);
|
||||
}
|
||||
|
||||
TEST_CASE("A missing lane namespace leaves the existing fallback sources available", "[MoonrakerFilamentSources]")
|
||||
{
|
||||
Sources sources;
|
||||
sources.lanes = {false, {{true, 27, "discard invalid lanes"}}, 27};
|
||||
sources.hh = {true, {{true, 4, "PETG"}}, 4};
|
||||
REQUIRE(sources.read() == MoonrakerFilamentSource::HappyHare);
|
||||
REQUIRE(sources.trays.size() == 1);
|
||||
CHECK(sources.max_index == 4);
|
||||
CHECK(sources.cfs.calls == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("No successful source leaves no filament system or partial reader data", "[MoonrakerFilamentSources]")
|
||||
{
|
||||
Sources sources;
|
||||
sources.lanes = {false, {{true, 27, "invalid lanes"}}, 27};
|
||||
sources.hh = {false, {{true, 19, "partial HH"}}, 19};
|
||||
sources.cfs = {false, {{true, 23, "partial CFS"}}, 23};
|
||||
CHECK(sources.read() == MoonrakerFilamentSource::None);
|
||||
CHECK(sources.trays.empty());
|
||||
CHECK(sources.max_index == 0);
|
||||
}
|
||||
Reference in new issue
Block a user