Hardware Reference
In-Depth Information
Figure 10-16. The power control application directory and scripts
The first script I want to show you is the gpio-setup.sh script. Because I wanted the WEBrick server to be able to
be run from boot, I needed to create a script that would configure the GPIO pins the way I needed them to be. Take a
look at Listing 10-2 to see the contents of the script.
Listing 10-2. The gpio-setup.sh Script
#!/bin/bash
# Description : Set up GPIO pins, exit if they are already one
# GPIO 4 is the ON switch
# GPIO 17 is the OFF switch
# Author : Brendan Horan
function check {
if [ -e "/sys/class/gpio/gpio4" ]
then
exit
fi
}
function export {
# Export the GPIO pins
echo 4 > /sys/class/gpio/export
echo 17 > /sys/class/gpio/export
}
function direction {
# Set the GPIO pins to be outputs
echo out > /sys/class/gpio/gpio4/direction
echo out > /sys/class/gpio/gpio17/direction
}
 
Search WWH ::




Custom Search