From: Joseph Coffland Date: Wed, 21 Dec 2016 10:45:25 +0000 (-0800) Subject: Removed LCD force, Retry AVR connection X-Git-Url: https://git.buildbotics.com/?a=commitdiff_plain;h=0f1e48b0b0c87018f71478b62950688d12c7e142;p=bbctrl-firmware Removed LCD force, Retry AVR connection --- diff --git a/scripts/setup_rpi.sh b/scripts/setup_rpi.sh index 0b8545e..2ee7118 100755 --- a/scripts/setup_rpi.sh +++ b/scripts/setup_rpi.sh @@ -78,6 +78,9 @@ echo "bbmc ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers #sed -i 's/^\(.*ttyAMA0.*\)$/# \1/' /etc/inittab sed -i 's/console=ttyAMA0,115200 //' /boot/cmdline.txt +# Disable i2c HAT ID probe +echo -n " bcm2708.vc_i2c_override=1" >> /boot/cmdline.txt + # Disable extra gettys sed -i 's/^\([23456]:.*\/sbin\/getty\)/#\1/' /etc/inittab diff --git a/src/py/bbctrl/AVR.py b/src/py/bbctrl/AVR.py index 5a534c9..f947c0e 100644 --- a/src/py/bbctrl/AVR.py +++ b/src/py/bbctrl/AVR.py @@ -61,9 +61,7 @@ class AVR(): 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): @@ -80,6 +78,16 @@ class AVR(): 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 @@ -110,7 +118,7 @@ class AVR(): else: log.error('I2C communication failed: %s' % e) - return + raise def report(self): self._i2c_command(I2C_REPORT) diff --git a/src/py/bbctrl/LCD.py b/src/py/bbctrl/LCD.py index 9a6a037..1910b4b 100644 --- a/src/py/bbctrl/LCD.py +++ b/src/py/bbctrl/LCD.py @@ -9,7 +9,6 @@ log = logging.getLogger('LCD') class LCD: def __init__(self, ctrl): self.ctrl = ctrl - self.force = False atexit.register(self.goodbye) self.connect() @@ -20,33 +19,28 @@ class LCD: 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):