Skip to content
Snippets Groups Projects
Commit 85f38e02 authored by Tobias Kahlki's avatar Tobias Kahlki
Browse files

scripts: Add simple GPIO loopback script

This uses gpioset/gpioget to set an output and read back the value from
an input.
parent d1415dd3
No related branches found
No related tags found
1 merge request!293Add GPIOs to emission/immunity tests for MV
#!/bin/sh
GPIO_OUT=$(gpiofind "$1")
GPIO_IN=$(gpiofind "$2")
RETVAL=0
print_help() {
echo "Usage: simple_gpio_loopback.sh [Output] [Input]"
echo ""
echo "Example:"
echo " simple_gpio_loopback.sh GPIO13 GPIO12"
}
if [ -z "$1" ]; then
echo "ERROR: Output not set ($1 / $2)"
print_help
exit 1
elif [ -z "$2" ]; then
echo "ERROR: Input not set ($1 / $2)"
print_help
exit 1
elif [ -z "$GPIO_OUT" ]; then
echo "ERROR: Lookup of Output failed ($1 / $2)"
print_help
exit 1
elif [ -z "$GPIO_IN" ]; then
echo "ERROR: Lookup of Input failed ($1 / $2)"
print_help
exit 1
fi
echo "OUT: $GPIO_OUT - IN: $GPIO_IN"
# shellcheck disable=2086
gpioset --mode=signal $GPIO_OUT=1 &
PID="$!"
sleep 0.5
# shellcheck disable=2046 disable=2086
if ! [ 1 -eq $(gpioget $GPIO_IN) ]; then
echo "ERROR: Input value does not match ($1 / $2)"
RETVAL=1
fi
kill $PID
# shellcheck disable=2086
gpioset $GPIO_OUT=0
exit $RETVAL
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment