idle_timeout: Add a get_status() method

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-06-04 12:35:50 -04:00
parent 0bb714edd7
commit 1c09a0935f
1 changed files with 8 additions and 1 deletions

View File

@ -20,11 +20,17 @@ class IdleTimeout:
self.gcode = self.printer.lookup_object('gcode')
self.toolhead = self.timeout_timer = None
self.printer.register_event_handler("klippy:ready", self.handle_ready)
self.state = "Idle"
self.idle_timeout = config.getfloat('timeout', 600., above=0.)
self.idle_gcode = config.get('gcode', DEFAULT_IDLE_GCODE).split('\n')
self.gcode.register_command(
'SET_IDLE_TIMEOUT', self.cmd_SET_IDLE_TIMEOUT)
self.state = "Idle"
self.last_print_start_systime = 0.
def get_status(self, eventtime):
printing_time = 0.
if state == "Printing":
printing_time = eventtime - self.last_print_start_systime
return { "state": self.state, "printing_time": printing_time }
def handle_ready(self):
self.toolhead = self.printer.lookup_object('toolhead')
self.timeout_timer = self.reactor.register_timer(self.timeout_handler)
@ -86,6 +92,7 @@ class IdleTimeout:
return
# Transition to "printing" state
self.state = "Printing"
self.last_print_start_systime = curtime
check_time = READY_TIMEOUT + print_time - est_print_time
self.reactor.update_timer(self.timeout_timer, curtime + check_time)
self.printer.send_event("idle_timeout:printing",