mcu: Use regular send_with_response() for query_endstop()
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
a116fa9054
commit
e148dbe52a
|
@ -147,7 +147,6 @@ class MCU_endstop:
|
||||||
self._invert = pin_params['invert']
|
self._invert = pin_params['invert']
|
||||||
self._oid = self._home_cmd = self._query_cmd = None
|
self._oid = self._home_cmd = self._query_cmd = None
|
||||||
self._mcu.register_config_callback(self._build_config)
|
self._mcu.register_config_callback(self._build_config)
|
||||||
self._homing = False
|
|
||||||
self._min_query_time = 0.
|
self._min_query_time = 0.
|
||||||
self._next_query_print_time = 0.
|
self._next_query_print_time = 0.
|
||||||
self._last_state = {}
|
self._last_state = {}
|
||||||
|
@ -179,17 +178,16 @@ class MCU_endstop:
|
||||||
" rest_ticks=%u pin_value=%c", cq=cmd_queue)
|
" rest_ticks=%u pin_value=%c", cq=cmd_queue)
|
||||||
self._query_cmd = self._mcu.lookup_command(
|
self._query_cmd = self._mcu.lookup_command(
|
||||||
"end_stop_query_state oid=%c", cq=cmd_queue)
|
"end_stop_query_state oid=%c", cq=cmd_queue)
|
||||||
self._mcu.register_response(self._handle_end_stop_state,
|
|
||||||
"end_stop_state", self._oid)
|
|
||||||
def home_prepare(self):
|
def home_prepare(self):
|
||||||
pass
|
pass
|
||||||
def home_start(self, print_time, sample_time, sample_count, rest_time,
|
def home_start(self, print_time, sample_time, sample_count, rest_time,
|
||||||
triggered=True):
|
triggered=True):
|
||||||
clock = self._mcu.print_time_to_clock(print_time)
|
clock = self._mcu.print_time_to_clock(print_time)
|
||||||
rest_ticks = int(rest_time * self._mcu.get_adjusted_freq())
|
rest_ticks = int(rest_time * self._mcu.get_adjusted_freq())
|
||||||
self._homing = True
|
|
||||||
self._min_query_time = self._mcu.monotonic()
|
self._min_query_time = self._mcu.monotonic()
|
||||||
self._next_query_print_time = print_time + self.RETRY_QUERY
|
self._next_query_print_time = print_time + self.RETRY_QUERY
|
||||||
|
self._mcu.register_response(self._handle_end_stop_state,
|
||||||
|
"end_stop_state", self._oid)
|
||||||
self._home_cmd.send(
|
self._home_cmd.send(
|
||||||
[self._oid, clock, self._mcu.seconds_to_clock(sample_time),
|
[self._oid, clock, self._mcu.seconds_to_clock(sample_time),
|
||||||
sample_count, rest_ticks, triggered ^ self._invert],
|
sample_count, rest_ticks, triggered ^ self._invert],
|
||||||
|
@ -198,8 +196,11 @@ class MCU_endstop:
|
||||||
s.note_homing_start(clock)
|
s.note_homing_start(clock)
|
||||||
def home_wait(self, home_end_time):
|
def home_wait(self, home_end_time):
|
||||||
eventtime = self._mcu.monotonic()
|
eventtime = self._mcu.monotonic()
|
||||||
while self._check_busy(eventtime, home_end_time):
|
try:
|
||||||
eventtime = self._mcu.pause(eventtime + 0.1)
|
while self._check_busy(eventtime, home_end_time):
|
||||||
|
eventtime = self._mcu.pause(eventtime + 0.1)
|
||||||
|
finally:
|
||||||
|
self._mcu.register_response(None, "end_stop_state", self._oid)
|
||||||
def home_finalize(self):
|
def home_finalize(self):
|
||||||
pass
|
pass
|
||||||
def _handle_end_stop_state(self, params):
|
def _handle_end_stop_state(self, params):
|
||||||
|
@ -209,12 +210,9 @@ class MCU_endstop:
|
||||||
# Check if need to send an end_stop_query command
|
# Check if need to send an end_stop_query command
|
||||||
last_sent_time = self._last_state.get('#sent_time', -1.)
|
last_sent_time = self._last_state.get('#sent_time', -1.)
|
||||||
if last_sent_time >= self._min_query_time or self._mcu.is_fileoutput():
|
if last_sent_time >= self._min_query_time or self._mcu.is_fileoutput():
|
||||||
if not self._homing:
|
|
||||||
return False
|
|
||||||
if not self._last_state.get('homing', 0):
|
if not self._last_state.get('homing', 0):
|
||||||
for s in self._steppers:
|
for s in self._steppers:
|
||||||
s.note_homing_end(did_trigger=True)
|
s.note_homing_end(did_trigger=True)
|
||||||
self._homing = False
|
|
||||||
return False
|
return False
|
||||||
last_sent_print_time = self._mcu.estimated_print_time(
|
last_sent_print_time = self._mcu.estimated_print_time(
|
||||||
last_sent_time)
|
last_sent_time)
|
||||||
|
@ -222,7 +220,6 @@ class MCU_endstop:
|
||||||
# Timeout - disable endstop checking
|
# Timeout - disable endstop checking
|
||||||
for s in self._steppers:
|
for s in self._steppers:
|
||||||
s.note_homing_end()
|
s.note_homing_end()
|
||||||
self._homing = False
|
|
||||||
self._home_cmd.send([self._oid, 0, 0, 0, 0, 0])
|
self._home_cmd.send([self._oid, 0, 0, 0, 0, 0])
|
||||||
raise self.TimeoutError("Timeout during endstop homing")
|
raise self.TimeoutError("Timeout during endstop homing")
|
||||||
if self._mcu.is_shutdown():
|
if self._mcu.is_shutdown():
|
||||||
|
@ -233,12 +230,12 @@ class MCU_endstop:
|
||||||
self._query_cmd.send([self._oid])
|
self._query_cmd.send([self._oid])
|
||||||
return True
|
return True
|
||||||
def query_endstop(self, print_time):
|
def query_endstop(self, print_time):
|
||||||
self._homing = False
|
clock = self._mcu.print_time_to_clock(print_time)
|
||||||
self._min_query_time = eventtime = self._mcu.monotonic()
|
if self._mcu.is_fileoutput():
|
||||||
self._next_query_print_time = print_time
|
return 0
|
||||||
while self._check_busy(eventtime):
|
params = self._query_cmd.send_with_response(
|
||||||
eventtime = self._mcu.pause(eventtime + 0.1)
|
[self._oid], "end_stop_state", self._oid, minclock=clock)
|
||||||
return self._last_state.get('pin_value', self._invert) ^ self._invert
|
return params['pin_value'] ^ self._invert
|
||||||
|
|
||||||
class MCU_digital_out:
|
class MCU_digital_out:
|
||||||
def __init__(self, mcu, pin_params):
|
def __init__(self, mcu, pin_params):
|
||||||
|
|
Loading…
Reference in New Issue