Created
May 14, 2017 17:11
-
-
Save yangl1996/4e172a00be7c4fa9d308f9af6decfca7 to your computer and use it in GitHub Desktop.
lightctl - control USB power on/off on BeagleBone Black
This file contains 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
#!/usr/bin/bash | |
function lighton { | |
until sudo devmem2 0x47401c60 b 0x01 | |
do | |
echo "Trying again" | |
done | |
} | |
function lightoff { | |
until sudo devmem2 0x47401c60 b 0x00 | |
do | |
echo "Trying again" | |
done | |
} | |
function printhelp { | |
echo 'Usage: lightctl (on|off|status)' | |
echo 'Need passwordless sudo.' | |
} | |
function getstatus { | |
until sudo devmem2 0x47401c60 b | |
do | |
echo "Trying again" | |
done | |
} | |
function parsestatus { | |
outpu=$(getstatus) | |
if [[ $outpu == *'0x128'* ]]; | |
then | |
echo 'off' | |
elif [[ $outpu == *'0x25'* ]]; | |
then | |
echo 'on' | |
else | |
echo "error" | |
fi | |
} | |
if [ $# -eq 0 ]; | |
then | |
printhelp | |
elif [ $# -eq 1 ]; | |
then | |
if [ "$1" == 'on' ]; | |
then | |
lighton &> /dev/null | |
elif [ "$1" == 'off' ]; | |
then | |
lightoff &> /dev/null | |
elif [ "$1" == 'status' ]; | |
then | |
parsestatus | |
else | |
printhelp | |
fi | |
else | |
printhelp | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Need
devmem2
and passwordless sudo.