From ff789058dfe5d3e5f34482f8410aaf0358e582e9 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Sat, 11 Jun 2016 22:31:05 -0400 Subject: [PATCH] console: Update the debugging console to support setting local varables Add a "SET varname value" local command to the console.py script. Signed-off-by: Kevin O'Connor --- klippy/console.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/klippy/console.py b/klippy/console.py index 4782702a..21cd5f4d 100755 --- a/klippy/console.py +++ b/klippy/console.py @@ -19,16 +19,26 @@ class KeyboardReader: self.pins = None self.data = "" self.reactor.register_fd(self.fd, self.process_kbd) - self.local_commands = { "PINS": self.set_pin_map } + self.local_commands = { "PINS": self.set_pin_map, "SET": self.set_var } self.eval_globals = {} def update_evals(self, eventtime): f = self.ser.msgparser.config.get('CLOCK_FREQ', 1) - c = (eventtime - self.ser.last_ack_time) * f + self.ser.last_ack_clock + c = self.ser.get_clock(eventtime) self.eval_globals['freq'] = f self.eval_globals['clock'] = int(c) def set_pin_map(self, parts): mcu = self.ser.msgparser.config['MCU'] self.pins = pins.map_pins(parts[1], mcu) + def set_var(self, parts): + val = parts[2] + try: + val = int(val) + except ValueError: + try: + val = float(val) + except ValueError: + pass + self.eval_globals[parts[1]] = val def lookup_pin(self, value): if self.pins is None: self.pins = pins.mcu_to_pins(self.ser.msgparser.config['MCU'])