Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Request] Allow API for setting Temp for "Current Tool" for Multi-Toolhead Printers #5018

Closed
ccatlett1984 opened this issue May 22, 2024 · 5 comments
Labels
done Done but not yet released request Feature request
Milestone

Comments

@ccatlett1984
Copy link

Is your feature request related to a problem? Please describe.

If you have multiple printers, there is no way to send a temp command for the current tool:
M104 T{current_extruder} S140

Describe the solution you'd like

I've taken a crack at editing standard.py, but must have a syntax error. Not a python person ;)

Adding this additional endpoint, would allow for setting hotend temp of the loaded tool, without having to specify the tool (and in the case of OctoDash being hard coded to tool0 currently.)

    def set_temperature(self, heater, value, *args, **kwargs):
        if not PrinterInterface.valid_heater_regex.match(heater):
            raise ValueError(
                'heater must match "tool([0-9]+|Current)", "bed" or "chamber": {heater}'.format(
                    heater=heater
                )
            )

        if not isinstance(value, (int, float)) or value < 0:
            raise ValueError(f"value must be a valid number >= 0: {value}")

        tags = kwargs.get("tags", set()) | {"trigger:printer.set_temperature"}

        if heater.startswith("tool"):
            printer_profile = self._printerProfileManager.get_current_or_default()
            extruder_count = printer_profile["extruder"]["count"]
            shared_nozzle = printer_profile["extruder"]["sharedNozzle"]
            if extruder_count > 1 and not shared_nozzle:
                if heater[len("tool") :] == "Current":
                    self.commands(f"M104 T{"current_extruder"} S{value}", tags=tags)
                else:
                    toolNum = int(heater[len("tool") :])
                self.commands(f"M104 T{toolNum} S{value}", tags=tags)
            else:
                self.commands(f"M104 S{value}", tags=tags)

Describe alternatives you've considered

Since there does not be a method to query a Marlin (or other OS) printer for which toolhead is active, I don't see another way for controlling the "current" toolhead temp.

Additional context

No response

@github-actions github-actions bot added the request Feature request label May 22, 2024
@morphias2004
Copy link

  • 1

@ccatlett1984 ccatlett1984 changed the title [Request] Allow API for setting "Current_Extruder" for Multi-Toolhead Printers [Request] Allow API for setting Temp for "Current Tool" for Multi-Toolhead Printers May 22, 2024
@morphias2004
Copy link

A friend of @ccatlett1984 and I (Zura - thanks dude!) helped with the syntax errors, so OctoPrint now boots without issue.

Attached is the working standard.py file.
standard.py.txt

@ccatlett1984
Copy link
Author

ccatlett1984 commented May 25, 2024

PR: #5022

@foosel
Copy link
Member

foosel commented May 27, 2024

Quoting myself here:

I've changed the implementation a bit.

First of all you forgot to adjust the regexes used for validating tool names. Then, I really wasn't happy with something like toolCurrent_Extruder - instead it's now just tool without a number, and it is only supported for setting a temperature, which is the only place where it even makes sense (so I also added another validation regex to ensure that on e.g. setting an offset or selecting a tool it would not be supported).

Then I also adjusted the actual REST API endpoint, which also contains a sanity check which got forgotten, fixed a bug in the virtual printer plugin (M104 S120 would set the temperature of the first tool, instead of the current one) and finally updated the docs as well.

So, long story short, something like this works now:

curl --header "Authorization: Bearer ..." http://example.com/api/printer/tool --json '{"command": "target", "targets": {"tool": 120}}'

and is also documented correctly.

Will be in 1.11.0 👍 Docs are already updated here: https://docs.octoprint.org/en/maintenance/api/printer.html#issue-a-tool-command

@foosel foosel moved this from Todo to Done in OctoPrint Backlog May 27, 2024
@foosel foosel added the done Done but not yet released label May 27, 2024
@foosel foosel added this to the 1.11.0 milestone May 27, 2024
@ccatlett1984
Copy link
Author

Awesome, now on to getting OctoDash sorted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
done Done but not yet released request Feature request
Projects
Status: Done
Development

No branches or pull requests

3 participants