Skip to content

Instantly share code, notes, and snippets.

@yangl1996
Created May 14, 2017 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yangl1996/4e172a00be7c4fa9d308f9af6decfca7 to your computer and use it in GitHub Desktop.
Save yangl1996/4e172a00be7c4fa9d308f9af6decfca7 to your computer and use it in GitHub Desktop.
lightctl - control USB power on/off on BeagleBone Black
#!/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
@yangl1996
Copy link
Author

Need devmem2 and passwordless sudo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment