Skip to content

Commit

Permalink
Update status name to match what fluidd is expecting.
Browse files Browse the repository at this point in the history
  • Loading branch information
viesturz committed Jul 20, 2023
1 parent c08e404 commit 3e9aa4d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/Status_Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ The following information is available in the `tool` object:
- `toolchanger`: The name of the toolchanger this tool is attached to.
- `extruder`: Name of the extruder used for this tool.
- `fan`: Name of the part fan used for this tool.
- `selected`: If this tool is currently the selected tool.
- `active`: If this tool is currently the selected tool.
- `mounted`: If this tool is currently mounted, the tool may be mounted but
not selected. Some reasons for that can be that a child tool is selected, or
lazy unmounting is configured.
Expand Down
25 changes: 21 additions & 4 deletions klippy/extras/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def get_status(self, eventtime):
'tool_number': self.tool_number,
'extruder': self.extruder_name,
'fan': self.fan_name,
'selected': self.toolchanger.get_selected_tool() == self,
'active': self.toolchanger.get_selected_tool() == self,
'gcode_x_offset': self.gcode_x_offset if self.gcode_x_offset else 0.0,
'gcode_y_offset': self.gcode_y_offset if self.gcode_y_offset else 0.0,
'gcode_z_offset': self.gcode_z_offset if self.gcode_z_offset else 0.0,
Expand All @@ -77,10 +77,17 @@ def assign_tool(self, number, replace = False):
self.tool_number = number
self.toolchanger.assign_tool(self, number, prev_number, replace)
gcode = self.printer.lookup_object('gcode')
gcode.register_command('T%d' % (number), None)
gcode.register_command('T%d' % (number), self.cmd_T, desc=self.cmd_T_help)
cmd_name = 'T%d' % (number)
gcode.register_command(cmd_name, None)
gcode.register_command(cmd_name, self.cmd_T, desc=self.cmd_T_help % (number))
# Pretend to be a macro, to allow discovery by UIs.
macro_obj_name = "gcode_macro %s" % (cmd_name,)
if macro_obj_name not in self.printer.objects:
self.printer.add_object(macro_obj_name, self)
else:
self.printer.lookup_object(macro_obj_name).set_tool(self)

cmd_T_help = 'Select tool'
cmd_T_help = 'Select tool %d'
def cmd_T(self, gcmd):
self.toolchanger.select_tool(gcmd, self, self.t_command_restore_axis)

Expand All @@ -91,6 +98,16 @@ def _config_getfloat(self, config, name, default_value):
def _config_getboolean(self, config, name, default_value):
return config.getboolean(name, self.toolchanger.config.getboolean(name, default_value))

# A placeholder object to emulate gcode macro.
class ToolMacro:
def __init__(self, tool):
self.tool = tool
def set_tool(self, tool):
self.tool = tool
def get_status(self, eventtime):
if self.tool is None:
return {}
return self.tool.get_status(eventtime)

def load_config_prefix(config):
return Tool(config)

0 comments on commit 3e9aa4d

Please sign in to comment.