Split out LCD screens
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 22 Feb 2018 08:36:40 +0000 (00:36 -0800)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 22 Feb 2018 08:36:40 +0000 (00:36 -0800)
src/py/bbctrl/Ctrl.py
src/py/bbctrl/IPLCDPage.py [new file with mode: 0644]
src/py/bbctrl/Mach.py
src/py/bbctrl/MainLCDPage.py [new file with mode: 0644]
src/py/bbctrl/State.py
src/py/bbctrl/__init__.py

index c327a865f3f0190e13bc1850827f2693d1de3759..99a31db81362037d389ca8f20918641f03cd1280 100644 (file)
@@ -26,7 +26,6 @@
 ################################################################################
 
 import logging
-import subprocess
 
 import bbctrl
 
@@ -34,25 +33,6 @@ import bbctrl
 log = logging.getLogger('Ctrl')
 
 
-class IPPage(bbctrl.LCDPage):
-    def update(self):
-        p = subprocess.Popen(['hostname', '-I'], stdout = subprocess.PIPE)
-        ips = p.communicate()[0].decode('utf-8').split()
-
-        p = subprocess.Popen(['hostname'], stdout = subprocess.PIPE)
-        hostname = p.communicate()[0].decode('utf-8').strip()
-
-        self.clear()
-
-        self.text('Host: %s' % hostname[0:14], 0, 0)
-
-        for i in range(min(3, len(ips))):
-            if len(ips[i]) <= 16:
-                self.text('IP: %s' % ips[i], 0, i + 1)
-
-
-    def activate(self): self.update()
-
 
 class Ctrl(object):
     def __init__(self, args, ioloop):
@@ -74,6 +54,7 @@ class Ctrl(object):
 
             self.mach.comm.connect()
 
-            self.lcd.add_new_page(IPPage(self.lcd))
+            self.lcd.add_new_page(bbctrl.MainLCDPage(self))
+            self.lcd.add_new_page(bbctrl.IPLCDPage(self.lcd))
 
         except Exception as e: log.exception(e)
diff --git a/src/py/bbctrl/IPLCDPage.py b/src/py/bbctrl/IPLCDPage.py
new file mode 100644 (file)
index 0000000..4f5ee4e
--- /dev/null
@@ -0,0 +1,48 @@
+################################################################################
+#                                                                              #
+#                This file is part of the Buildbotics firmware.                #
+#                                                                              #
+#                  Copyright (c) 2015 - 2018, Buildbotics LLC                  #
+#                             All rights reserved.                             #
+#                                                                              #
+#     This file ("the software") is free software: you can redistribute it     #
+#     and/or modify it under the terms of the GNU General Public License,      #
+#      version 2 as published by the Free Software Foundation. You should      #
+#      have received a copy of the GNU General Public License, version 2       #
+#     along with the software. If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                              #
+#     The software is distributed in the hope that it will be useful, but      #
+#          WITHOUT ANY WARRANTY; without even the implied warranty of          #
+#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       #
+#               Lesser General Public License for more details.                #
+#                                                                              #
+#       You should have received a copy of the GNU Lesser General Public       #
+#                License along with the software.  If not, see                 #
+#                       <http://www.gnu.org/licenses/>.                        #
+#                                                                              #
+#                For information regarding this software email:                #
+#                  "Joseph Coffland" <joseph@buildbotics.com>                  #
+#                                                                              #
+################################################################################
+
+import subprocess
+
+import bbctrl
+
+
+class IPLCDPage(bbctrl.LCDPage):
+    # From bbctrl.LCDPage
+    def activate(self):
+        p = subprocess.Popen(['hostname', '-I'], stdout = subprocess.PIPE)
+        ips = p.communicate()[0].decode('utf-8').split()
+
+        p = subprocess.Popen(['hostname'], stdout = subprocess.PIPE)
+        hostname = p.communicate()[0].decode('utf-8').strip()
+
+        self.clear()
+
+        self.text('Host: %s' % hostname[0:14], 0, 0)
+
+        for i in range(min(3, len(ips))):
+            if len(ips[i]) <= 16:
+                self.text('IP: %s' % ips[i], 0, i + 1)
index f99b4a850ab00ea309753f5f88c69de2d734a116..367d7cfc0b949d3fa82eb5d8b15a495bb29d0e91 100644 (file)
@@ -63,10 +63,6 @@ class Mach():
 
         self.comm.add_listener(self._comm_update)
         self.comm.add_listener(self.ctrl.state.update)
-        ctrl.state.add_listener(self._update_lcd)
-
-        self.lcd_page = ctrl.lcd.add_new_page()
-        self.install_page = True
 
         self.comm.queue_command(Cmd.REBOOT)
 
@@ -82,39 +78,12 @@ class Mach():
             self.comm.queue_command(Cmd.RESUME)
             self.stopping = False
 
-        # Must be after machine vars have loaded
-        if self.install_page:
-            self.install_page = False
-            self.ctrl.lcd.set_current_page(self.lcd_page.id)
-
-
-    def _update_lcd(self, update):
-        if 'xx' in update:
-            self.lcd_page.text('%-9s' % self.ctrl.state.get('xx'), 0, 0)
-
-         # Automatically unpause on seek hold
+        # Automatically unpause on seek hold
         if self.ctrl.state.get('xx', '') == 'HOLDING' and \
                 self.ctrl.state.get('pr', '') == 'Switch found' and \
                 self.ctrl.planner.is_synchronizing():
             self.ctrl.mach.unpause()
 
-       # Show enabled axes
-        row = 0
-        for axis in 'xyzabc':
-            motor = self.ctrl.state.find_motor(axis)
-            if motor is not None:
-                if (axis + 'p') in update:
-                    self.lcd_page.text('% 10.3f%s' % (
-                            update[axis + 'p'], axis.upper()), 9, row)
-
-                row += 1
-
-        # Show tool, units, feed and speed
-        if 'tool'  in update: self.lcd_page.text('%2uT' % update['tool'],  6, 1)
-        if 'units' in update: self.lcd_page.text('%-6s' % update['units'], 0, 1)
-        if 'feed'  in update: self.lcd_page.text('%8uF' % update['feed'],  0, 2)
-        if 'speed' in update: self.lcd_page.text('%8dS' % update['speed'], 0, 3)
-
 
     def set(self, code, value):
         self.comm.queue_command('${}={}'.format(code, value))
diff --git a/src/py/bbctrl/MainLCDPage.py b/src/py/bbctrl/MainLCDPage.py
new file mode 100644 (file)
index 0000000..05ac51a
--- /dev/null
@@ -0,0 +1,65 @@
+################################################################################
+#                                                                              #
+#                This file is part of the Buildbotics firmware.                #
+#                                                                              #
+#                  Copyright (c) 2015 - 2018, Buildbotics LLC                  #
+#                             All rights reserved.                             #
+#                                                                              #
+#     This file ("the software") is free software: you can redistribute it     #
+#     and/or modify it under the terms of the GNU General Public License,      #
+#      version 2 as published by the Free Software Foundation. You should      #
+#      have received a copy of the GNU General Public License, version 2       #
+#     along with the software. If not, see <http://www.gnu.org/licenses/>.     #
+#                                                                              #
+#     The software is distributed in the hope that it will be useful, but      #
+#          WITHOUT ANY WARRANTY; without even the implied warranty of          #
+#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       #
+#               Lesser General Public License for more details.                #
+#                                                                              #
+#       You should have received a copy of the GNU Lesser General Public       #
+#                License along with the software.  If not, see                 #
+#                       <http://www.gnu.org/licenses/>.                        #
+#                                                                              #
+#                For information regarding this software email:                #
+#                  "Joseph Coffland" <joseph@buildbotics.com>                  #
+#                                                                              #
+################################################################################
+
+import bbctrl
+
+
+class MainLCDPage(bbctrl.LCDPage):
+    def __init__(self, ctrl):
+        bbctrl.LCDPage.__init__(self, ctrl.lcd)
+
+        self.ctrl = ctrl
+        self.install = True
+
+        ctrl.state.add_listener(self.update)
+
+
+    def update(self, update):
+        # Must be after machine vars have loaded
+        if self.install and hasattr(self, 'id'):
+            self.install = False
+            self.ctrl.lcd.set_current_page(self.id)
+
+        if 'xx' in update:
+            self.text('%-9s' % self.ctrl.state.get('xx'), 0, 0)
+
+       # Show enabled axes
+        row = 0
+        for axis in 'xyzabc':
+            motor = self.ctrl.state.find_motor(axis)
+            if motor is not None:
+                if (axis + 'p') in update:
+                    self.text('% 10.3f%s' % (update[axis + 'p'], axis.upper()),
+                              9, row)
+
+                row += 1
+
+        # Show tool, units, feed and speed
+        if 'tool'  in update: self.text('%2uT' % update['tool'],  6, 1)
+        if 'units' in update: self.text('%-6s' % update['units'], 0, 1)
+        if 'feed'  in update: self.text('%8uF' % update['feed'],  0, 2)
+        if 'speed' in update: self.text('%8dS' % update['speed'], 0, 3)
index 20e836aaffa6e85a7833815e930f7db710d390e1..47355e4f19a1bc6c68a0dcdb04e61c7b1d8307a7 100644 (file)
@@ -39,7 +39,6 @@ machine_state_vars = '''xp yp zp ap bp cp t fo so'''.split()
 class State(object):
     def __init__(self, ctrl):
         self.ctrl = ctrl
-        self.vars = {}
         self.callbacks = {}
         self.changes = {}
         self.listeners = []
@@ -48,6 +47,15 @@ class State(object):
         self.machine_var_set = set()
         self.machine_cmds = {}
 
+        # Defaults
+        self.vars = {
+            'line': -1,
+            'tool': 0,
+            'units': 'METRIC',
+            'feed': 0,
+            'speed': 0,
+        }
+
         for i in range(4):
             # Add home direction callbacks
             self.set_callback(str(i) + 'hd',
@@ -63,9 +71,6 @@ class State(object):
         # Zero offsets
         for axis in 'xyzabc': self.vars['offset_' + axis] = 0
 
-        # No line
-        self.vars['line'] = -1
-
 
     def _notify(self):
         if not self.changes: return
index 51c75422756895e2f927899853edae104be9fcab..65607a03b8448093101d907cfb998cfdaa92de6e 100644 (file)
@@ -51,6 +51,8 @@ from bbctrl.Planner import Planner
 from bbctrl.State import State
 from bbctrl.Messages import Messages
 from bbctrl.Comm import Comm
+from bbctrl.MainLCDPage import MainLCDPage
+from bbctrl.IPLCDPage import IPLCDPage
 import bbctrl.Cmd as Cmd