aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/klippy.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-11-28 13:14:56 -0500
committerKevin O'Connor <kevin@koconnor.net>2016-11-29 21:54:45 -0500
commit5d805ba55059750e79c8b507d164c55a14c6d737 (patch)
tree83342573f394dd96e14e1b2d6433caf495373c30 /klippy/klippy.py
parentbafe796eeb70703ea44a368614f3cc5be0898b45 (diff)
downloadkutter-5d805ba55059750e79c8b507d164c55a14c6d737.tar.gz
kutter-5d805ba55059750e79c8b507d164c55a14c6d737.tar.xz
kutter-5d805ba55059750e79c8b507d164c55a14c6d737.zip
klippy: Run the MCU connect code within the reactor
Setup the reactor and run the MCU connection code as a timer within the reactor. The connection code will make use of reactor greenlets so that it can wait for events during the connection phase. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/klippy.py')
-rw-r--r--klippy/klippy.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/klippy/klippy.py b/klippy/klippy.py
index 191997c5..ed71d699 100644
--- a/klippy/klippy.py
+++ b/klippy/klippy.py
@@ -45,8 +45,11 @@ class Printer:
self.gcode = gcode.GCodeParser(
self, pseudo_tty, inputfile=debuginput is not None)
- self.mcu = None
- self.stat_timer = None
+ self.mcu = mcu.MCU(self, ConfigWrapper(self, 'mcu'))
+ self.stats_timer = self.reactor.register_timer(
+ self.stats, self.reactor.NOW)
+ self.connect_timer = self.reactor.register_timer(
+ self.connect, self.reactor.NOW)
self.objects = {}
if self.fileconfig.has_section('fan'):
@@ -73,18 +76,20 @@ class Printer:
self.objects[oname].build_config()
self.gcode.build_config()
self.mcu.build_config()
- def connect(self):
- self.mcu = mcu.MCU(self, ConfigWrapper(self, 'mcu'))
+ def connect(self, eventtime):
self.mcu.connect()
self.build_config()
- self.stats_timer = self.reactor.register_timer(
- self.stats, self.reactor.NOW)
+ self.gcode.run()
+ self.reactor.unregister_timer(self.connect_timer)
+ return self.reactor.NEVER
def connect_file(self, output, dictionary):
- self.mcu = mcu.MCU(self, ConfigWrapper(self, 'mcu'))
+ self.reactor.update_timer(self.stats_timer, self.reactor.NEVER)
self.mcu.connect_file(output, dictionary)
self.build_config()
- def run(self):
self.gcode.run()
+ self.reactor.unregister_timer(self.connect_timer)
+ def run(self):
+ self.reactor.run()
# If gcode exits, then exit the MCU
self.stats(time.time())
self.mcu.disconnect()
@@ -141,8 +146,6 @@ def main():
if debugoutput:
proto_dict = read_dictionary(options.read_dictionary)
printer.connect_file(debugoutput, proto_dict)
- else:
- printer.connect()
printer.run()
if bglogger is not None: