From 512ad4b3a4e3893dea3efc02d7517a032fef4ac6 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 12 Feb 2020 19:11:40 -0500 Subject: query_endstops: Add get_status() method that reports the last query state Signed-off-by: Kevin O'Connor --- klippy/extras/query_endstops.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'klippy/extras/query_endstops.py') diff --git a/klippy/extras/query_endstops.py b/klippy/extras/query_endstops.py index f0e5c58e..9682228f 100644 --- a/klippy/extras/query_endstops.py +++ b/klippy/extras/query_endstops.py @@ -8,21 +8,24 @@ class QueryEndstops: def __init__(self, config): self.printer = config.get_printer() self.endstops = [] + self.last_state = {} 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)) + def get_status(self, eventtime): + return {'last_query': {name: value for name, value in self.last_state}} cmd_QUERY_ENDSTOPS_help = "Report on the status of each endstop" def cmd_QUERY_ENDSTOPS(self, params): # Query the endstops print_time = self.printer.lookup_object('toolhead').get_last_move_time() - out = [(name, mcu_endstop.query_endstop(print_time)) - for mcu_endstop, name in self.endstops] + self.last_state = [(name, mcu_endstop.query_endstop(print_time)) + for mcu_endstop, name in self.endstops] # Report results msg = " ".join(["%s:%s" % (name, ["open", "TRIGGERED"][not not t]) - for name, t in out]) + for name, t in self.last_state]) gcode = self.printer.lookup_object('gcode') gcode.respond(msg) -- cgit v1.2.3-70-g09d2