mirror of https://github.com/Desuuuu/klipper.git
console: Automatically convert float values to int during evaluation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
fe11c3e348
commit
a6fe355801
|
@ -25,7 +25,7 @@ class KeyboardReader:
|
||||||
self.eval_globals = {}
|
self.eval_globals = {}
|
||||||
def connect(self, eventtime):
|
def connect(self, eventtime):
|
||||||
self.ser.connect()
|
self.ser.connect()
|
||||||
self.mcu_freq = int(self.ser.msgparser.get_constant_float('CLOCK_FREQ'))
|
self.mcu_freq = self.ser.msgparser.get_constant_float('CLOCK_FREQ')
|
||||||
mcu = self.ser.msgparser.get_constant('MCU')
|
mcu = self.ser.msgparser.get_constant('MCU')
|
||||||
self.pins = pins.get_pin_map(mcu)
|
self.pins = pins.get_pin_map(mcu)
|
||||||
self.reactor.unregister_timer(self.connect_timer)
|
self.reactor.unregister_timer(self.connect_timer)
|
||||||
|
@ -35,19 +35,16 @@ class KeyboardReader:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
def update_evals(self, eventtime):
|
def update_evals(self, eventtime):
|
||||||
self.eval_globals['freq'] = self.mcu_freq
|
self.eval_globals['freq'] = self.mcu_freq
|
||||||
self.eval_globals['clock'] = int(self.ser.get_clock(eventtime))
|
self.eval_globals['clock'] = self.ser.get_clock(eventtime)
|
||||||
def set_pin_map(self, parts):
|
def set_pin_map(self, parts):
|
||||||
mcu = self.ser.msgparser.get_constant('MCU')
|
mcu = self.ser.msgparser.get_constant('MCU')
|
||||||
self.pins = pins.get_pin_map(mcu, parts[1])
|
self.pins = pins.get_pin_map(mcu, parts[1])
|
||||||
def set_var(self, parts):
|
def set_var(self, parts):
|
||||||
val = parts[2]
|
val = parts[2]
|
||||||
try:
|
try:
|
||||||
val = int(val)
|
val = float(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
try:
|
pass
|
||||||
val = float(val)
|
|
||||||
except ValueError:
|
|
||||||
pass
|
|
||||||
self.eval_globals[parts[1]] = val
|
self.eval_globals[parts[1]] = val
|
||||||
def translate(self, line, eventtime):
|
def translate(self, line, eventtime):
|
||||||
evalparts = re_eval.split(line)
|
evalparts = re_eval.split(line)
|
||||||
|
@ -55,7 +52,10 @@ class KeyboardReader:
|
||||||
self.update_evals(eventtime)
|
self.update_evals(eventtime)
|
||||||
try:
|
try:
|
||||||
for i in range(1, len(evalparts), 2):
|
for i in range(1, len(evalparts), 2):
|
||||||
evalparts[i] = str(eval(evalparts[i], self.eval_globals))
|
e = eval(evalparts[i], self.eval_globals)
|
||||||
|
if type(e) == type(0.):
|
||||||
|
e = int(e)
|
||||||
|
evalparts[i] = str(e)
|
||||||
except:
|
except:
|
||||||
self.output("Unable to evaluate: %s" % (line,))
|
self.output("Unable to evaluate: %s" % (line,))
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Reference in New Issue