Skip to content

Commit e686d52

Browse files
committed
- Removed functions get_states, get_events and get_variables from statemachine.py, which were called from pycboard, and modified the pycboard code so it accesses the relevent variables directly.
1 parent 3f5201b commit e686d52

2 files changed

Lines changed: 6 additions & 20 deletions

File tree

com/pycboard.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -315,15 +315,15 @@ def setup_state_machine(self, sm_name, sm_dir=None, uploaded=False):
315315

316316
def get_states(self):
317317
'''Return states as a dictionary {state_name: state_ID}'''
318-
return eval(self.exec('sm.get_states()').decode().strip())
318+
return eval(self.eval('sm.states').decode())
319319

320320
def get_events(self):
321321
'''Return events as a dictionary {event_name: state_ID}'''
322-
return eval(self.exec('sm.get_events()').decode().strip())
322+
return eval(self.eval('sm.events').decode())
323323

324324
def get_variables(self):
325325
'''Return variables as a dictionary {variable_name: value}'''
326-
return eval(self.exec('sm.get_variables()').decode().strip())
326+
return eval(self.eval('{k: repr(v) for k, v in sm.variables.__dict__.items()}'))
327327

328328
def get_analog_inputs(self):
329329
'''Return analog_inputs as a directory {input name: ID}'''
@@ -429,8 +429,7 @@ def set_variable(self, v_name, v_value):
429429
return None
430430
else: # Set variable using REPL.
431431
checksum = sum(v_str.encode())
432-
set_OK = eval(self.eval("state_machine.set_variable({}, {}, {})"
433-
.format(repr(v_name), repr(v_str), checksum)).decode())
432+
set_OK = eval(self.eval(f'sm.set_variable({repr(v_name)}, {repr(v_str)}, {checksum})').decode())
434433
if set_OK:
435434
self.sm_info['variables'][v_name] = v_str
436435
return set_OK
@@ -447,5 +446,4 @@ def get_variable(self, v_name):
447446
checksum = sum(data).to_bytes(2, 'little')
448447
self.serial.write(b'V' + data_len + data + checksum)
449448
else: # Get variable using REPL.
450-
return eval(self.eval("state_machine.get_variable({})"
451-
.format(repr(v_name))).decode())
449+
return eval(self.eval(f'sm.get_variable({repr(v_name)})').decode())

pyControl/state_machine.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,4 @@ def get_variable(v_name):
105105
try:
106106
return repr(getattr(variables, v_name))
107107
except Exception:
108-
return None
109-
110-
def get_events():
111-
# Print events dict to USB serial.
112-
print(events)
113-
114-
def get_states():
115-
# Print states dict to USB serial.
116-
print(states)
117-
118-
def get_variables():
119-
# Print state machines variables as dict {v_name: repr(v_value)} to USB serial.
120-
print({k: repr(v) for k, v in variables.__dict__.items()})
108+
return None # Bad variable name

0 commit comments

Comments
 (0)