# Request GPIO via sysfs, using gpiolib

echo "$0: do nothing"                                   
exit 1

# GPIO out (82-85), modem ignition (19)
gpio_out='82
83
84
85
19'

# GPIO in (54-57)
gpio_in='54
55
56
57'

SYS_DIR=/sys/class/gpio
name=`basename $0`

export_gpio() {
	gpio=$1
	direction=$2
	active_low=$3
	
	echo -n $gpio > $SYS_DIR/export
	if [ $? != 0 ]; then
		echo "$name: can't export GPIO$gpio"
		return 1
	fi
	
	echo -n $direction > $SYS_DIR/gpio$gpio/direction
	if [ $? != 0 ]; then
		echo "$name: can't set $direction dir for GPIO$gpio"
		return 1
	fi
	
	echo -n $active_low > $SYS_DIR/gpio$gpio/active_low
	
	return 0
}

unexport_gpio() {
	gpio=$1
	echo -n $gpio > $SYS_DIR/unexport
}

if [ "$1" = stop ]; then
	for gpio in $gpio_out $gpio_in; do
		unexport_gpio $gpio
	done
	
	exit 0
fi

echo -n "$name: export GPIO's as output: "
for gpio in $gpio_out; do
	export_gpio $gpio out 1 && echo -n "$gpio "
done
echo ""

echo -n "$name: export GPIO's as input:  "
for gpio in $gpio_in; do
	export_gpio $gpio in 1 && echo -n "$gpio "
done
echo ""
