Removed LCD force, Retry AVR connection
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 21 Dec 2016 10:45:25 +0000 (02:45 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Wed, 21 Dec 2016 10:45:25 +0000 (02:45 -0800)
scripts/setup_rpi.sh
src/py/bbctrl/AVR.py
src/py/bbctrl/LCD.py

index 0b8545e6e6eb731ff93dc10a3752ab14faad7c50..2ee7118c63a56468b03e04d2f7a8efc326b153d3 100755 (executable)
@@ -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
 
index 5a534c94d3b62cd855604002d314bd9567f52ef5..f947c0ecc68ee0763aa16d0a0170598fc6a9ae05 100644 (file)
@@ -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)
index 9a6a03721ac74541002dd842a5c570b72bf2ae2f..1910b4bd24d0785d1155699f7a1aa77b66571630 100644 (file)
@@ -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):