splash script, use LCD
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Mon, 20 Jun 2016 11:27:31 +0000 (04:27 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Mon, 20 Jun 2016 11:27:31 +0000 (04:27 -0700)
bbctrl.init.d
bbctrl.py
lcd.py
setup_rpi.sh
splash.py [new file with mode: 0755]

index 4dad98d75fcbabf2963795c47b38fbe003543d9d..b7a0fb6f71db1bc3791e677ed9d1760f585283aa 100644 (file)
@@ -2,8 +2,8 @@
 
 ### BEGIN INIT INFO
 # Provides:          bbctl
-# Required-Start:    $remote_fs $syslog
-# Required-Stop:     $remote_fs $syslog
+# Required-Start:    $local_fs $network
+# Required-Stop:     $local_fs $network
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: Buildbotics Controller Web service
@@ -17,15 +17,15 @@ DAEMON_USER=root
 DAEMON_DIR=$(dirname $DAEMON)
 PIDFILE=/var/run/$DAEMON_NAME.pid
 
-
 . /lib/lsb/init-functions
 
 
 do_start () {
     log_daemon_msg "Starting system $DAEMON_NAME daemon"
     start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile \
-        --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON \
-        --chdir $DAEMON_DIR -- $DAEMON_OPTS
+        --user $DAEMON_USER --chuid $DAEMON_USER --chdir $DAEMON_DIR \
+        --startas /bin/bash -- \
+        -c "exec $DAEMON $DAEMON_OPTS > /var/log/$DAEMON_NAME.log 2>&1"
     log_end_msg $?
 }
 
index c7d6888fff81bd15e20c26d2b69d0442615df061..0a4e8759008befb919c959abe8e0285dc325903f 100755 (executable)
--- a/bbctrl.py
+++ b/bbctrl.py
@@ -7,6 +7,8 @@ HTTP_PORT = 8080
 HTTP_ADDR = '0.0.0.0'
 
 import os
+import sys
+import signal
 from tornado import web, ioloop, escape
 from sockjs.tornado import SockJSRouter, SockJSConnection
 import json
@@ -14,7 +16,9 @@ import serial
 import multiprocessing
 import time
 import select
+import atexit
 
+import lcd
 import inevent
 from inevent.Constants import *
 
@@ -31,7 +35,7 @@ config = {
     }
 
 
-with open('http/config-template.json', 'r') as f:
+with open('http/config-template.json', 'r', encoding = 'utf-8') as f:
     config_template = json.load(f)
 
 
@@ -42,6 +46,11 @@ input_queue = multiprocessing.Queue()
 output_queue = multiprocessing.Queue()
 
 
+def on_exit(sig, func = None):
+    print('exit handler triggered')
+    sys.exit(1)
+
+
 def encode_cmd(index, value, spec):
     if spec['type'] == 'enum': value = spec['values'].index(value)
     elif spec['type'] == 'bool': value = 1 if value else 0
@@ -310,9 +319,24 @@ def checkEvents():
 eventProcessor = inevent.InEvent(types = "js kbd".split())
 eventHandler = JogHandler(config)
 
+screen = lcd.LCD(1, 0x27)
+
+
+def splash():
+    screen.clear()
+    screen.display(0, 'Buildbotics', lcd.JUSTIFY_CENTER)
+    screen.display(1, 'Controller', lcd.JUSTIFY_CENTER)
+    screen.display(3, '*Ready*', lcd.JUSTIFY_CENTER)
+
+
+def goodbye():
+    screen.clear()
+    screen.display(1, 'Goodbye', lcd.JUSTIFY_CENTER)
 
 
 if __name__ == "__main__":
+    signal.signal(signal.SIGTERM, on_exit)
+
     import logging
     logging.getLogger().setLevel(logging.DEBUG)
 
@@ -328,6 +352,9 @@ if __name__ == "__main__":
     ioloop.PeriodicCallback(checkQueue, 100).start()
     ioloop.PeriodicCallback(checkEvents, 100).start()
 
+    splash()
+    atexit.register(goodbye)
+
     # Start the web server
     app = web.Application(router.urls + handlers)
     app.listen(HTTP_PORT, address = HTTP_ADDR)
diff --git a/lcd.py b/lcd.py
index 405a6b652dfb32dba84669f3d14e3587d7480920..d8577662b145a78b2b740a262b254160233d52d6 100755 (executable)
--- a/lcd.py
+++ b/lcd.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 import smbus
 import time
@@ -123,7 +123,7 @@ class LCD:
 
     def goto(self, x, y):
         if x < 0 or self.width <= x or y < 0 or self.height <= y: return
-        self.write(LCD_SET_DDRAM_ADDR | (0, 64, 20, 84)[y] + x)
+        self.write(LCD_SET_DDRAM_ADDR | (0, 64, 20, 84)[y] + int(x))
 
 
     def text(self, msg):
index 4b2542675f6a3afda2e0f03163ee910db88df5a0..dd389750d21bbfa6f3f931baa3814b3afe116a03 100755 (executable)
@@ -79,12 +79,19 @@ 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 extra gettys
+sed -i 's/^\([23456]:.*\/sbin\/getty\)/#\1/' /etc/inittab
+
 # Enable I2C
 sed -i 's/#dtparam=i2c/dtparam=i2c/' /boot/config.txt
 echo i2c-bcm2708 >> /etc/modules
 echo i2c-dev >> /etc/modules
 
+# Install bbctrl w/ init.d script
+cp bbctrl.init.d /etc/init.d/bbctrl
+chmod +x /etc/init.d/bbctrl
+update-rc.d bbctrl defaults
+
 # TODO setup input and serial device permissions in udev
-# TODO install bbctrl w/ init.d script
 
 reboot
diff --git a/splash.py b/splash.py
new file mode 100755 (executable)
index 0000000..d4277c1
--- /dev/null
+++ b/splash.py
@@ -0,0 +1,11 @@
+#!/usr/bin/env python3
+
+import lcd
+
+if __name__ == "__main__":
+    screen = lcd.LCD(1, 0x27)
+
+    screen.clear()
+    screen.display(0, 'Buildbotics', lcd.JUSTIFY_CENTER)
+    screen.display(1, 'Controller', lcd.JUSTIFY_CENTER)
+    screen.display(3, 'Booting...', lcd.JUSTIFY_CENTER)