self.i2c_bus = None
log.warning('Failed to open device: %s', e)
- # Reset AVR communication
- self.stop();
- self.report()
+ self._i2c_connect()
def _start_sending_gcode(self, path):
self.stream = None
+ def _i2c_connect(self):
+ try:
+ # Reset AVR communication
+ self.stop();
+ self.report()
+
+ except:
+ self.ctrl.ioloop.call_later(1, self._i2c_connect)
+
+
def _i2c_command(self, cmd, byte = None, word = None):
if self.i2c_bus is None or not hasattr(self.i2c_bus, 'write_byte'):
return
else:
log.error('I2C communication failed: %s' % e)
- return
+ raise
def report(self): self._i2c_command(I2C_REPORT)
class LCD:
def __init__(self, ctrl):
self.ctrl = ctrl
- self.force = False
atexit.register(self.goodbye)
self.connect()
self.lcd = lcd.LCD(self.ctrl.args.lcd_port, self.ctrl.args.lcd_addr)
self.lcd.clear()
self.lcd.display(1, 'Loading', lcd.JUSTIFY_CENTER)
- self.force = True
except IOError as e:
log.error('Connect failed, retrying: %s' % e)
self.ctrl.ioloop.call_later(1, self.connect)
- def update(self, msg, force = False):
- def has(name): return self.force or force or name in msg
-
- if has('x') or has('c'):
+ def update(self, msg):
+ if 'x' in msg or 'c' in msg:
v = self.ctrl.avr.vars
state = v.get('x', 'INIT')
if 'c' in v and state == 'RUNNING': state = v['c']
self.lcd.text('%-9s' % state, 0, 0)
- if has('xp'): self.lcd.text('% 10.4fX' % msg['xp'], 9, 0)
- if has('yp'): self.lcd.text('% 10.4fY' % msg['yp'], 9, 1)
- if has('zp'): self.lcd.text('% 10.4fZ' % msg['zp'], 9, 2)
- if has('ap'): self.lcd.text('% 10.4fA' % msg['ap'], 9, 3)
- if has('t'): self.lcd.text('%2uT' % msg['t'], 6, 1)
- if has('u'): self.lcd.text('%s' % msg['u'], 0, 1)
- if has('f'): self.lcd.text('%8uF' % msg['f'], 0, 2)
- if has('s'): self.lcd.text('%8dS' % msg['s'], 0, 3)
-
- self.force = False
+ if 'xp' in msg: self.lcd.text('% 10.4fX' % msg['xp'], 9, 0)
+ if 'yp' in msg: self.lcd.text('% 10.4fY' % msg['yp'], 9, 1)
+ if 'zp' in msg: self.lcd.text('% 10.4fZ' % msg['zp'], 9, 2)
+ if 'ap' in msg: self.lcd.text('% 10.4fA' % msg['ap'], 9, 3)
+ if 't' in msg: self.lcd.text('%2uT' % msg['t'], 6, 1)
+ if 'u' in msg: self.lcd.text('%s' % msg['u'], 0, 1)
+ if 'f' in msg: self.lcd.text('%8uF' % msg['f'], 0, 2)
+ if 's' in msg: self.lcd.text('%8dS' % msg['s'], 0, 3)
def goodbye(self):