slitaz-arm rev 184

Add piface utility
author Christophe Lincoln <pankso@slitaz.org>
date Sun May 11 21:44:43 2014 +0200 (2014-05-11)
parents 054c80b093ca
children 9bc526b4f259
files rpi/piface
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rpi/piface	Sun May 11 21:44:43 2014 +0200
     1.3 @@ -0,0 +1,83 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# PiFace - PiFace SHell utility using libpifacedigital and WiringPi
     1.7 +#
     1.8 +# (C) 2014 SliTaz GNU/Linux - BSD License
     1.9 +#
    1.10 +. /lib/libtaz.sh
    1.11 +check_root
    1.12 +
    1.13 +wiringpi_exec="/usr/lib/wiringpi/piface"
    1.14 +
    1.15 +usage() {
    1.16 +	cat << EOT
    1.17 +
    1.18 +$(boldify "Usage:") $(basename $0) [command] [beates]
    1.19 +
    1.20 +$(boldify "Commands:")
    1.21 +  testsuite     $(gettext "Run official pifacedigital testsuite")
    1.22 +  blink         $(gettext "Blink a Piface LED with WiringPi")
    1.23 +  buttons       $(gettext "Reads buttons and toggle first 4 outputs")
    1.24 +  motor         $(gettext "Motor control using WiringPi")
    1.25 +  reaction      $(gettext "LEDs and buttons reaction timer game")
    1.26 +  metronome     $(gettext "Turn on/off PiFace metronome [40-200 beates]")
    1.27 +
    1.28 +EOT
    1.29 +}
    1.30 +
    1.31 +# Usage: load_modules "mod1" "modN"
    1.32 +load_modules() {
    1.33 +	for mod in $@
    1.34 +	do
    1.35 +		if ! lsmod | grep -q ${mod}; then
    1.36 +			echo "Loading kernel module: $mod"
    1.37 +			modprobe ${mod}
    1.38 +		fi
    1.39 +	done
    1.40 +}
    1.41 +
    1.42 +# Usage: check_packages "pkg1" "pkg2"
    1.43 +check_packages() {
    1.44 +	db="/var/lib/tazpkg/installed"
    1.45 +	for pkg in $@; do
    1.46 +		[ -f "$db/$pkg/receipt" ] || spk-add ${pkg}
    1.47 +	done
    1.48 +}
    1.49 +
    1.50 +case "$1" in
    1.51 +		
    1.52 +	testsuite)
    1.53 +		load_modules "i2c_bcm2708" "i2c_dev"
    1.54 +		check_packages "libpifacedigital"
    1.55 +		pifacedigital-test ;;
    1.56 +	
    1.57 +	blink|buttons|motor|reaction)
    1.58 +		load_modules "i2c_bcm2708" "i2c_dev"
    1.59 +		check_packages "wiringpi-piface"
    1.60 +		newline
    1.61 +		${wiringpi_exec}/${1} ;;
    1.62 +	
    1.63 +	metronome)
    1.64 +		pid=$(pidof metro)
    1.65 +		load_modules "i2c-bcm2708" "i2c-dev"
    1.66 +		check_packages "wiringpi-piface"
    1.67 +		# Off
    1.68 +		if [ "$pid" ]; then
    1.69 +			kill ${pid} && exit 0
    1.70 +		fi
    1.71 +		# On
    1.72 +		beates="$2"
    1.73 +		[ "$beates" ] || beates=80
    1.74 +		if [ "$beates" -lt "40" ] || [ "$beates" -gt "200" ]; then
    1.75 +			echo "Metronome beates is out of range: 40-200" && exit 0
    1.76 +		fi
    1.77 +		newline
    1.78 +		colorize 35 "PiFace Metronome"
    1.79 +		separator
    1.80 +		echo "beates: $beates"
    1.81 +		${wiringpi_exec}/metro ${beates} >/dev/null & 
    1.82 +		newline ;;
    1.83 +	
    1.84 +	*) usage ;;
    1.85 +	
    1.86 +esac && exit 0