slitaz-arm diff rpi/pibrella @ rev 189

Add Pibrella utility
author Christophe Lincoln <pankso@slitaz.org>
date Thu May 15 21:40:05 2014 +0200 (2014-05-15)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rpi/pibrella	Thu May 15 21:40:05 2014 +0200
     1.3 @@ -0,0 +1,72 @@
     1.4 +#!/bin/sh
     1.5 +#
     1.6 +# Pibrella - SliTaz Raspberry Pibrella SHell utility
     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 +sysfs="/sys/class/gpio"
    1.14 +
    1.15 +# Pibrella Pins
    1.16 +led_red=27
    1.17 +led_yellow=17
    1.18 +led_green=4
    1.19 +
    1.20 +buzzer=18
    1.21 +
    1.22 +usage() {
    1.23 +	cat << EOT
    1.24 +
    1.25 +$(boldify 'Usage:') $(basename $0) [command] [color] [seconds|on|off]
    1.26 +
    1.27 +$(boldify 'Commands:')
    1.28 +  testsuite   $(gettext 'Run a small testsuite on Pibrella')
    1.29 +  led         $(gettext 'Turn on/off LEDs or on for N seconds')
    1.30 +
    1.31 +EOT
    1.32 +}
    1.33 +
    1.34 +# Usage: export_pin NB --> librpigpio.sh
    1.35 +export_pin() {
    1.36 +	if [ ! -d "${sysfs}/gpio${1}" ]; then
    1.37 +		echo ${1} > ${sysfs}/export
    1.38 +	fi
    1.39 +}
    1.40 +
    1.41 +case "$1" in
    1.42 +	
    1.43 +	testsuite)
    1.44 +		# LEDs
    1.45 +		for pin in ${led_red} ${led_yellow} ${led_green}
    1.46 +		do
    1.47 +			export_pin ${pin}
    1.48 +			echo "out" > ${sysfs}/gpio${pin}/direction
    1.49 +			echo "1" > ${sysfs}/gpio${pin}/value 
    1.50 +			sleep 2 
    1.51 +			echo "0" > ${sysfs}/gpio${pin}/value
    1.52 +		done ;;
    1.53 +	
    1.54 +	led)
    1.55 +		case "$2" in
    1.56 +			r|red) pin=${led_red} ;;
    1.57 +			y|yellow) pin=${led_yellow} ;;
    1.58 +			g|green) pin= ${led_green} ;;
    1.59 +		esac
    1.60 +		case "$3" in
    1.61 +			on) echo "1" > ${sysfs}/gpio${pin}/value ;;
    1.62 +			off) echo "0" > ${sysfs}/gpio${pin}/value ;;
    1.63 +			*)
    1.64 +				sec="$3"
    1.65 +				[ "$sec" ] || sec=1
    1.66 +				echo "1" > ${sysfs}/gpio${pin}/value
    1.67 +				sleep ${sec} 
    1.68 +				echo "0" > ${sysfs}/gpio${pin}/value ;;
    1.69 +		esac ;;
    1.70 +		
    1.71 +	*)
    1.72 +		usage ;;
    1.73 +		
    1.74 +esac
    1.75 +exit 0