homing: Create QueryEndstops class from gcode

Create the QueryEndstops in the gcode handler instead of in the
kinematic classes.  This simplifies the gcode handler as it can
directly register its response callback.

Also, store the stepper name in the stepper class.  Also, propagate
the print_time of the query request to the mcu_endstop class.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2016-11-17 17:24:03 -05:00
parent 7ef8c0442a
commit 9e1059afb4
8 changed files with 37 additions and 36 deletions

View File

@@ -65,31 +65,36 @@ class Homing:
del self.endstops[:]
return False
# Helper code for querying and reporting the status of the endstops
class QueryEndstops:
def __init__(self, names, steppers):
def __init__(self, print_time, respond_cb):
self.print_time = print_time
self.respond_cb = respond_cb
self.endstops = []
self.busy = []
for name, stepper in zip(names, steppers):
es = stepper.query_endstop()
def set_steppers(self, steppers):
for stepper in steppers:
es = stepper.query_endstop(self.print_time)
if es is None:
continue
self.endstops.append((name, es))
self.endstops.append((stepper.name, es))
self.busy.append(es)
def check_busy(self, eventtime):
# Check if all endstop queries have been received
while self.busy:
busy = self.busy[0].check_busy(eventtime)
if busy:
return True
self.busy.pop(0)
return False
def get_msg(self):
# All responses received - report status
msgs = []
for name, es in self.endstops:
msg = "open"
if es.get_last_triggered():
msg = "TRIGGERED"
msgs.append("%s:%s" % (name, msg))
return " ".join(msgs)
self.respond_cb(" ".join(msgs))
return False
class EndstopError(Exception):
def __init__(self, pos, msg="Move out of range"):