From a3629bd19aa064a007300e13098c068971726a97 Mon Sep 17 00:00:00 2001 From: Joseph Coffland Date: Mon, 20 Jun 2016 04:27:31 -0700 Subject: [PATCH] splash script, use LCD --- bbctrl.init.d | 10 +++++----- bbctrl.py | 29 ++++++++++++++++++++++++++++- lcd.py | 4 ++-- setup_rpi.sh | 9 ++++++++- splash.py | 11 +++++++++++ 5 files changed, 54 insertions(+), 9 deletions(-) create mode 100755 splash.py diff --git a/bbctrl.init.d b/bbctrl.init.d index 4dad98d..b7a0fb6 100644 --- a/bbctrl.init.d +++ b/bbctrl.init.d @@ -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 $? } diff --git a/bbctrl.py b/bbctrl.py index c7d6888..0a4e875 100755 --- 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 405a6b6..d857766 100755 --- 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): diff --git a/setup_rpi.sh b/setup_rpi.sh index 4b25426..dd38975 100755 --- a/setup_rpi.sh +++ b/setup_rpi.sh @@ -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 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) -- 2.27.0