Skip to content

Commit

Permalink
toolhead: Extend flushing slightly past required time
Browse files Browse the repository at this point in the history
There is no harm in enabling flushing for a little longer than
necessary.  In contrast, a slight rounding issue causing a message to
not get flushed properly could result in an error.  So, extend the
flushing time slightly to avoid potential issues.

Signed-off-by: Kevin O'Connor <[email protected]>
  • Loading branch information
KevinOConnor committed Jan 17, 2024
1 parent 3d3b87f commit 7a74888
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 1 addition & 3 deletions klippy/extras/pwm_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import chelper

MAX_SCHEDULE_TIME = 5.0
CLOCK_SYNC_EXTRA_TIME = 0.050

class error(Exception):
pass
Expand Down Expand Up @@ -118,8 +117,7 @@ def _send_update(self, clock, val):
# Continue flushing to resend time
wakeclock += self._duration_ticks
wake_print_time = self._mcu.clock_to_print_time(wakeclock)
self._toolhead.note_kinematic_activity(wake_print_time
+ CLOCK_SYNC_EXTRA_TIME)
self._toolhead.note_kinematic_activity(wake_print_time)
def set_pwm(self, print_time, value):
clock = self._mcu.print_time_to_clock(print_time)
if self._invert:
Expand Down
8 changes: 5 additions & 3 deletions klippy/toolhead.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Code for coordinating events on the printer toolhead
#
# Copyright (C) 2016-2021 Kevin O'Connor <[email protected]>
# Copyright (C) 2016-2024 Kevin O'Connor <[email protected]>
#
# This file may be distributed under the terms of the GNU GPLv3 license.
import math, logging, importlib
Expand Down Expand Up @@ -191,6 +191,7 @@ def add_move(self, move):
BUFFER_TIME_START = 0.250
BGFLUSH_LOW_TIME = 0.200
BGFLUSH_BATCH_TIME = 0.200
BGFLUSH_EXTRA_TIME = 0.250
MIN_KIN_TIME = 0.100
MOVE_BATCH_TIME = 0.500
STEPCOMPRESS_FLUSH_TIME = 0.050
Expand Down Expand Up @@ -428,14 +429,15 @@ def _flush_handler(self, eventtime):
self.check_stall_time = self.print_time
# In "NeedPrime"/"Priming" state - flush queues if needed
while 1:
if self.last_flush_time >= self.need_flush_time:
end_flush = self.need_flush_time + BGFLUSH_EXTRA_TIME
if self.last_flush_time >= end_flush:
self.do_kick_flush_timer = True
return self.reactor.NEVER
buffer_time = self.last_flush_time - est_print_time
if buffer_time > BGFLUSH_LOW_TIME:
return eventtime + buffer_time - BGFLUSH_LOW_TIME
ftime = est_print_time + BGFLUSH_LOW_TIME + BGFLUSH_BATCH_TIME
self._advance_flush_time(min(self.need_flush_time, ftime))
self._advance_flush_time(min(end_flush, ftime))
except:
logging.exception("Exception in flush_handler")
self.printer.invoke_shutdown("Exception in flush_handler")
Expand Down

0 comments on commit 7a74888

Please sign in to comment.