#!/bin/bash

cd /sys/class/gpio

if [ $# -eq 2 ]
then
	case "$1" in
	--net) 
		if [ ! -d "gpio153" ]
		then
			echo 153 > export
		fi
		cd gpio153
		echo "out" > direction
		echo $2 > value;;
	--sys) 
		if [ ! -d "gpio41" ] && [ ! -d "gpio42" ]
		then
			echo 41 > export
			echo 42 > export
		fi

		echo "out" > ./gpio41/direction
		echo "out" > ./gpio42/direction
		
		case "$2" in
		0)
			echo 0 > ./gpio41/value
			echo 0 > ./gpio42/value;;
		1)
			echo 0 > ./gpio41/value
			echo 1 > ./gpio42/value;;
		2)
			echo 1 > ./gpio41/value
			echo 0 > ./gpio42/value;;
		*)
			echo "param error";;
		esac;;
	*) echo "option error";;
	esac
	shift
else
	echo "paramters number error!!!"
	echo "Usage gpioN --sys param/--net param"
fi