toolhead: Separate lookahead timer flushing to new _check_flush_lookahead()

Separate out the lookahead specific flushing logic from the
_flush_handler() code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2025-08-12 14:27:21 -04:00
parent a64207aac3
commit 4b9a0b4f82

View File

@ -401,11 +401,11 @@ class ToolHead:
logging.exception("Exception in priming_handler") logging.exception("Exception in priming_handler")
self.printer.invoke_shutdown("Exception in priming_handler") self.printer.invoke_shutdown("Exception in priming_handler")
return self.reactor.NEVER return self.reactor.NEVER
def _flush_handler(self, eventtime): def _check_flush_lookahead(self, eventtime):
try: if self.special_queuing_state:
est_print_time = self.mcu.estimated_print_time(eventtime) return None
if not self.special_queuing_state:
# In "main" state - flush lookahead if buffer runs low # In "main" state - flush lookahead if buffer runs low
est_print_time = self.mcu.estimated_print_time(eventtime)
print_time = self.print_time print_time = self.print_time
buffer_time = print_time - est_print_time buffer_time = print_time - est_print_time
if buffer_time > BUFFER_TIME_LOW: if buffer_time > BUFFER_TIME_LOW:
@ -415,7 +415,15 @@ class ToolHead:
self._flush_lookahead() self._flush_lookahead()
if print_time != self.print_time: if print_time != self.print_time:
self.check_stall_time = self.print_time self.check_stall_time = self.print_time
# In "NeedPrime"/"Priming" state - flush queues if needed return None
def _flush_handler(self, eventtime):
try:
# Check if flushing is done via lookahead queue
ret = self._check_flush_lookahead(eventtime)
if ret is not None:
return ret
# Flush motion queues
est_print_time = self.mcu.estimated_print_time(eventtime)
while 1: while 1:
end_flush = self.need_flush_time + BGFLUSH_EXTRA_TIME end_flush = self.need_flush_time + BGFLUSH_EXTRA_TIME
if self.last_flush_time >= end_flush: if self.last_flush_time >= end_flush: