aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/klippy.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-30 23:47:40 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-30 23:53:03 -0500
commitfbd7cc243ba49b7e8ab0b435e319cf133dea5224 (patch)
treec8b6e1c42b96f7ff5f2855f8c956ba3ca51d0a5b /klippy/klippy.py
parenta6055ce069b65d04a56551b72282f0f2b439b6c8 (diff)
downloadkutter-fbd7cc243ba49b7e8ab0b435e319cf133dea5224.tar.gz
kutter-fbd7cc243ba49b7e8ab0b435e319cf133dea5224.tar.xz
kutter-fbd7cc243ba49b7e8ab0b435e319cf133dea5224.zip
klippy: Add ability to restart the host software
Add a "restart" gcode command that will cause the host "klippy" software to reload its config and restart. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r--klippy/klippy.py43
1 files changed, 30 insertions, 13 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 25f6b99b..2787a6aa 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -14,9 +14,8 @@ Printer is not ready
"""
message_restart = """
-This is an unrecoverable error. Please correct the
-underlying issue and then manually restart the klippy host
-software.
+Once the underlying issue is corrected, use the "RESTART"
+command to reload the config and restart the host software.
Printer is halted
"""
@@ -85,6 +84,7 @@ class Printer:
self.need_dump_debug = False
self.state_message = message_startup
self.debugoutput = self.dictionary = None
+ self.run_result = None
self.fileconfig = None
self.mcu = None
self.objects = {}
@@ -172,10 +172,7 @@ class Printer:
except:
logging.exception("Unhandled exception during run")
return
- # If gcode exits, then exit the MCU
- self.stats(time.time())
- self.mcu.disconnect()
- self.stats(time.time())
+ return self.run_result
def get_state_message(self):
return self.state_message
def note_shutdown(self, msg):
@@ -187,7 +184,17 @@ class Printer:
def note_mcu_error(self, msg):
self.state_message = "%s%s" % (msg, message_restart)
self.gcode.set_printer_ready(False)
- self.gcode.note_mcu_error()
+ self.gcode.motor_heater_off()
+ def disconnect(self):
+ if self.mcu is not None:
+ self.stats(time.time())
+ self.mcu.disconnect()
+ def request_restart(self):
+ self.run_result = "restart"
+ self.reactor.end()
+ def request_exit_eof(self):
+ self.run_result = "exit_eof"
+ self.reactor.end()
######################################################################
@@ -239,11 +246,21 @@ def main():
logging.info("Starting Klippy...")
# Start firmware
- printer = Printer(conffile, input_fd, is_fileinput=debuginput is not None)
- if debugoutput:
- proto_dict = read_dictionary(options.read_dictionary)
- printer.set_fileoutput(debugoutput, proto_dict)
- printer.run()
+ while 1:
+ is_fileinput = debuginput is not None
+ printer = Printer(conffile, input_fd, is_fileinput)
+ if debugoutput:
+ proto_dict = read_dictionary(options.read_dictionary)
+ printer.set_fileoutput(debugoutput, proto_dict)
+ res = printer.run()
+ if res == 'restart':
+ printer.disconnect()
+ time.sleep(1.)
+ logging.info("Restarting printer")
+ continue
+ elif res == 'eof_stats':
+ printer.disconnect()
+ break
if bglogger is not None:
bglogger.stop()