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/console.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/console.py')
-rwxr-xr-x | klippy/console.py | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/klippy/console.py b/klippy/console.py index cd7facfd..0259864f 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -86,11 +86,10 @@ class KeyboardReader: self.output("Error: %s" % (str(e),)) return try: - msg = self.ser.msgparser.create_command(' '.join(parts[2:])) + self.ser.send(' '.join(parts[2:]), minclock=val) except msgproto.error as e: self.output("Error: %s" % (str(e),)) return - self.ser.send(msg, minclock=val) def command_FLOOD(self, parts): try: count = int(parts[1]) @@ -98,18 +97,18 @@ class KeyboardReader: except ValueError as e: self.output("Error: %s" % (str(e),)) return + msg = ' '.join(parts[3:]) + delay_clock = int(delay * self.mcu_freq) + msg_clock = int(self.clocksync.get_clock(self.reactor.monotonic()) + + self.mcu_freq * .200) try: - msg = self.ser.msgparser.create_command(' '.join(parts[3:])) + for i in range(count): + next_clock = msg_clock + delay_clock + self.ser.send(msg, minclock=msg_clock, reqclock=next_clock) + msg_clock = next_clock except msgproto.error as e: self.output("Error: %s" % (str(e),)) return - delay_clock = int(delay * self.mcu_freq) - msg_clock = int(self.clocksync.get_clock(self.reactor.monotonic()) - + self.mcu_freq * .200) - for i in range(count): - next_clock = msg_clock + delay_clock - self.ser.send(msg, minclock=msg_clock, reqclock=next_clock) - msg_clock = next_clock def command_SUPPRESS(self, parts): oid = None try: @@ -164,12 +163,7 @@ class KeyboardReader: if parts[0] in self.local_commands: self.local_commands[parts[0]](parts) return None - try: - msg = self.ser.msgparser.create_command(line) - except msgproto.error as e: - self.output("Error: %s" % (str(e),)) - return None - return msg + return line def process_kbd(self, eventtime): self.data += os.read(self.fd, 4096) @@ -184,7 +178,11 @@ class KeyboardReader: msg = self.translate(line.strip(), eventtime) if msg is None: continue - self.ser.send(msg) + try: + self.ser.send(msg) + except msgproto.error as e: + self.output("Error: %s" % (str(e),)) + return None self.data = kbdlines[-1] def main(): |