Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # dimmer.sh
- # written by Rob Stockley (rob dash stockley at mowgli dot net dot nz)
- # to incrementally change the LCD brightness on a Compaq TC1100 tablet.
- # Tested only with Kubuntu 7.04. All comments and suggestions welcome.
- ME=`whoami`
- if [ $ME = root ]; then
- DISPLAYOWNER=`w -h | awk '{print $1" "$2" "$3}' | grep ":0"`
- USER=`echo $DISPLAYOWNER | awk '{print $1}'`
- # echo working on: $USER
- su -l $USER <<ENDSU
- /usr/bin/dimmer.sh $1 dummy;
- ENDSU
- exit 0
- fi
- # first need to establish whether config file exists and we can write to it
- echo $HOME
- NV_CONFIG="$HOME/.nvidia-settings-rc"
- if ! [ -w $NV_CONFIG ]; then
- echo "$NV_CONFIG is either missing or not writable. Before you run this script you need to run the nvidia-settings GUI application. When you quit the GUI the current driver settings should be written to $NV_CONFIG."
- nvidia-settings
- # exit 0
- fi
- # now need to read current brightness values
- CUR_R=`grep RedBrightness $NV_CONFIG | awk 'BEGIN { FS = "=" } ; { print $2 }'`
- CUR_G=`grep GreenBrightness $NV_CONFIG | awk 'BEGIN { FS = "=" } ; { print $2 }'`
- CUR_B=`grep BlueBrightness $NV_CONFIG | awk 'BEGIN { FS = "=" } ; { print $2 }'`
- # stepping 0.2 gives me five dim and five bright settings
- STEP="0.2"
- case $1 in
- --reset)
- # reset to driver defaults
- NEW_R='0.0000'
- NEW_G='0.0000'
- NEW_B='0.0000'
- ;;
- --dec)
- # decrease brightness and check limits
- NEW_R=`echo "scale=4; $CUR_R - $STEP" | bc`
- if [ `echo "scale=4; $NEW_R < -1.0" | bc` -eq 1 ]; then
- NEW_R=-1.0
- fi
- NEW_G=`echo "scale=4; $CUR_G - $STEP" | bc`
- if [ `echo "scale=4; $NEW_G < -1.0" | bc` -eq 1 ]; then
- NEW_G=-1.0
- fi
- NEW_B=`echo "scale=4; $CUR_B - $STEP" | bc`
- if [ `echo "scale=4; $NEW_B < -1.0" | bc` -eq 1 ]; then
- NEW_B=-1.0
- fi
- ;;
- --inc)
- # increase brightness and check limits
- NEW_R=`echo "scale=4; $CUR_R + $STEP" | bc`
- if [ `echo "scale=4; $NEW_R > 1.0" | bc` -eq 1 ]; then
- NEW_R=1.0
- fi
- NEW_G=`echo "scale=4; $CUR_G + $STEP" | bc`
- if [ `echo "scale=4; $NEW_G > 1.0" | bc` -eq 1 ]; then
- NEW_G=1.0
- fi
- NEW_B=`echo "scale=4; $CUR_B + $STEP" | bc`
- if [ `echo "scale=4; $NEW_B > 1.0" | bc` -eq 1 ]; then
- NEW_B=1.0
- fi
- ;;
- --help)
- echo "Script: $0"
- echo "Purpose: Change the LCD brightness on a"
- echo "Compaq TC1100 using Nvidia restricted driver. "
- echo "Written by Rob Stockley, October 2007"
- echo
- echo "Usage: $0 [ --reset | --dim | --inc | --help ]"
- echo "Options:"
- echo " --dec decrease the brightness a little"
- echo " --inc increace the brightness a little"
- echo " --reset reset to standard brightness"
- echo " --help print this message"
- exit 0
- ;;
- *)
- echo "Usage: $0 [ --reset | --dim | --inc | --help ]"
- exit 0
- ;;
- esac
- # fix cases where bc leaves us with leading -.
- NEW_R=`echo $NEW_R | sed 's/-\./-0\./'`
- NEW_G=`echo $NEW_G | sed 's/-\./-0\./'`
- NEW_B=`echo $NEW_B | sed 's/-\./-0\./'`
- # if we get to here then patch the .nvidia-settings-rc
- patch -s $NV_CONFIG << EOF
- --- .nvidia-settings-rc 2007-10-10 21:45:26.000000000 +1300
- +++ .nvidia-settings-rc.new 2007-10-11 10:00:52.000000000 +1300
- @@ -36,3 +36,3 @@
- -0/RedBrightness=$CUR_R
- -0/GreenBrightness=$CUR_G
- -0/BlueBrightness=$CUR_B
- +0/RedBrightness=$NEW_R
- +0/GreenBrightness=$NEW_G
- +0/BlueBrightness=$NEW_B
- EOF
- # finally the nvidia driver needs to load the new configuration
- nvidia-settings -l -c :0
Advertisement
Add Comment
Please, Sign In to add comment