mirror of
https://github.com/Klipper3d/klipper.git
synced 2025-08-05 13:04:05 -06:00
idle_timeout: Move timeout handling from toolhead.py to new extras module
Move the "motor_off_timeout" tracking to a new module in the extras/ directory. This makes it easier to customize the idle timeout behavior. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
0025fbf10d
commit
acefe26e0f
7 changed files with 77 additions and 32 deletions
48
klippy/extras/idle_timeout.py
Normal file
48
klippy/extras/idle_timeout.py
Normal file
|
@ -0,0 +1,48 @@
|
|||
# Support for disabling the printer on an idle timeout
|
||||
#
|
||||
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
||||
#
|
||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||
|
||||
DEFAULT_IDLE_GCODE = """
|
||||
M84
|
||||
"""
|
||||
|
||||
class IdleTimeout:
|
||||
def __init__(self, config):
|
||||
self.printer = config.get_printer()
|
||||
self.toolhead = None
|
||||
self.last_timeout = 0.
|
||||
self.idle_timeout = config.getfloat('timeout', 600., above=0.)
|
||||
self.idle_script = config.get('gcode', DEFAULT_IDLE_GCODE)
|
||||
def printer_state(self, state):
|
||||
if state == 'ready':
|
||||
self.toolhead = self.printer.lookup_object('toolhead')
|
||||
reactor = self.printer.get_reactor()
|
||||
reactor.register_timer(self.timeout_handler, reactor.NOW)
|
||||
def run_idle_script(self):
|
||||
gcode = self.printer.lookup_object('gcode')
|
||||
for line in self.idle_script.split('\n'):
|
||||
try:
|
||||
res = gcode.process_batch(line)
|
||||
except:
|
||||
break
|
||||
if not res:
|
||||
# Raced with incoming g-code commands
|
||||
return
|
||||
self.last_timeout = self.toolhead.get_last_move_time()
|
||||
def timeout_handler(self, eventtime):
|
||||
info = self.toolhead.get_status(eventtime)
|
||||
print_time = info['print_time']
|
||||
status = info['status']
|
||||
if print_time <= self.last_timeout or status == 'Printing':
|
||||
return eventtime + self.idle_timeout
|
||||
estimated_print_time = info['estimated_print_time']
|
||||
elapsed_time = estimated_print_time - print_time
|
||||
if elapsed_time < self.idle_timeout:
|
||||
return eventtime + self.idle_timeout - elapsed_time
|
||||
self.run_idle_script()
|
||||
return eventtime + 1.
|
||||
|
||||
def load_config(config):
|
||||
return IdleTimeout(config)
|
Loading…
Add table
Add a link
Reference in a new issue