diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2016-11-28 13:14:56 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2016-11-29 21:54:45 -0500 |
commit | 5d805ba55059750e79c8b507d164c55a14c6d737 (patch) | |
tree | 83342573f394dd96e14e1b2d6433caf495373c30 /klippy/mcu.py | |
parent | bafe796eeb70703ea44a368614f3cc5be0898b45 (diff) | |
download | kutter-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/mcu.py')
-rw-r--r-- | klippy/mcu.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/klippy/mcu.py b/klippy/mcu.py index ba95d92c..d279a847 100644 --- a/klippy/mcu.py +++ b/klippy/mcu.py @@ -342,12 +342,13 @@ class MCU: self._steppersync = self.ffi_lib.steppersync_alloc( self.serial.serialqueue, stepqueues, len(stepqueues), count) def connect(self): + state_params = {} def handle_serial_state(params): - if params['#state'] == 'connected': - self._printer.reactor.end() + state_params.update(params) self.serial.register_callback(handle_serial_state, '#state') self.serial.connect() - self._printer.reactor.run() + while state_params.get('#state') != 'connected': + self._printer.reactor.pause(time.time() + 0.05) self.serial.unregister_callback('#state') logging.info("serial connected") self._mcu_freq = float(self.serial.msgparser.config['CLOCK_FREQ']) @@ -427,14 +428,15 @@ class MCU: sent_config = False def handle_get_config(params): config_params.update(params) - done = not sent_config or params['is_config'] - if done: - self._printer.reactor.end() - return done + return True while 1: self.serial.send_with_response(msg, handle_get_config, 'config') - self._printer.reactor.run() - if not config_params['is_config']: + while 1: + is_config = config_params.get('is_config') + if is_config is not None and (not sent_config or is_config): + break + self._printer.reactor.pause(time.time() + 0.05) + if not is_config: # Send config commands for c in self._config_cmds: self.send(self.create_command(c)) |