Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@yangl1996

yangl1996 May 14, 2017

Need devmem2 and passwordless sudo.

Owner

yangl1996 commented May 14, 2017

Need devmem2 and passwordless sudo.

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