console: Automatically convert float values to int during evaluation

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2017-04-25 11:19:35 -04:00
parent fe11c3e348
commit a6fe355801
1 changed files with 8 additions and 8 deletions

View File

@ -25,7 +25,7 @@ class KeyboardReader:
self.eval_globals = {}
def connect(self, eventtime):
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')
self.pins = pins.get_pin_map(mcu)
self.reactor.unregister_timer(self.connect_timer)
@ -35,15 +35,12 @@ class KeyboardReader:
sys.stdout.flush()
def update_evals(self, eventtime):
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):
mcu = self.ser.msgparser.get_constant('MCU')
self.pins = pins.get_pin_map(mcu, parts[1])
def set_var(self, parts):
val = parts[2]
try:
val = int(val)
except ValueError:
try:
val = float(val)
except ValueError:
@ -55,7 +52,10 @@ class KeyboardReader:
self.update_evals(eventtime)
try:
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:
self.output("Unable to evaluate: %s" % (line,))
return None