slitaz-arm annotate rpi/piface @ rev 207

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