Skip to content

Latest commit

 

History

History

gcode_shell_command

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

GCode Shell Command

The original extension is part of the Kiauh repo (https://github.com/th33xitus/kiauh/blob/master/resources/gcode_shell_command.py). I've modified it to add support for custom GCode execution on either success or failure:

Usage

[gcode_shell_command COMMAND]
#value_<var>: <value>
#   Output value that can be updated by the command. <value>
#   serves as a default.
command:
#   The command line to be executed. This option is required.
#   The command can update the values for any of the value_*
#   variables above. In order to do so, the command should
#   output the update value in the following format:
#      VALUE_UPDATE:<var>=<value>
#   Only one value can be updated on a single line. The updated
#   values are processes as strings.
#timeout: 2.0
#   The amount of time (in seconds) to wait before forcefully
#   terminating the command.
#verbose: True
#   Enable verbose output to the console.
#success:
#   A list of G-Code commands to execute if the command
#   completes successfully. If this option is not present
#   nothing will be executed.
#   This section is evaluated as a template and can
#   reference the value_* values.
#failure:
#   A list of G-Code commands to execute if the command
#   does not complete successfully. If this option is not
#   present nothing will be executed.
#   This section is evaluated as a template and can
#   reference the value_* values.

Examples

[gcode_shell_command my_command]
command: echo my_command executing
success:
    M117 my_command executed successfully.
failure:
    M117 my_command failed.

[gcode_macro exec_my_command]
gcode:
    RUN_SHELL_COMMAND CMD=my_command
[gcode_shell_command my_command]
value_var1: 0
command: echo "VALUE_UPDATE:var1=10"
success:
    {action_respnd_info("var1=%s" % var1)}

Warning Infinite Loops

Since the G-Code executed on success/failure can be arbitrary, on top of all the other issues resulting from using external commands, it is now possible to create an infinite loop that will prevent the printer from continuing.

For example, the following will cause an infinite loop:

[gcode_shell_command my_command]
command: echo my_command executing
success:
    exec_my_command

[gcode_macro exec_my_command]
gcode:
    RUN_SHELL_COMMAND CMD=my_command

Known Issues

  1. This extension (like many others) need the gcode_macro Klipper object to already exist as it is used to process the success and failure actions. If a [gcode_shell_command] instance appears in the configuration prior to any [gcode_macro] sections, an error will occur as the lookup fails. To fix this, ensure that there is at least one [gcode_macro] section in the configuration prior to any [gcode_shell_command] sections.