aboutsummaryrefslogtreecommitdiff
path: root/recipes-demo/de10-nano-gpio-apps/files/show_KEY0_pb_state.sh
blob: a71d366aba6d4f7ab34821f2a0386e223c7de2cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/sh

# locate the gpio controller for the KEY0 push button 'gpio@0x100005000'
GPIO_DIRNAME="unknown"
for NEXT in $(find /sys/class/gpio -name "gpiochip*" | sort)
do
	cat "${NEXT}/label" | grep "gpio@0x100005000" > /dev/null && {
		GPIO_DIRNAME="${NEXT}"
		break
	}
done

[ "unknown" == "${GPIO_DIRNAME}" ] && {
	echo "unable to locate gpio controller"
	exit 1
} || {
	# the KEY0 gpio is the first gpio in this controller
	GPIO_NUMBER="$(cat "${GPIO_DIRNAME}/base")"
	echo "${GPIO_NUMBER}" > /sys/class/gpio/export
	GPIO_VALUE="$(cat /sys/class/gpio/gpio${GPIO_NUMBER}/value)"
	echo "KEY0 push button is at state '${GPIO_VALUE}'"
	echo "${GPIO_NUMBER}" > /sys/class/gpio/unexport
}