slitaz-arm view rpi/piface @ rev 184
Add piface utility
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sun May 11 21:44:43 2014 +0200 (2014-05-11) |
parents | |
children | 9bc526b4f259 |
line source
1 #!/bin/sh
2 #
3 # PiFace - PiFace SHell utility using libpifacedigital and WiringPi
4 #
5 # (C) 2014 SliTaz GNU/Linux - BSD License
6 #
7 . /lib/libtaz.sh
8 check_root
10 wiringpi_exec="/usr/lib/wiringpi/piface"
12 usage() {
13 cat << EOT
15 $(boldify "Usage:") $(basename $0) [command] [beates]
17 $(boldify "Commands:")
18 testsuite $(gettext "Run official pifacedigital testsuite")
19 blink $(gettext "Blink a Piface LED with WiringPi")
20 buttons $(gettext "Reads buttons and toggle first 4 outputs")
21 motor $(gettext "Motor control using WiringPi")
22 reaction $(gettext "LEDs and buttons reaction timer game")
23 metronome $(gettext "Turn on/off PiFace metronome [40-200 beates]")
25 EOT
26 }
28 # Usage: load_modules "mod1" "modN"
29 load_modules() {
30 for mod in $@
31 do
32 if ! lsmod | grep -q ${mod}; then
33 echo "Loading kernel module: $mod"
34 modprobe ${mod}
35 fi
36 done
37 }
39 # Usage: check_packages "pkg1" "pkg2"
40 check_packages() {
41 db="/var/lib/tazpkg/installed"
42 for pkg in $@; do
43 [ -f "$db/$pkg/receipt" ] || spk-add ${pkg}
44 done
45 }
47 case "$1" in
49 testsuite)
50 load_modules "i2c_bcm2708" "i2c_dev"
51 check_packages "libpifacedigital"
52 pifacedigital-test ;;
54 blink|buttons|motor|reaction)
55 load_modules "i2c_bcm2708" "i2c_dev"
56 check_packages "wiringpi-piface"
57 newline
58 ${wiringpi_exec}/${1} ;;
60 metronome)
61 pid=$(pidof metro)
62 load_modules "i2c-bcm2708" "i2c-dev"
63 check_packages "wiringpi-piface"
64 # Off
65 if [ "$pid" ]; then
66 kill ${pid} && exit 0
67 fi
68 # On
69 beates="$2"
70 [ "$beates" ] || beates=80
71 if [ "$beates" -lt "40" ] || [ "$beates" -gt "200" ]; then
72 echo "Metronome beates is out of range: 40-200" && exit 0
73 fi
74 newline
75 colorize 35 "PiFace Metronome"
76 separator
77 echo "beates: $beates"
78 ${wiringpi_exec}/metro ${beates} >/dev/null &
79 newline ;;
81 *) usage ;;
83 esac && exit 0