Created
February 4, 2009 09:47
-
-
Save masuidrive/58042 to your computer and use it in GitHub Desktop.
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/env bash | |
# | |
# syntax: | |
# 'sudo zbright +N' increments screen brightness by N percent (N=0-100) | |
# 'sudo zbright -N' decrements screen brightness by N percent | |
# 'sudo zbright N' sets screen brightness to N percent | |
# 'sudo zbright' w/o any args reports current brightness | |
# | |
# note: must be run as sudo | |
# | |
# 2008-12-24 Ryan M. Eustice [email protected] | |
# 2009-02-23 Yuichiro MASUI [email protected] | |
# probe current brightness | |
ho=0x$(setpci -s 00:02.0 F4.B); # hex (0-FF) | |
do=$(printf "%d" $ho); # decimal (0-255) | |
po=$(($do*100/255)); # percent (0-100) | |
#echo "$ho $do $po" | |
if [ $1 ]; then | |
if [ "$(echo $1 | tr -d '\-')" != "$1" ]; then | |
delta=$(echo $1 | tr -d '\-'); | |
d=$((do-delta)); | |
elif [ "$(echo $1 | tr -d '\+')" != "$1" ]; then | |
delta=$(echo $1 | tr -d '\+'); | |
d=$((do+delta)); | |
else | |
d=$1; | |
fi | |
if [ $d -ge 256 ]; then | |
d=255; | |
fi | |
if [ $d -le 0 ]; then | |
d=0; | |
fi | |
h=0x$(printf "%x" $d); # hex (0-FF) | |
H=$(printf "%x" $h); # strip 0x hex prefix | |
setpci -s 00:02.0 F4.B=$H | |
else | |
echo "$ho $do $po"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment