query_endstops: Add get_status() method that reports the last query state

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2020-02-12 19:11:40 -05:00
parent 4d9a36b34f
commit 512ad4b3a4
2 changed files with 11 additions and 3 deletions

View File

@ -175,6 +175,11 @@ The following are common printer attributes:
available temperature sensors by their full config section names,
e.g. `["extruder", "heater_bed", "heater_generic my_custom_heater",
"temperature_sensor electronics_temp"]`.
- `printer.query_endstops.last_query["<endstop>"]`: Returns True if
the given endstop was reported as "triggered" during the last
QUERY_ENDSTOP command. Note, due to the order of template expansion
(see above), the QUERY_STATUS command must be run prior to the macro
containing this reference.
The above list is subject to change - if using an attribute be sure to
review the [Config Changes document](Config_Changes.md) when upgrading

View File

@ -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))
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)