aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/extras/homing_override.py
blob: 1e23fb80aa7a4c2d0b17a24cf92bb1dc13f36fbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Run user defined actions in place of a normal G28 homing command
#
# Copyright (C) 2018  Kevin O'Connor <kevin@koconnor.net>
#
# This file may be distributed under the terms of the GNU GPLv3 license.

class HomingOverride:
    def __init__(self, config):
        printer = config.get_printer()
        self.script = config.get('gcode')
        self.in_script = False
        self.gcode = printer.lookup_object('gcode')
        self.gcode.register_command("G28", self.cmd_G28)
    def cmd_G28(self, params):
        if self.in_script:
            # Was called recursively - invoke the real G28 command
            self.gcode.cmd_G28(params)
            return
        try:
            self.in_script = True
            self.gcode.run_script(self.script)
        finally:
            self.in_script = False

def load_config(config):
    if config.get_name() != 'homing_override':
        raise config.error("Invalid homing_override config name")
    return HomingOverride(config)