Host Module - how are valid options defined?

When creating a new host module, how/where are valid options defined? For example, take a look at the script in extras/static_digital_output.py – this script defines a single option, called “pins” (see Configuration reference - Klipper documentation).

How would you go about adding another configuraiton option? If I add “value” to printer.cfg:

[static_digital_output my_output_pins]
pins: PA4
value: 5

Klipper will error out:

Option ‘value’ is not valid in section ‘static_digital_output my_output_pins’

How does Klipper determine which values are valid for a given host module? I tried replicating the code which references the current, working value for ‘pins’ but the error persists.

Thanks!

What are you trying to do? If you’re just trying to set a default value for your particular output pin, it would be best to do that with a gcode macro.

Regarding your question, this may be helpful.

I’m looking to write a new module. My references to static_digital_output.py is only an example.

How does Klipper know which variables are supported by a given host module?

For example, here’s the full code for ‘static_digital_output.py’

Set the state of a list of digital output pins

Copyright (C) 2017-2018 Kevin O’Connor kevin@koconnor.net

This file may be distributed under the terms of the GNU GPLv3 license.

class PrinterStaticDigitalOut:
def init(self, config):
printer = config.get_printer()
ppins = printer.lookup_object(‘pins’)
pin_list = config.getlist(‘pins’)
for pin_desc in pin_list:
mcu_pin = ppins.setup_pin(‘digital_out’, pin_desc)
mcu_pin.setup_start_value(1, 1, True)

def load_config_prefix(config):
return PrinterStaticDigitalOut(config)

How would I go about modifying this code so that I can have a second variable, for example:

[static_digital_output my_output_pins]
pins: PA4
value: 5

I tried the obvious – duplicate the reference to ‘pins’ using ‘value’ but this only results in:

Klipper reports: ERROR

Option ‘value’ is not valid in section ‘static_digital_output my_output_pins’

Thanks!

Here’s the code I added to the __init__ function:

value = config.getint(‘value’)

I still get the same error as shown above. The documentation states:

Be sure to read all values from the config during the construction of the printer object - if the user specifies a config parameter that is not read during this phase then it will be assumed it is a typo in the config and an error will be raised.

What am I missing? Thanks :slight_smile:

For whatever reason, if I use:

    value   = config.get('value')

It works. Hope this helps others who are working on developing a host module.

Either one should work. If you’re experimenting by modifying static_digital_output.py, make sure you delete static_digital_output.pyc and then fully stop and restart the main klipper/klippy processes, to make sure klipper is actually using your modified version of static_digital_output.py. (I’m not sure if it’s always necessary to delete the *.pyc, but I always do that when tinkering just to eliminate it as a potential problem.)

Thanks!

Does anyone happen to know if there is any documentation for the register_mux_command method? for example, in extras/fan_generic.py:

    gcode.register_mux_command("SET_FAN_SPEED", "FAN",
                               self.fan_name,
                               self.cmd_SET_FAN_SPEED,
                               desc=self.cmd_SET_FAN_SPEED_help)

arg0 is the command to be registered
arg1 is the name of the parameter to use on the console, e.g. "SET_FAN_SPEED FAN=value_here
arg2 is… what?
arg3 is the method to call
arg4 is the help text

1 Like