diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2018-02-27 14:16:16 -0500 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2018-02-27 21:06:16 -0500 |
commit | b139a8561f54b7a764faa54b117a8544b8451d41 (patch) | |
tree | 1d23fd730928f3db60d8d5838b0cded936fbb655 /klippy/clocksync.py | |
parent | 8518da9824ffa4c8b0f41be140eecf3973126d10 (diff) | |
download | kutter-b139a8561f54b7a764faa54b117a8544b8451d41.tar.gz kutter-b139a8561f54b7a764faa54b117a8544b8451d41.tar.xz kutter-b139a8561f54b7a764faa54b117a8544b8451d41.zip |
serialhdl: Add a wrapper around the results of lookup_command()
Add a lookup_command() method to the SerialReader class that provides
a wrapper that stores the serial and commandqueue references. This
makes it easier to run the send() method.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/clocksync.py')
-rw-r--r-- | klippy/clocksync.py | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/klippy/clocksync.py b/klippy/clocksync.py index 65c3face..b31908b6 100644 --- a/klippy/clocksync.py +++ b/klippy/clocksync.py @@ -29,20 +29,19 @@ class ClockSync: self.last_prediction_time = 0. def connect(self, serial): self.serial = serial - msgparser = serial.msgparser - self.mcu_freq = msgparser.get_constant_float('CLOCK_FREQ') + self.mcu_freq = serial.msgparser.get_constant_float('CLOCK_FREQ') # Load initial clock and frequency - uptime_msg = msgparser.create_command('get_uptime') - params = serial.send_with_response(uptime_msg, 'uptime') + get_uptime_cmd = serial.lookup_command('get_uptime') + params = get_uptime_cmd.send_with_response(response='uptime') self.last_clock = (params['high'] << 32) | params['clock'] self.clock_avg = self.last_clock self.time_avg = params['#sent_time'] self.clock_est = (self.time_avg, self.clock_avg, self.mcu_freq) self.prediction_variance = (.001 * self.mcu_freq)**2 # Enable periodic get_status timer - self.status_cmd = msgparser.create_command('get_status') + self.status_cmd = serial.lookup_command('get_status') for i in range(8): - params = serial.send_with_response(self.status_cmd, 'status') + params = self.status_cmd.send_with_response(response='status') self._handle_status(params) self.reactor.pause(0.100) serial.register_callback(self._handle_status, 'status') @@ -57,7 +56,7 @@ class ClockSync: serial.set_clock_est(freq, self.reactor.monotonic(), 0) # MCU clock querying (status callback invoked from background thread) def _status_event(self, eventtime): - self.serial.send(self.status_cmd) + self.status_cmd.send() return eventtime + 1.0 def _handle_status(self, params): # Extend clock to 64bit |