Skip to content

Commit

Permalink
toolhead remapping improved
Browse files Browse the repository at this point in the history
  • Loading branch information
HelgeKeck committed Apr 15, 2024
1 parent 80ff1cd commit 9711b9c
Showing 1 changed file with 40 additions and 31 deletions.
71 changes: 40 additions & 31 deletions klippy/rmmu.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,20 +433,10 @@ def home_filament(self, filament):
#####
def change_filament(self, tool, x, y):
# handle toolhead mapping
if len(self.toolhead_mapping) > 0:
for toolhead_map in self.toolhead_mapping:
if tool in toolhead_map:
for t in toolhead_map:
if tool != t:
tool = toolhead_map[t]
break
tool = self.get_remapped_toolhead(tool)

# handle spool mapping
if len(self.spool_mapping) > 0:
for spool_map in self.spool_mapping:
if tool in spool_map:
tool = spool_map[tool]
break
tool = self.get_remapped_spool(tool)

# we ignore the first filament change since we have already loaded the first filament during the start print macro
if self.filament_changes > 0:
Expand Down Expand Up @@ -934,9 +924,10 @@ def test_filaments(self, param):
for i in range(0, self.tool_count):
toolhead_used = param.get('T' + str(i), "true")
if toolhead_used == "true":
if not self.test_filament(i):
toolhead = self.get_remapped_toolhead(i)
if not self.test_filament(toolhead):
self.select_filament(-1)
self.gcode.run_script_from_command('_RMMU_ON_START_PRINT_FILAMENT_TEST_FAILED TOOLHEAD=' + str(i))
self.gcode.run_script_from_command('_RMMU_ON_START_PRINT_FILAMENT_TEST_FAILED TOOLHEAD=' + str(toolhead))
return

# release idler
Expand Down Expand Up @@ -1084,23 +1075,6 @@ def join_filament(self, param):
self.spool_joins.append(new_spools)
self.echo_spool_join()

def echo_spool_join(self):
if len(self.spool_joins) > 0:
result = "Joining filament:\n"
for spool_join in self.spool_joins:
result += "Spools: " + ",".join(str(i) for i in spool_join) + "\n"
self.gcode.respond_raw(result)
return
result = "Joining deactivated!\n\n"
result += "Deactivate joining with:\n"
result += "JOIN_FILAMENT SPOOLS=\n\n"
result += "Join spool 1, 2 and 3 with:\n"
result += "JOIN_FILAMENT SPOOLS=1,2,3\n\n"
result += "Join spool 1 and 2 and then 0 and 3 with:\n"
result += "JOIN_FILAMENT SPOOLS=1,2\n"
result += "JOIN_FILAMENT SPOOLS=0,3\n"
self.gcode.respond_raw(result)

def join_spool(self, spool_join, tool):
for spool in spool_join:
if spool != tool:
Expand All @@ -1127,6 +1101,31 @@ def join_spool(self, spool_join, tool):
self.ratos_echo("Spool " + str(spool) + " not available!")
return False

def get_remapped_spool(self, tool):
if len(self.spool_mapping) > 0:
for spool_map in self.spool_mapping:
if tool in spool_map:
tool = spool_map[tool]
break
return tool

def echo_spool_join(self):
if len(self.spool_joins) > 0:
result = "Joining filament:\n"
for spool_join in self.spool_joins:
result += "Spools: " + ",".join(str(i) for i in spool_join) + "\n"
self.gcode.respond_raw(result)
return
result = "Joining deactivated!\n\n"
result += "Deactivate joining with:\n"
result += "JOIN_FILAMENT SPOOLS=\n\n"
result += "Join spool 1, 2 and 3 with:\n"
result += "JOIN_FILAMENT SPOOLS=1,2,3\n\n"
result += "Join spool 1 and 2 and then 0 and 3 with:\n"
result += "JOIN_FILAMENT SPOOLS=1,2\n"
result += "JOIN_FILAMENT SPOOLS=0,3\n"
self.gcode.respond_raw(result)

#####
# Toolhead mapping
#####
Expand Down Expand Up @@ -1172,6 +1171,16 @@ def remap_toolhead(self, param):
self.toolhead_mapping.append(new_toolhead_map)
self.echo_toolhead_mapping()

def get_remapped_toolhead(self, tool):
if len(self.toolhead_mapping) > 0:
for toolhead_map in self.toolhead_mapping:
if tool in toolhead_map:
for t in toolhead_map:
if tool != t:
tool = t
break
return tool

def echo_toolhead_mapping(self):
if len(self.toolhead_mapping) > 0:
result = "Remap toolheads:\n"
Expand Down

0 comments on commit 9711b9c

Please sign in to comment.