Created
January 3, 2020 13:19
-
-
Save sophec/a1318a5a3bdb7f2cdfe95fcd965d9538 to your computer and use it in GitHub Desktop.
A script to get the details of an exported GPIO device.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash -e | |
if [[ $# < 2 ]]; then | |
echo "Example usage: $0 1 27" | |
echo "This would get the details of GPIO1_27 if it's exported." | |
exit 1 | |
fi | |
DEVNUM=$(( 32 * $1 + $2 )) | |
if [ ! -d "/sys/class/gpio/gpio$DEVNUM" ]; then | |
echo "Could not find GPIO$1_$2! Make sure it was exported!" | |
exit 1 | |
fi | |
echo "# Device found: gpio$DEVNUM" | |
for file in /sys/class/gpio/gpio$DEVNUM/*; do | |
if [ -f "$file" ]; then | |
echo -n "- ${file//"/sys/class/gpio/gpio$DEVNUM/"}: " | |
CONTENTS="$(cat "$file")" | |
if [ -z "$CONTENTS" ]; then | |
echo "<EMPTY>" | |
else | |
echo "$CONTENTS" | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment