Override gcode method and call overridden method

Basic Information:

Printer Model: Hypercube (custom printer from scratch)
MCU / Printerboard: (SKR1.4 Turbo / EBB42 - both over serial, not CAN)
klippy.log not applicable here

Describe your issue: How do I override a built-in GCODE and still call the overridden method?

Okay, so I have two Meanwell PSUs on my printer - 5V/10A and 24V/25A. The 5V is always on and that feeds the raspberry pi 4 with klipper, the touchscreen, cameras, and both of my mcu boards. The 5V PSU is silent with no fan. Then, there’s the powerful 600W 24V PSU I switch on only when I want to print - so before running any heater or before doing any motor movements. I have a gcode macro and a pin defined in mainsail so I can switch the 24V PSU on or off that way. But I would like to use the SET_HEATER_TEMPERATURE gcode to turn on my PSU if it’s off, so I don’t have to remember to turn the PSU on myself first. This way I could just set the preheat temperature from klipperscreen or from mainsail and not think about the PSU. The same would go for motor movements, but that’s the exact same problem, so once I find the solution to this one I’ll be able to use it for that too.

The only thing I am after here is the way to call the overridden gcode, if it can be done at all. Anything else like the PSU sensing and other things I already have solutions for.

What I am looking for in a pseudo code would be something like this:

[gcode_macro SET_HEATER_TEMPERATURE]
gcode:
    <DETERMINE_PSU_STATE>
    {% if PSU_OFF %}
        <TURN_PSU ON>
    {% endif %}
    CALL_ORIGINAL_SET_HEATER_TEMPERATURE

Is anything like this possible with current klipper firmware? Or should I more look in the feature request section?

Did you try to use enable_pin for motors and extruder ?
Klipper already controlling it

If you really want to override GCode - just use gcode_macro
It have abilities to override existing command, refer to rename_existing parameter

https://www.klipper3d.org/Config_Reference.html#gcode_macro

For sample usage - look in sample_macros.cfg file, macro “M117”

Well, the enable_pin is an interesting option. But there’s also the bed heater and hotend that would need to be handled too.

As for the override - I know I can override the gcode, but my question is how to override it and call the previous overriden gcode from within. Because if I override the SET_HEATER_TEMPERATURE to do my stuff with the PSU, then it won’t do what SET_HEATER_TEMPERATURE is supposed to do …

What you use for rename_existing retains the original function.

As an alternative, you could create your own SET_EXT_TEMP macro, do your stuff and finally call SET_HEATER_TEMPERATURE

1 Like

Ah! I see! Yeah I didn’t understand the rename attribute properly! That sounds like a winner. Thank you.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.