slitaz-arm view rpi/cgi-adm/plugins/rpi_gpio/rpi_gpio.cgi @ rev 182
Add raspicomm utility for RaspiComm board support
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Sat May 10 14:31:30 2014 +0200 (2014-05-10) |
parents | 71b3777ac5f1 |
children |
line source
1 #!/bin/sh
2 #
3 # TazBerry CGI Plugin - Raspberry Pi GPIO settings
4 #
6 case " $(GET) " in
8 *\ rpi_gpio\ *)
9 sysfs="/sys/class/gpio"
11 case " $(GET rpi_gpio) " in
12 *\ export\ *)
13 sysfs="/sys/class/gpio"
14 pin="$(GET pin)"
15 set="$(GET set)"
16 [ "$set" == "unexport" ] || html_header "GPIO pin: $pin"
17 if [ ! -d "$sysfs/gpio${pin}" ]; then
18 echo ${pin} > ${sysfs}/export
19 fi
20 # in/out
21 case "$set" in
22 in)
23 echo "0" > ${sysfs}/gpio${pin}/value
24 echo "in" > ${sysfs}/gpio${pin}/direction ;;
25 out)
26 echo "out" > ${sysfs}/gpio${pin}/direction ;;
27 write)
28 echo "out" > ${sysfs}/gpio${pin}/direction
29 echo "1" > ${sysfs}/gpio${pin}/value ;;
30 unexport)
31 echo "$pin" > ${sysfs}/unexport ;;
32 esac
33 [ "$set" == "unexport" ] || cat << EOT
34 <h1>Raspberry Pi GPIO pin: $pin</h1>
36 <pre>
37 Direction : $(cat $sysfs/gpio${pin}/direction)
38 Value : $(cat $sysfs/gpio${pin}/value)
39 </pre>
41 <div class="button">
42 <a href='$script?rpi_gpio=export&pin=$pin&set=in'>in</a>
43 <a href='$script?rpi_gpio=export&pin=$pin&set=out'>out</a>
44 <a href='$script?rpi_gpio=export&pin=$pin&set=write'>Write output</a>
45 <a href='$script?rpi_gpio=export&pin=$pin&set=unexport'>Unexport</a>
46 </div>
48 EOT
49 html_footer && [ "$set" == "unexport" ] || exit 0 ;;
50 esac
52 # Main page
53 html_header "GPIO pins"
55 cat << EOT
56 <h1>Raspberry Pi GPIO pins</h1>
58 <p>
59 The R-Pi offers GPIO lower-level interfaces intended to connect
60 more directly with chips and subsystem modules. Documentation on:
61 <a href="http://elinux.org/RPi_Low-level_peripherals">the Official Wiki</a>
62 </p>
64 <h2>$sysfs</h2>
65 <pre>
66 $(ls -1p $sysfs)
67 </pre>
69 <h2>Export GPIO pin</h2>
70 <div class="button">
71 EOT
72 for pin in 0 1 4 7 8 9 10 11 14 15 17 18 21 22 23 24 25 27
73 do
74 echo -n "<a href='$script?rpi_gpio=export&pin=$pin'>${pin}</a> "
75 done
76 echo '<div>'
77 html_footer && exit 0 ;;
78 esac