@@ -43,15 +43,11 @@ def __init__(self, parent: QtCore.QObject | None = None) -> None:
4343 self .__setup_configfile ()
4444
4545 def __setup_configfile (self ) -> None :
46- """
47- Sets up local configfile variable
48-
49- Raises:
50- FileNotFoundError: File Not Found
51- """
52- self ._config_filename = CONFIG_PATH
46+ """Sets up local configfile variable"""
47+ self ._config_filename : Path | None = CONFIG_PATH
5348 if not self ._config_filename .exists ():
54- raise FileNotFoundError (("Config file not found %s" , self ._config_filename ))
49+ logger .warning ("Config file not found %s" , self ._config_filename )
50+ self ._config_filename = None
5551
5652 def _apply_patterns (self , state : bool ) -> bool :
5753 """Method that comments/uncomments the AMU_FILES from the printer.cfg according with state value
@@ -62,6 +58,10 @@ def _apply_patterns(self, state: bool) -> bool:
6258 Returns:
6359 bool: True: Success, False: Failed
6460 """
61+ if self ._config_filename is None :
62+ logger .warning ("_apply_patterns called but no config file available" )
63+ return False
64+
6565 if self ._amu_state == state :
6666 return False
6767
@@ -122,7 +122,9 @@ def set_gate_info(
122122 color (str): Filament color as hex string, e.g. ``"ff56e0"``.
123123 spool_id (int): Spoolman spool ID, or -1 if not tracked.
124124 """
125- ...
125+ self .run_gcode_signal .emit (
126+ f"MMU_GATE_MAP gate={ gate } MATERIAL={ material } COLOR={ color } SPOOLID={ spool_id } "
127+ )
126128
127129 def set_gate_material (self , gate : int , material : str ) -> None :
128130 """Set the `material` at the gate `gate`
@@ -131,6 +133,7 @@ def set_gate_material(self, gate: int, material: str) -> None:
131133 gate (int): Gate index (0-based).
132134 material (str): Filament material name, e.g. ``"PLA"``.
133135 """
136+ self .run_gcode_signal .emit (f"MMU_GATE_MAP gate={ gate } MATERIAL={ material } " )
134137
135138 def set_gate_color (self , gate : int , color : str ) -> None :
136139 """Set the `color` at the gate `gate`
@@ -139,6 +142,7 @@ def set_gate_color(self, gate: int, color: str) -> None:
139142 gate (int): Gate index (0-based).
140143 color (str): Filament color, e.g. ``"ff56e0"``.
141144 """
145+ self .run_gcode_signal .emit (f"MMU_GATE_MAP gate={ gate } COLOR={ color } " )
142146
143147 def set_gate_spool (self , gate : int , spool_id : int ) -> None :
144148 """Set the `spool_id` at the gate `gate`
@@ -147,31 +151,53 @@ def set_gate_spool(self, gate: int, spool_id: int) -> None:
147151 gate (int): Gate index (0-based).
148152 spool_id (int): Spoolman spool ID, or -1 to clear.
149153 """
154+ self .run_gcode_signal .emit (f"MMU_GATE_MAP gate={ gate } SPOOLID={ spool_id } " )
150155
151156 def home_mmu (self ) -> None :
152157 """Home the MMU selector by sending MMU_HOME."""
158+ self .run_gcode_signal .emit ("MMU_HOME" )
153159
154160 def reset_mmu (self ) -> None :
155161 """Reset the MMU and clear any pause or error state by sending MMU_RESET."""
162+ self .run_gcode_signal .emit ("MMU_RESET" )
156163
157164 def load_gate (self , gate : int ) -> None :
158165 """Load filament from the specified gate by sending MMU_LOAD
159166
160167 Args:
161168 gate (int): Gate index to select (0-based)
162169 """
170+ self .run_gcode_signal .emit (f"MMU_SELECT gate={ gate } \n MMU_LOAD" )
163171
164172 def unload (self ) -> None :
165173 """Unload the currently loaded filament by sending MMU_UNLOAD."""
166174 ...
175+ self .run_gcode_signal .emit ("MMU_UNLOAD" )
176+
177+ def eject_gate (self , gate : int ) -> None :
178+ """Fully eject filament from gate, releasing from MMU gear.
179+
180+ Args:
181+ gate: Gate index to eject from, on None to use currently selected gate.
182+ """
183+ self .run_gcode_signal .emit (f"MMU_EJECT GATE={ gate } " )
184+
185+ def eject_all_gates (self , num_gates : int ) -> None :
186+ """Fully eject filament from all gates sequentially(amu_manager.get_state().num_gates)
187+
188+ Args:
189+ num_gates: Total number of gates(from MMUState.num_gates)
190+ """
191+ cmd = "\n " .join (f"MMU_EJECT GATE={ i } " for i in range (num_gates ))
192+ self .run_gcode_signal .emit (cmd )
167193
168194 def select_tool (self , tool : int ) -> None :
169195 """Select a tool, triggering a filament change if needed.
170196
171197 Args:
172198 tool (int): Tool index to select (0-based).
173199 """
174- ...
200+ self . run_gcode_signal . emit ( f"MMU_CHANGE_TOOL TOOL= { tool } " )
175201
176202 @QtCore .pyqtSlot (dict , name = "update_mmu_state" )
177203 def update_mmu_state (self , data : dict ) -> None :
@@ -184,7 +210,11 @@ def update_mmu_state(self, data: dict) -> None:
184210 Args:
185211 data (dict): Raw MMU status or diff dict from Moonraker
186212 """
187- ...
213+ if self ._mmu_state is None :
214+ self ._mmu_state = MMUState .from_status (data )
215+ else :
216+ self ._mmu_state = self ._mmu_state .apply_diff (data )
217+ self .mmu_state_changed .emit (self ._mmu_state )
188218
189219
190220if __name__ == "__main__" :
0 commit comments