slitaz-arm view rpi/pibrella @ rev 214

tazbian: typo
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu May 05 17:03:59 2016 +0200 (2016-05-05)
parents
children
line source
1 #!/bin/sh
2 #
3 # Pibrella - SliTaz Raspberry Pibrella SHell utility
4 #
5 # (C) 2014 SliTaz GNU/Linux - BSD License
6 #
7 . /lib/libtaz.sh
8 check_root
10 sysfs="/sys/class/gpio"
12 # Pibrella Pins
13 led_red=27
14 led_yellow=17
15 led_green=4
17 buzzer=18
19 usage() {
20 cat << EOT
22 $(boldify 'Usage:') $(basename $0) [command] [color] [seconds|on|off]
24 $(boldify 'Commands:')
25 testsuite $(gettext 'Run a small testsuite on Pibrella')
26 led $(gettext 'Turn on/off LEDs or on for N seconds')
28 EOT
29 }
31 # Usage: export_pin NB --> librpigpio.sh
32 export_pin() {
33 if [ ! -d "${sysfs}/gpio${1}" ]; then
34 echo ${1} > ${sysfs}/export
35 fi
36 }
38 case "$1" in
40 testsuite)
41 # LEDs
42 for pin in ${led_red} ${led_yellow} ${led_green}
43 do
44 export_pin ${pin}
45 echo "out" > ${sysfs}/gpio${pin}/direction
46 echo "1" > ${sysfs}/gpio${pin}/value
47 sleep 2
48 echo "0" > ${sysfs}/gpio${pin}/value
49 done ;;
51 led)
52 case "$2" in
53 r|red) pin=${led_red} ;;
54 y|yellow) pin=${led_yellow} ;;
55 g|green) pin= ${led_green} ;;
56 esac
57 case "$3" in
58 on) echo "1" > ${sysfs}/gpio${pin}/value ;;
59 off) echo "0" > ${sysfs}/gpio${pin}/value ;;
60 *)
61 sec="$3"
62 [ "$sec" ] || sec=1
63 echo "1" > ${sysfs}/gpio${pin}/value
64 sleep ${sec}
65 echo "0" > ${sysfs}/gpio${pin}/value ;;
66 esac ;;
68 *)
69 usage ;;
71 esac
72 exit 0