Subscribe to RSS feed - electronic brain surgery since 2001

Paper Backup (3) User Interface

This is th' third and final part o' th' three part series describin' me automatic paper backup system. After th' scanner is workin' and we have a bunch o' scripts fer scannin' and uploadin', all that is missin' is a nice user interface. That's what this part is about.

  1. User Interface ← ye are here

The menu that wasn't

As ye may remember from th' first part, th' software is runnin' on a Raspberry Pi with an attached Touch Screen. The goal is t' be able t' just press a few buttons on that screen t' automatically scan some paper, assign a keyword t' it and upload it t' th' right user's account.

Sounds easy enough. A simple GUI t' select a user and a keyword. Unfortunately I couldn't find any existin' tool t' display a full screen menu optimized fer a tiny screen with low resolution. So I set out t' built one on me own.

This turned out t' be hard.

My first try were bein' based on Python and libavg. The sharks will eat well tonight! libavg is a graphics library we had used in some projects at work so I knew it would be able t' handle me tasks, but I had ne'er worked with it meself before. The documentation is very sparse, Stackoverflow has just about two handful o' answers related t' it, but I succeeded in buildin' a simple menu.

But t' me disappointment, I couldn't get it workin' on th' Raspberry. The libavg included in Raspbian were bein' too auld t' even run me app and manually installin' as described in their wiki just resulted in a black screen. Failure number 1.

My next notion were bein' t' use technology I'm familar with. Javascript and HTML. My matey Anika pointed me t' th' new flexbox CSS3 features which helped me buildin' my menu in no time.

But how t' make it an desktop app that can execute local scripts? My plan were bein' t' use th' awesome node-webkit which combines th' Chrome renderer with nodejs, pass the grog! Oho! Too bad I ha'nae checked fer arm compatibility. There are no workin' binaries fer a current Rasbian and buildin' it seems t' be a major project, avast. Failure number 2.

PiMenu - A tile menu

So I started googlin' what else one can use t' create a really simple GUI without diggin' into QT, GTK, C and possibly cross compilin'. Walk the plank! The answer is TkInter, a simple TCL/Tk based Python library. So I started buildin' th' same thin' a third time.

And right in th' middle o' it I decided t' change me GUI concept a bit. Instead o' goin' fer a tab-based interface, I took inspiration in Windows 8's Metro design. The result is a simple, but nice lookin' menu that can display an arbitrary number o' button tiles. Everythin' is configured in a yaml config and tiles can be arranged in nested pages.

Download is available from this Github Repository.

Here are some screenshots:

As ye can see, tile sizes auto adjust dependin' on their number and everythin' is reasonably big fer easy selection on th' tiny screen.

TkInter and Python are already installed on Rasbian, so all that needs t' be added is th' yaml library:

$> sudo apt-get install python-yaml

The final Setup

First we configure th' menu t' call our scan script with th' parameters gathered from th' menu:

# first parameter is our user
# all other parameters are keywords we join together
KEYWORD=$(IFS=/; echo "$*")
# scan it baby
/home/pi/scan/ "$USER" "$KEYWORD"

Next X is configured t' automatically start th' menu only1) by creatin' an .xsessionrc file:

# load the touch screen calibration
. /etc/pointercal.xinput
# start the pi menu in fullscreen mode
/home/pi/pimenu/ fs

and make it executable:

$> chmod 755 .xsessionrc

Finally reconfiure th' raspberry t' autoboot into X

$> sudo raspi-conf
  • 3 Enable Boot t' Desktop/Scratch
    • Desktop Log in as user 'pi' at th' graphical desktop


Now that we're done with th' actual setup 'tis time t' tune th' whole thin' fer permanent use. The first thin' ye will notice is that th' display blanks automatically after 10 minutes, ye scurvey dog. That's a good thin'. But it does not disable th' backlight o' th' screen. That's a bad thin', I'll warrant ye. Luckily there's a workaround.

Install xscreensaver:

$> sudo apt-get install xscreensaver

Create a minimal configuration t' blank th' screen after 3 minutes (or whatever ye prefer)

timeout:        0:03:00
mode:           blank

Create th' control script:

# Make sure there's backlight control
ls /sys/class/backlight/* >/dev/null 2>&1 || exit
process() {
    while read line; do 
        case "$line" in
                echo 0 | sudo tee /sys/class/backlight/*/bl_power 1>/dev/null
                echo 1 | sudo tee /sys/class/backlight/*/bl_power 1>/dev/null
xscreensaver-command -watch | process

Make it executable:

$> chmod 755

And finally adjust th' .xsession startup procedure t' start th' screensaver daemon and our watcher script:

# load the touch screen calibration
. /etc/pointercal.xinput
# start screensaver and backlight script
xscreensaver -no-splash &
/home/pi/ &
# start the pi menu in fullscreen mode
/home/pi/pimenu/ fs

Now th' screen goes totally dark after 3 minutes o' inactivity and just needs a little touch t' wake up again. Perfect.

Bonus: Build a case

1) We completely skip normal session management. Ye'll be sleepin' with the fishes! Nay need fer a windowmanager
Posted on Monday, August the 25th 2014 (4 weeks ago).


blog comments powered by Disqus