diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-07-16 10:06:30 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-07-16 10:06:30 -0400 |
commit | 89835940f70ff4b9f19a77d14fdaeefa86d777db (patch) | |
tree | 0d564bb267611b39589c9c020c663237c6e5d0ea /klippy/extras/query_endstops.py | |
parent | 28fa954487443e48fff04dd412e11e877d50f143 (diff) | |
download | kutter-89835940f70ff4b9f19a77d14fdaeefa86d777db.tar.gz kutter-89835940f70ff4b9f19a77d14fdaeefa86d777db.tar.xz kutter-89835940f70ff4b9f19a77d14fdaeefa86d777db.zip |
query_endstops: Move QUERY_ENDSTOP command to it own extras/ module
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/extras/query_endstops.py')
-rw-r--r-- | klippy/extras/query_endstops.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/klippy/extras/query_endstops.py b/klippy/extras/query_endstops.py new file mode 100644 index 00000000..0b139ec2 --- /dev/null +++ b/klippy/extras/query_endstops.py @@ -0,0 +1,34 @@ +# Utility for querying the current state of all endstops +# +# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net> +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +class QueryEndstops: + def __init__(self, config): + self.printer = config.get_printer() + self.endstops = [] + gcode = self.printer.lookup_object('gcode') + gcode.register_command("QUERY_ENDSTOPS", self.cmd_QUERY_ENDSTOPS, + desc=self.cmd_QUERY_ENDSTOPS_help) + gcode.register_command("M119", self.cmd_QUERY_ENDSTOPS) + def register_endstop(self, mcu_endstop, name): + self.endstops.append((mcu_endstop, name)) + cmd_QUERY_ENDSTOPS_help = "Report on the status of each endstop" + def cmd_QUERY_ENDSTOPS(self, params): + toolhead = self.printer.lookup_object('toolhead') + print_time = toolhead.get_last_move_time() + # Query the endstops + for mcu_endstop, name in self.endstops: + mcu_endstop.query_endstop(print_time) + out = [] + for mcu_endstop, name in self.endstops: + out.append((name, mcu_endstop.query_endstop_wait())) + # Report results + msg = " ".join(["%s:%s" % (name, ["open", "TRIGGERED"][not not t]) + for name, t in out]) + gcode = self.printer.lookup_object('gcode') + gcode.respond(msg) + +def load_config(config): + return QueryEndstops(config) |