Last active
August 29, 2015 14:07
-
-
Save bdunlay/2f30972faacc9e1bfc32 to your computer and use it in GitHub Desktop.
dims on over a specified period of time
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
#!/bin/bash | |
################################################### | |
PATH_WHERE_YOUR_SCRIPTS_LIVE="" | |
export PATH=$PATH:$PATH_WHERE_YOUR_SCRIPTS_LIVE | |
################################################### | |
function usage | |
{ | |
echo "\nDims a lightbulb over a specified number of minutes" | |
echo "\nUsage:\n\t$0 [minutes] \n" | |
} | |
function validate | |
{ | |
if [ $# -eq 0 ]; then | |
usage | |
exit 1 | |
fi | |
re='^[0-9]+$' | |
if ! [[ $1 =~ $re ]] ; then | |
echo "Error: $0 - Not an integer" >&2; | |
usage | |
exit 1 | |
fi | |
} | |
# set to lowest brightness and turn on | |
function initialize | |
{ | |
sh dim.sh 1 | |
sh toggle.sh 1 | |
} | |
function dim_and_sleep | |
{ | |
sh dim.sh $1 | |
sleep $2 | |
} | |
function timed_dim | |
{ | |
seconds=$[$1*60] | |
if [ $seconds -lt 100 ]; then | |
# calculate each brightness level, update every second | |
for i in $(seq 1 $seconds); do | |
dim_and_sleep $(bc <<< "(100 * $i) / $seconds") 1 | |
done | |
else | |
# calculate time between increments. | |
# brightness level increases by one with each increment | |
for i in {1..100}; do | |
dim_and_sleep $i $[$seconds/100] | |
done | |
fi | |
# rounding errors may not leave it at full brightness | |
sh dim.sh 100 | |
} | |
validate $@ | |
initialize | |
timed_dim $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment