def __init__(self, ctrl):
self.ctrl = ctrl
- self.listeners = []
self.queue = deque()
self.in_buf = ''
self.command = None
- ctrl.state.add_listener(self._update_state)
+ ctrl.state.add_listener(self._update)
try:
self.sp = serial.Serial(ctrl.args.serial, ctrl.args.baud,
self.i2c_addr = ctrl.args.avr_addr
- def add_listener(self, listener):
- self.listeners.append(listener)
-
-
def start_sending_gcode(self, path):
self.ctrl.planner.load(path)
self.set_write(True)
self.ctrl.ioloop.update_handler(self.sp, flags)
- def _update_state(self, update):
+ def _update(self, update):
if 'xx' in update and update['xx'] == 'ESTOPPED':
self.stop_sending_gcode()
except Exception as e:
log.warning('%s: %s', e, data)
- update = {}
-
# Parse incoming serial data into lines
while True:
i = self.in_buf.find('\n')
if 'variables' in msg:
self._update_vars(msg)
- continue
- if 'msg' in msg:
+ elif 'msg' in msg:
self._log_msg(msg)
- continue
- if 'firmware' in msg:
+ elif 'firmware' in msg:
log.warning('firmware rebooted')
self.connect()
- update.update(msg)
-
- if update:
- for listener in self.listeners: listener(update)
+ else: self.ctrl.state.update(msg)
def _serial_handler(self, fd, events):
def __init__(self, ctrl):
self.ctrl = ctrl
self.comm = bbctrl.Comm(ctrl)
-
self.stopping = False
- self.comm.add_listener(self._comm_update)
- self.comm.add_listener(self.ctrl.state.update)
+ ctrl.state.add_listener(self._update)
self.comm.queue_command(Cmd.REBOOT)
def _is_busy(self): return self.ctrl.planner.is_running()
- def _comm_update(self, update):
+ def _update(self, update):
if self.stopping and 'xx' in update and update['xx'] == 'HOLDING':
self.comm.stop_sending_gcode()
# Resume once current queue of GCode commands has flushed
def estop(self): self.comm.i2c_command(Cmd.ESTOP)
def clear(self): self.comm.i2c_command(Cmd.CLEAR)
-
-
- def start(self, path):
- if path: self.comm.start_sending_gcode(path)
+ def start(self, path): self.comm.start_sending_gcode(path)
def step(self, path):