fix(ams): leerer AMS-Slot zeigt kein altes Filament mehr (Moonraker/KX-Bridge)

Bei Pull-Mode-Agents (Moonraker/AMS-Lite) wird das DevAmsTray-Objekt
zwischen Updates gemergt statt neu aufgebaut. Ein Slot, der zuvor belegt
war und jetzt leer ist (placeholder bzw. exist-Bit nicht gesetzt), behielt
Name/Typ/Farbe des alten Filaments und wurde als belegt gerendert.

- ParseV1_0: is_slot_placeholder jedes Update neu setzen; bei leerem Slot
  setting_id/m_fila_type/color/sub_brands/cols aktiv zuruecksetzen.
- AMSItem::parse_ams_info: Placeholder-Slot unabhaengig von stale is_exists
  als leer (grau) rendern, Position bleibt erhalten.
This commit is contained in:
thysson2701
2026-06-16 19:52:09 +02:00
parent 3fd461c804
commit 0fa9194813
2 changed files with 26 additions and 4 deletions

View File

@@ -612,9 +612,10 @@ void DevFilaSystemParser::ParseV1_0(const json& jj, MachineObject* obj, DevFilaS
{
curr_tray->remain = -1;
}
if (tray_it->contains("tray_slot_placeholder")) {
curr_tray->is_slot_placeholder = true;
}
// Reset the placeholder flag every update so a slot that
// was empty before but is now loaded does not stay marked
// as a placeholder (and vice versa).
curr_tray->is_slot_placeholder = tray_it->contains("tray_slot_placeholder");
int ams_id_int = 0;
int tray_id_int = 0;
try
@@ -638,6 +639,21 @@ void DevFilaSystemParser::ParseV1_0(const json& jj, MachineObject* obj, DevFilaS
catch (...)
{
}
// An empty slot (placeholder or exist-bit not set) must not
// keep the previously loaded filament's name/type/color from
// an earlier update. The Moonraker/AMS-Lite bridge reports
// empty slots with a placeholder + cleared fields, but the
// tray object is merged (not rebuilt) between updates, so the
// stale values would otherwise survive and the slot would
// render as loaded. Reset them explicitly.
if (curr_tray->is_slot_placeholder || !curr_tray->is_exists)
{
curr_tray->setting_id = "";
curr_tray->m_fila_type = "";
curr_tray->color = "";
curr_tray->sub_brands = "";
curr_tray->cols.clear();
}
if (tray_it->contains("setting_id"))
{
curr_tray->filament_setting_id = (*tray_it)["setting_id"].get<std::string>();

View File

@@ -69,7 +69,13 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, DevAms *ams, bool remain_flag,
auto it = ams->GetTrays().find(std::to_string(i));
Caninfo info;
// tray is exists
if (it != ams->GetTrays().end() && it->second->is_exists) {
// A placeholder slot is explicitly empty (reported by the Moonraker/AMS-Lite
// bridge): treat it as empty regardless of any stale is_exists/filament data
// left over from a previous update, so it renders grey at its position
// instead of showing the previously loaded filament.
const bool tray_present = it != ams->GetTrays().end() && it->second->is_exists
&& !it->second->is_slot_placeholder;
if (tray_present) {
if (it->second->is_tray_info_ready()) {
info.can_id = it->second->id;
info.ctype = it->second->ctype;